Skip to content

Commit

Permalink
Add initial user spans for cache, memory-cache
Browse files Browse the repository at this point in the history
  • Loading branch information
fhanau committed Sep 30, 2024
1 parent cfa99d4 commit 82d0e98
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/workerd/api/cache.c++
Original file line number Diff line number Diff line change
Expand Up @@ -517,8 +517,9 @@ jsg::Promise<bool> Cache::delete_(
}

kj::Own<kj::HttpClient> Cache::getHttpClient(
IoContext& context, kj::Maybe<kj::String> cfBlobJson, kj::ConstString operationName) {
auto span = context.makeTraceSpan(kj::mv(operationName));
IoContext& context, kj::Maybe<kj::String> cfBlobJson, kj::LiteralStringConst operationName) {
auto span = context.makeTraceSpan(operationName);
auto limeSpan = context.makeLimeTraceSpan(operationName);

auto cacheClient = context.getCacheClient();
auto httpClient = cacheName
Expand Down
2 changes: 1 addition & 1 deletion src/workerd/api/cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class Cache: public jsg::Object {
kj::Maybe<kj::String> cacheName;

kj::Own<kj::HttpClient> getHttpClient(
IoContext& context, kj::Maybe<kj::String> cfBlobJson, kj::ConstString operationName);
IoContext& context, kj::Maybe<kj::String> cfBlobJson, kj::LiteralStringConst operationName);
};

// =======================================================================================
Expand Down
4 changes: 3 additions & 1 deletion src/workerd/api/memory-cache.c++
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ jsg::Promise<jsg::JsRef<jsg::JsValue>> MemoryCache::read(jsg::Lock& js,
}

auto readSpan = IoContext::current().makeTraceSpan("memory_cache_read"_kjc);
auto limeReadSpan = IoContext::current().makeLimeTraceSpan("memory_cache_read"_kjc);

KJ_IF_SOME(fallback, optionalFallback) {
KJ_SWITCH_ONEOF(cacheUse.getWithFallback(key.value, readSpan)) {
Expand All @@ -393,7 +394,8 @@ jsg::Promise<jsg::JsRef<jsg::JsValue>> MemoryCache::read(jsg::Lock& js,
}
KJ_CASE_ONEOF(promise, kj::Promise<SharedMemoryCache::Use::GetWithFallbackOutcome>) {
return IoContext::current().awaitIo(js, kj::mv(promise),
[fallback = kj::mv(fallback), key = kj::str(key.value), span = kj::mv(readSpan)](
[fallback = kj::mv(fallback), key = kj::str(key.value), span = kj::mv(readSpan),
limeSpan = kj::mv(limeReadSpan)](
jsg::Lock& js, SharedMemoryCache::Use::GetWithFallbackOutcome cacheResult) mutable
-> jsg::Promise<jsg::JsRef<jsg::JsValue>> {
KJ_SWITCH_ONEOF(cacheResult) {
Expand Down
3 changes: 2 additions & 1 deletion src/workerd/io/io-context.c++
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,8 @@ kj::Own<WorkerInterface> IoContext::getSubrequestNoChecks(
SpanBuilder limeSpan = nullptr;

KJ_IF_SOME(n, options.operationName) {
// TODO(cleanup): Avoid cloning the string here if possible.
// TODO(cleanup): Using kj::Maybe<kj::LiteralStringConst> for operationName instead would remove
// a memory allocation here, but there might be use cases for dynamically allocated strings.
span = makeTraceSpan(kj::ConstString(kj::str(n)));
limeSpan = makeLimeTraceSpan(kj::ConstString(kj::mv(n)));
}
Expand Down

0 comments on commit 82d0e98

Please sign in to comment.