@@ -220,34 +220,44 @@ void WorkerTracer::addSpan(CompleteSpan&& span) {
220220 }
221221 }
222222
223- // Span events are transmitted together for now.
223+ // Compose span events – attributes and spanClose are transmitted together for now.
224224 auto & topLevelContext = KJ_ASSERT_NONNULL (topLevelInvocationSpanContext);
225- // Compose span events. For SpanOpen, an all-zero spanId is interpreted as having no spans above
226- // this one, thus we use the Onset spanId instead (taken from topLevelContext). We go to great
227- // lengths to rule out getting an all-zero spanId by chance (see SpanId::fromEntropy()), so this
228- // should be safe.
229- tracing::SpanId parentSpanId = span.parentSpanId ;
230- if (parentSpanId == tracing::SpanId::nullId) {
231- parentSpanId = topLevelContext.getSpanId ();
232- }
233- // TODO(o11y): Actually report the spanOpen event at span creation time
234- auto spanOpenContext = tracing::InvocationSpanContext (
235- topLevelContext.getTraceId (), topLevelContext.getInvocationId (), parentSpanId);
236225 auto spanComponentContext = tracing::InvocationSpanContext (
237226 topLevelContext.getTraceId (), topLevelContext.getInvocationId (), span.spanId );
238227
239- tailStreamWriter->report (
240- spanOpenContext, tracing::SpanOpen (span.spanId , kj::str (span.operationName )), span.startTime );
241228 // If a span manages to exceed the size limit, truncate it by not providing span attributes.
242229 if (span.tags .size () && messageSize <= MAX_TRACE_BYTES) {
243230 tracing::CustomInfo attr = KJ_MAP (tag, span.tags ) {
244- return tracing::Attribute (kj::ConstString ( kj::str ( tag.key )), spanTagClone (tag.value ));
231+ return tracing::Attribute (kj::mv ( tag.key ), kj::mv (tag.value ));
245232 };
246233 tailStreamWriter->report (spanComponentContext, kj::mv (attr), span.startTime );
247234 }
248235 tailStreamWriter->report (spanComponentContext, tracing::SpanClose (), span.endTime );
249236}
250237
238+ void WorkerTracer::addSpanOpen (tracing::SpanId spanId,
239+ tracing::SpanId parentSpanId,
240+ kj::ConstString& operationName,
241+ kj::Date startTime) {
242+ // This is where we'll actually encode the span.
243+ if (pipelineLogLevel == PipelineLogLevel::NONE) {
244+ return ;
245+ }
246+
247+ auto & tailStreamWriter = KJ_UNWRAP_OR_RETURN (maybeTailStreamWriter);
248+ auto & topLevelContext = KJ_ASSERT_NONNULL (topLevelInvocationSpanContext);
249+ // Compose SpanOpen. An all-zero spanId is interpreted as having no spans above this one, thus we
250+ // use the Onset spanId instead (taken from topLevelContext). We go to great lengths to rule out
251+ // getting an all-zero spanId by chance (see SpanId::fromEntropy()), so this should be safe.
252+ if (parentSpanId == tracing::SpanId::nullId) {
253+ parentSpanId = topLevelContext.getSpanId ();
254+ }
255+ auto spanOpenContext = tracing::InvocationSpanContext (
256+ topLevelContext.getTraceId (), topLevelContext.getInvocationId (), parentSpanId);
257+ tailStreamWriter->report (
258+ spanOpenContext, tracing::SpanOpen (spanId, kj::str (operationName)), startTime);
259+ }
260+
251261void WorkerTracer::addException (const tracing::InvocationSpanContext& context,
252262 kj::Date timestamp,
253263 kj::String name,
0 commit comments