You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(serverless-init): eliminate GlobalTags data race in MicroVM trace tags
Codex flagged a data race on PR #53036: MicroVM's /run lifecycle hook calls
serverlessTraceAgent.SetTags from an async goroutine, which mutates
Agent.GlobalTags via SetGlobalTagsUnsafe concurrently with the trace agent's
span-processing loop reading that same field unsynchronized. GlobalTags is
computed once at config-build time and every reader in pkg/trace/agent and
pkg/trace/api assumes it is frozen thereafter; MicroVM's dynamic
lambda_microvm_id update breaks that invariant.
Route the async update through the span modifier instead, which already runs
at the identical point in the span-processing loop and is exclusively
serverless-owned:
- pkg/serverless/trace/span_modifier.go: tags field is now
atomic.Pointer[map[string]string]; ModifySpan reads it lock-free instead of
reading a field written by a separate mutator with no synchronization.
- pkg/serverless/trace/trace.go: new UpdateRuntimeTags method that only
updates the span modifier, never GlobalTags. Existing SetTags (used once
synchronously at startup, before the trace agent runs) is untouched.
- cmd/serverless-init/main.go: the two async TraceTagSetterFunc closures now
call UpdateRuntimeTags instead of SetTags.
This is scoped entirely to MicroVM: every other cloud service ignores
LifecycleCtx in Init, so they never exercise the async path and keep calling
the original SetTags at startup unchanged.
Also fixes an issue flagged by Codex review: ModifySpan's new tag-apply loop
unconditionally overwrote _dd.origin whenever the tags map contained it,
undoing the "only fill _dd.origin if absent" guard immediately above it.
Every CloudService.GetTags() sets _dd.origin (not just MicroVM's), and that
value flows into the tags applied here via SetTags/UpdateRuntimeTags at
startup for every cloud service — so this would have silently overwritten a
tracer-supplied span origin (e.g. _dd.origin:rum) for all of them, not just
MicroVM. Fixed by skipping _dd.origin in the loop. Covered by
TestSpanModifierModifySpanPreservesExistingOrigin.
A second Codex finding on this PR — UpdateRuntimeTags not reaching spans
processed via the V1 payload path (ProcessV1 skips SpanModifier) — is left
as a known follow-up; not fixed here.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
0 commit comments