Skip to content

Commit

Permalink
Rename lime tracing => user tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
fhanau committed Oct 15, 2024
1 parent 2160e96 commit 8823d7f
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/workerd/api/cache.c++
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ jsg::Promise<bool> Cache::delete_(
kj::Own<kj::HttpClient> Cache::getHttpClient(
IoContext& context, kj::Maybe<kj::String> cfBlobJson, kj::LiteralStringConst operationName) {
auto span = context.makeTraceSpan(operationName);
auto limeSpan = context.makeLimeTraceSpan(operationName);
auto userSpan = context.makeUserTraceSpan(operationName);

auto cacheClient = context.getCacheClient();
auto httpClient = cacheName
Expand Down
4 changes: 2 additions & 2 deletions src/workerd/api/memory-cache.c++
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +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);
auto userReadSpan = IoContext::current().makeUserTraceSpan("memory_cache_read"_kjc);

KJ_IF_SOME(fallback, optionalFallback) {
KJ_SWITCH_ONEOF(cacheUse.getWithFallback(key.value, readSpan)) {
Expand All @@ -395,7 +395,7 @@ 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),
limeSpan = kj::mv(limeReadSpan)](
userSpan = kj::mv(userReadSpan)](
jsg::Lock& js, SharedMemoryCache::Use::GetWithFallbackOutcome cacheResult) mutable
-> jsg::Promise<jsg::JsRef<jsg::JsValue>> {
KJ_SWITCH_ONEOF(cacheResult) {
Expand Down
18 changes: 9 additions & 9 deletions src/workerd/io/io-context.c++
Original file line number Diff line number Diff line change
Expand Up @@ -787,16 +787,16 @@ kj::Own<WorkerInterface> IoContext::getSubrequestNoChecks(
kj::FunctionParam<kj::Own<WorkerInterface>(TraceContext&, IoChannelFactory&)> func,
SubrequestOptions options) {
SpanBuilder span = nullptr;
SpanBuilder limeSpan = nullptr;
SpanBuilder userSpan = nullptr;

KJ_IF_SOME(n, options.operationName) {
// 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)));
userSpan = makeUserTraceSpan(kj::ConstString(kj::mv(n)));
}

TraceContext tracing(kj::mv(span), kj::mv(limeSpan));
TraceContext tracing(kj::mv(span), kj::mv(userSpan));
auto ret = func(tracing, getIoChannelFactory());

if (options.wrapMetrics) {
Expand All @@ -809,8 +809,8 @@ kj::Own<WorkerInterface> IoContext::getSubrequestNoChecks(
if (tracing.span.isObserved()) {
ret = ret.attach(kj::mv(tracing.span));
}
if (tracing.limeSpan.isObserved()) {
ret = ret.attach(kj::mv(tracing.limeSpan));
if (tracing.userSpan.isObserved()) {
ret = ret.attach(kj::mv(tracing.userSpan));
}

return kj::mv(ret);
Expand Down Expand Up @@ -925,18 +925,18 @@ SpanParent IoContext::getCurrentTraceSpan() {
return getMetrics().getSpan();
}

SpanParent IoContext::getCurrentLimeTraceSpan() {
SpanParent IoContext::getCurrentUserTraceSpan() {
// TODO(o11y): Add support for retrieving span from storage scope lock for more accurate span
// context, as with Jaeger spans.
return getMetrics().getLimeSpan();
return getMetrics().getUserSpan();
}

SpanBuilder IoContext::makeTraceSpan(kj::ConstString operationName) {
return getCurrentTraceSpan().newChild(kj::mv(operationName));
}

SpanBuilder IoContext::makeLimeTraceSpan(kj::ConstString operationName) {
return getCurrentLimeTraceSpan().newChild(kj::mv(operationName));
SpanBuilder IoContext::makeUserTraceSpan(kj::ConstString operationName) {
return getCurrentUserTraceSpan().newChild(kj::mv(operationName));
}

void IoContext::taskFailed(kj::Exception&& exception) {
Expand Down
4 changes: 2 additions & 2 deletions src/workerd/io/io-context.h
Original file line number Diff line number Diff line change
Expand Up @@ -751,13 +751,13 @@ class IoContext final: public kj::Refcounted, private kj::TaskSet::ErrorHandler
// Returns the current span being recorded. If called while the JS lock is held, uses the trace
// information from the current async context, if available.
SpanParent getCurrentTraceSpan();
SpanParent getCurrentLimeTraceSpan();
SpanParent getCurrentUserTraceSpan();

// Returns a builder for recording tracing spans (or a no-op builder if tracing is inactive).
// If called while the JS lock is held, uses the trace information from the current async
// context, if available.
SpanBuilder makeTraceSpan(kj::ConstString operationName);
SpanBuilder makeLimeTraceSpan(kj::ConstString operationName);
SpanBuilder makeUserTraceSpan(kj::ConstString operationName);

// Implement per-IoContext rate limiting for Cache.put(). Pass the body of a Cache API PUT
// request and get a possibly wrapped stream back.
Expand Down
2 changes: 1 addition & 1 deletion src/workerd/io/observer.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class RequestObserver: public kj::Refcounted {
virtual SpanParent getSpan() {
return nullptr;
}
virtual SpanParent getLimeSpan() {
virtual SpanParent getUserSpan() {
return nullptr;
}

Expand Down
6 changes: 3 additions & 3 deletions src/workerd/io/trace.c++
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ static constexpr size_t MAX_TRACE_BYTES = 128 * 1024;
// Limit spans to at most 512, it could be difficult to fit e.g. 1024 spans within MAX_TRACE_BYTES
// unless most of the included spans do not include tags. If use cases arise where this amount is
// insufficient, merge smaller spans together or drop smaller spans.
static constexpr size_t MAX_LIME_SPANS = 512;
static constexpr size_t MAX_USER_SPANS = 512;

namespace {

Expand Down Expand Up @@ -637,8 +637,8 @@ void WorkerTracer::log(kj::Date timestamp, LogLevel logLevel, kj::String message

void WorkerTracer::addSpan(const Span& span, kj::String spanContext) {
// This is where we'll actually encode the span for now.
// Drop any spans beyond MAX_LIME_SPANS.
if (trace->numSpans >= MAX_LIME_SPANS) {
// Drop any spans beyond MAX_USER_SPANS.
if (trace->numSpans >= MAX_USER_SPANS) {
return;
}
if (isPredictableModeForTest()) {
Expand Down
24 changes: 12 additions & 12 deletions src/workerd/io/trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ class WorkerTracer final: public kj::Refcounted {

// Adds log line to trace. For Spectre, timestamp should only be as accurate as JS Date.now().
// The isSpan parameter allows for logging spans, which will be emitted after regular logs. There
// can be at most MAX_LIME_SPANS spans in a trace.
// can be at most MAX_USER_SPANS spans in a trace.
void log(kj::Date timestamp, LogLevel logLevel, kj::String message, bool isSpan = false);
// Add a span, which will be represented as a log.
void addSpan(const Span& span, kj::String spanContext);
Expand Down Expand Up @@ -670,42 +670,42 @@ inline SpanBuilder SpanBuilder::newChild(kj::ConstString operationName, kj::Date
}

// TraceContext to keep track of user tracing/existing tracing better
// TODO(o11y): When creating lime child spans, verify that operationName is within a set of
// TODO(o11y): When creating user child spans, verify that operationName is within a set of
// supported operations. This is important to avoid adding spans to the wrong tracing system.

// Interface to track trace context including both Jaeger and Lime spans.
// Interface to track trace context including both Jaeger and User spans.
// TODO(o11y): Consider fleshing this out to make it a proper class, support adding tags/child spans
// to both,... We expect that tracking lime spans will not needed in all places where we have the
// to both,... We expect that tracking user spans will not needed in all places where we have the
// existing spans, so synergies will likely be limited.
struct TraceContext {
TraceContext(SpanBuilder span, SpanBuilder limeSpan)
TraceContext(SpanBuilder span, SpanBuilder userSpan)
: span(kj::mv(span)),
limeSpan(kj::mv(limeSpan)) {}
userSpan(kj::mv(userSpan)) {}
TraceContext(TraceContext&& other) = default;
TraceContext& operator=(TraceContext&& other) = default;
KJ_DISALLOW_COPY(TraceContext);

SpanBuilder span;
SpanBuilder limeSpan;
SpanBuilder userSpan;
};

// TraceContext variant tracking span parents instead. This is useful for code interacting with
// IoChannelFactory::SubrequestMetadata, which often needs to pass through both spans together
// without modifying them. In particular, add functions like newLimeChild() here to make it easier
// without modifying them. In particular, add functions like newUserChild() here to make it easier
// to add a span for the right parent.
struct TraceParentContext {
TraceParentContext(TraceContext& tracing)
: parentSpan(tracing.span),
limeParentSpan(tracing.limeSpan) {}
TraceParentContext(SpanParent span, SpanParent limeSpan)
userParentSpan(tracing.userSpan) {}
TraceParentContext(SpanParent span, SpanParent userSpan)
: parentSpan(kj::mv(span)),
limeParentSpan(kj::mv(limeSpan)) {}
userParentSpan(kj::mv(userSpan)) {}
TraceParentContext(TraceParentContext&& other) = default;
TraceParentContext& operator=(TraceParentContext&& other) = default;
KJ_DISALLOW_COPY(TraceParentContext);

SpanParent parentSpan;
SpanParent limeParentSpan;
SpanParent userParentSpan;
};

// RAII object that measures the time duration over its lifetime. It tags this duration onto a
Expand Down

0 comments on commit 8823d7f

Please sign in to comment.