Repository navigation
[Debugger] DEBUG-5828 Coordinate snapshot sampling per trace #9266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9eac20c
[Debugger] Coordinate snapshot sampling per trace
dudikeleti c359150
[Debugger] Harden coordinated snapshot sampling
dudikeleti f1fca5d
[Debugger] Preserve coordinated sampling retries and telemetry
dudikeleti ff1151e
[Debugger] Avoid eager span context lookup for non-payload probes
dudikeleti eefb898
testing
dudikeleti 05a18be
[Debugger] Keep per-trace snapshot slot when capture expressions are …
dudikeleti 09d47d7
[Debugger] Move sampling logic out of TraceContext
dudikeleti cd5559d
[Debugger] Use a single enum for the per-trace sampling decision
dudikeleti d9f50fc
addressing review comments
dudikeleti File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
59 changes: 59 additions & 0 deletions
59
tracer/src/Datadog.Trace/Debugger/RateLimiting/DebuggerSamplingCoordinator.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| // <copyright file="DebuggerSamplingCoordinator.cs" company="Datadog"> | ||
| // Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. | ||
| // This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. | ||
| // </copyright> | ||
|
|
||
| #nullable enable | ||
|
|
||
| using System.Collections.Generic; | ||
| using System.Threading; | ||
|
|
||
| namespace Datadog.Trace.Debugger.RateLimiting | ||
| { | ||
| internal sealed class DebuggerSamplingCoordinator | ||
| { | ||
| private HashSet<string>? _emittedProbeIds; | ||
| private int _decision; | ||
|
|
||
| internal DebuggerSamplingDecision TrySample<TSamplingDecisionProvider>(string probeId, TSamplingDecisionProvider samplingDecisionProvider) | ||
| where TSamplingDecisionProvider : struct, IDebuggerSamplingDecisionProvider | ||
| { | ||
| var decision = (DebuggerSamplingDecision)Volatile.Read(ref _decision); | ||
| if (decision is DebuggerSamplingDecision.DropGlobal or DebuggerSamplingDecision.DropProbe) | ||
| { | ||
| return decision; | ||
| } | ||
|
|
||
| // The lock is reentrant. Holding it here means Sample() ran customer code on this thread | ||
| // (for example a first-chance exception handler) that hit another probe in this trace. | ||
| if (Monitor.IsEntered(this)) | ||
| { | ||
| return DebuggerSamplingDecision.DropProbe; | ||
| } | ||
|
|
||
| lock (this) | ||
| { | ||
| if (_decision == (int)DebuggerSamplingDecision.Undecided) | ||
| { | ||
| var samplingDecision = samplingDecisionProvider.Sample(); | ||
| if (samplingDecision == DebuggerSamplingDecision.Keep) | ||
| { | ||
| _emittedProbeIds = [probeId]; | ||
| } | ||
|
|
||
| _decision = (int)samplingDecision; | ||
| return samplingDecision; | ||
| } | ||
|
|
||
| if (_decision == (int)DebuggerSamplingDecision.Keep) | ||
| { | ||
| return _emittedProbeIds!.Add(probeId) | ||
|
dudikeleti marked this conversation as resolved.
|
||
| ? DebuggerSamplingDecision.Keep | ||
| : DebuggerSamplingDecision.DropProbe; | ||
| } | ||
|
|
||
| return (DebuggerSamplingDecision)_decision; | ||
| } | ||
| } | ||
| } | ||
| } | ||
22 changes: 22 additions & 0 deletions
22
tracer/src/Datadog.Trace/Debugger/RateLimiting/IDebuggerSamplingDecisionProvider.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| // <copyright file="IDebuggerSamplingDecisionProvider.cs" company="Datadog"> | ||
| // Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. | ||
| // This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. | ||
| // </copyright> | ||
|
|
||
| #nullable enable | ||
|
|
||
| namespace Datadog.Trace.Debugger.RateLimiting | ||
| { | ||
| internal enum DebuggerSamplingDecision | ||
| { | ||
| Undecided, | ||
| Keep, | ||
| DropGlobal, | ||
| DropProbe | ||
| } | ||
|
|
||
| internal interface IDebuggerSamplingDecisionProvider | ||
| { | ||
| DebuggerSamplingDecision Sample(); | ||
| } | ||
| } |
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.