-
Notifications
You must be signed in to change notification settings - Fork 732
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
Update diagnosticsource to rc1 #1203
Changes from all commits
3e511e8
e2fbef0
f986a4f
fc292f6
7e912ed
6022042
444d63e
aaa032d
ece52dc
76b5251
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,30 +93,23 @@ static TracerProviderSdk() | |
this.processor?.OnEnd(activity); | ||
} | ||
}, | ||
|
||
// Setting this to true means TraceId will be always | ||
// available in sampling callbacks and will be the actual | ||
// traceid used, if activity ends up getting created. | ||
AutoGenerateRootContextTraceId = true, | ||
}; | ||
|
||
if (sampler is AlwaysOnSampler) | ||
{ | ||
listener.GetRequestedDataUsingContext = (ref ActivityCreationOptions<ActivityContext> options) => | ||
!Sdk.SuppressInstrumentation ? ActivityDataRequest.AllDataAndRecorded : ActivityDataRequest.None; | ||
listener.Sample = (ref ActivityCreationOptions<ActivityContext> options) => | ||
!Sdk.SuppressInstrumentation ? ActivitySamplingResult.AllDataAndRecorded : ActivitySamplingResult.None; | ||
} | ||
else if (sampler is AlwaysOffSampler) | ||
{ | ||
/*TODO: Change options.Parent.SpanId to options.Parent.TraceId | ||
once AutoGenerateRootContextTraceId is removed.*/ | ||
listener.GetRequestedDataUsingContext = (ref ActivityCreationOptions<ActivityContext> options) => | ||
!Sdk.SuppressInstrumentation ? PropagateOrIgnoreData(options.Parent.SpanId) : ActivityDataRequest.None; | ||
listener.Sample = (ref ActivityCreationOptions<ActivityContext> options) => | ||
!Sdk.SuppressInstrumentation ? PropagateOrIgnoreData(options.Parent.TraceId) : ActivitySamplingResult.None; | ||
} | ||
else | ||
{ | ||
// This delegate informs ActivitySource about sampling decision when the parent context is an ActivityContext. | ||
listener.GetRequestedDataUsingContext = (ref ActivityCreationOptions<ActivityContext> options) => | ||
!Sdk.SuppressInstrumentation ? ComputeActivityDataRequest(options, sampler) : ActivityDataRequest.None; | ||
listener.Sample = (ref ActivityCreationOptions<ActivityContext> options) => | ||
!Sdk.SuppressInstrumentation ? ComputeActivitySamplingResult(options, sampler) : ActivitySamplingResult.None; | ||
} | ||
|
||
if (sources.Any()) | ||
|
@@ -219,52 +212,50 @@ protected override void Dispose(bool disposing) | |
base.Dispose(disposing); | ||
} | ||
|
||
private static ActivityDataRequest ComputeActivityDataRequest( | ||
private static ActivitySamplingResult ComputeActivitySamplingResult( | ||
in ActivityCreationOptions<ActivityContext> options, | ||
Sampler sampler) | ||
{ | ||
// As we set ActivityListener.AutoGenerateRootContextTraceId = true, | ||
// Parent.TraceId will always be the TraceId of the to-be-created Activity, | ||
// if it get created. | ||
ActivityTraceId traceId = options.Parent.TraceId; | ||
|
||
var samplingParameters = new SamplingParameters( | ||
options.Parent, | ||
traceId, | ||
options.TraceId, | ||
options.Name, | ||
options.Kind, | ||
options.Tags, | ||
options.Links); | ||
|
||
var shouldSample = sampler.ShouldSample(samplingParameters); | ||
|
||
var activityDataRequest = shouldSample.Decision switch | ||
var activitySamplingResult = shouldSample.Decision switch | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would this callback be called for legacy (http-in/out) DiagnosticSource instrumentations? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point! |
||
{ | ||
SamplingDecision.RecordAndSampled => ActivityDataRequest.AllDataAndRecorded, | ||
SamplingDecision.Record => ActivityDataRequest.AllData, | ||
_ => ActivityDataRequest.PropagationData | ||
SamplingDecision.RecordAndSampled => ActivitySamplingResult.AllDataAndRecorded, | ||
SamplingDecision.Record => ActivitySamplingResult.AllData, | ||
_ => ActivitySamplingResult.PropagationData | ||
}; | ||
|
||
if (activityDataRequest != ActivityDataRequest.PropagationData) | ||
if (activitySamplingResult != ActivitySamplingResult.PropagationData) | ||
{ | ||
return activityDataRequest; | ||
foreach (var att in shouldSample.Attributes) | ||
{ | ||
options.SamplingTags.Add(att.Key, att.Value); | ||
} | ||
|
||
return activitySamplingResult; | ||
} | ||
|
||
/*TODO: Change options.Parent.SpanId to options.Parent.TraceId | ||
once AutoGenerateRootContextTraceId is removed.*/ | ||
return PropagateOrIgnoreData(options.Parent.SpanId); | ||
return PropagateOrIgnoreData(options.Parent.TraceId); | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
private static ActivityDataRequest PropagateOrIgnoreData(ActivitySpanId spanId) | ||
private static ActivitySamplingResult PropagateOrIgnoreData(ActivityTraceId traceId) | ||
{ | ||
var isRootSpan = spanId == default; | ||
var isRootSpan = traceId == default; | ||
|
||
// If it is the root span select PropagationData so the trace ID is preserved | ||
// even if no activity of the trace is recorded (sampled per OpenTelemetry parlance). | ||
return isRootSpan | ||
? ActivityDataRequest.PropagationData | ||
: ActivityDataRequest.None; | ||
? ActivitySamplingResult.PropagationData | ||
: ActivitySamplingResult.None; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Looks like the same entry is right above the new one (commented out).