From 831af142c781164256cb22aba260eb13003a4c03 Mon Sep 17 00:00:00 2001 From: Mar Witek Date: Fri, 23 Oct 2026 16:16:00 +0200 Subject: [PATCH] Let RPC tracers supply the span update timestamp WorkerTracer::addSpanUpdate() reads the time from the IoContext, which a tracer driven over RPC doesn't have, so every update it received failed with "expected weakIoContext != nullptr". Add addSpanUpdateInternal(), which takes the timestamp from the caller, like addSpanAttributeInternal(). Co-Authored-By: Claude Opus 5.5 --- src/workerd/io/tracer.c++ | 10 +++++++++- src/workerd/io/tracer.h | 3 +++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/workerd/io/tracer.c++ b/src/workerd/io/tracer.c++ index 96b01951263..d34e4bdf9c0 100644 --- a/src/workerd/io/tracer.c++ +++ b/src/workerd/io/tracer.c++ @@ -276,6 +276,14 @@ void WorkerTracer::addSpanClose(tracing::SpanEndData&& span, kj::Maybe } void WorkerTracer::addSpanUpdate(tracing::SpanId spanId, tracing::SpanUpdate&& update) { + if (maybeTailStreamWriter == kj::none) { + return; + } + addSpanUpdateInternal(spanId, kj::mv(update), getTime()); +} + +void WorkerTracer::addSpanUpdateInternal( + tracing::SpanId spanId, tracing::SpanUpdate&& update, kj::Date timestamp) { if (pipelineLogLevel == PipelineLogLevel::NONE) { return; } @@ -285,7 +293,7 @@ void WorkerTracer::addSpanUpdate(tracing::SpanId spanId, tracing::SpanUpdate&& u auto context = tracing::InvocationSpanContext(topLevelContext.getTraceId(), topLevelContext.getInvocationId(), spanId, topLevelContext.getTraceFlags()); auto size = update.size(); - tailStreamWriter->report(context, kj::mv(update), getTime(), size); + tailStreamWriter->report(context, kj::mv(update), timestamp, size); } void WorkerTracer::addException(const tracing::InvocationSpanContext& context, diff --git a/src/workerd/io/tracer.h b/src/workerd/io/tracer.h index 5807de56a28..ec82089a072 100644 --- a/src/workerd/io/tracer.h +++ b/src/workerd/io/tracer.h @@ -171,6 +171,9 @@ class WorkerTracer final: public BaseTracer { kj::Date startTime) override; void addSpanClose(tracing::SpanEndData&& span, kj::Maybe maybeStartTime) override; void addSpanUpdate(tracing::SpanId spanId, tracing::SpanUpdate&& update) override; + // Variant for RPC-based tracing, where the caller supplies the timestamp from its IoContext. + void addSpanUpdateInternal( + tracing::SpanId spanId, tracing::SpanUpdate&& update, kj::Date timestamp); void addSpanAttribute(const tracing::InvocationSpanContext& context, kj::ConstString key, tracing::Attribute::Value value) override;