Repository navigation
Conversation
…tore Activity generates trace IDs from an in-memory per-thread PRNG whose state is captured in the SnapStart snapshot, so restored execution environments repeat trace IDs. After restore, and before the function's after restore hooks run, set Activity.TraceIdGenerator to a generator backed by RandomNumberGenerator.Fill. A generator the function set during init is left in place.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Activitygenerates trace IDs from an in-memory, per-thread pseudo-random generator (the internal Xoshiro256**RandomNumberGeneratorinSystem.Diagnostics). A SnapStart snapshot captures that state, so every execution environment restored from the same snapshot continues the same sequence and produces the same trace IDs. OpenTelemetry .NET takes its IDs fromActivity, so instrumented functions merge unrelated requests into one trace.A repro on the
dotnet10managed runtime that createdActivityobjects during init got 3 distinct trace IDs across 50 concurrent first invokes. A control fromRandomNumberGenerator.Fillin the same invokes was 50 of 50 unique.Change
After
/runtime/restore/nextreturns, and before the function's after restore hooks run, RuntimeSupport setsActivity.TraceIdGeneratorto a generator that fills the trace ID fromSystem.Security.Cryptography.RandomNumberGenerator. Lambda reseeds the kernel random source after restore, so each environment gets unique IDs.Activity.TraceIdGeneratoris null, so a generator the function set during init (for exampleAWSXRayIdGenerator.ReplaceTraceId()) is kept.Not covered
Activityhas no hook for span IDs.ActivitySpanId.CreateRandom()always uses the internal generator, so span IDs can still repeat across restored environments on threads that created anActivitybefore the snapshot. Fixing that needs a change in dotnet/runtime.Testing
Unit tests cover the generator being set before after restore hooks run, a generator set during init being kept, and generated IDs being unique. Each test fails with its part of the fix reverted.
Live SnapStart test on the
dotnet10managed runtime (us-west-2, 512 MB), using an executable-mode function so the referenced RuntimeSupport drives the restore. The same harness was built once againstmasterand once against this branch. Init createsActivityobjects on the main thread and 8 thread-pool threads, then each invoke starts a rootActivity. Two snapshots per build, 50 concurrent invokes each:Every invoke of this PR's build reported
Activity.TraceIdGeneratorasSnapStartTraceIdGenerator.GenerateTraceId. Span IDs still repeat, as described above.