-
Notifications
You must be signed in to change notification settings - Fork 765
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
Add Sdk.SuppressInstrumentation #960
Changes from 3 commits
7a29abf
a686324
3911dc5
1f83935
af61349
ce02006
0594fdd
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 |
---|---|---|
|
@@ -17,7 +17,9 @@ | |
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Runtime.CompilerServices; | ||
using System.Threading; | ||
using OpenTelemetry.Context; | ||
using OpenTelemetry.Metrics; | ||
using OpenTelemetry.Metrics.Export; | ||
using OpenTelemetry.Trace; | ||
|
@@ -32,7 +34,24 @@ namespace OpenTelemetry | |
/// </summary> | ||
public static class Sdk | ||
{ | ||
private static TimeSpan defaultPushInterval = TimeSpan.FromSeconds(60); | ||
private static readonly TimeSpan DefaultPushInterval = TimeSpan.FromSeconds(60); | ||
|
||
private static readonly RuntimeContextSlot<bool> SuppressInstrumentationRuntimeContextSlot = RuntimeContext.RegisterSlot<bool>("otel.suppress_instrumentation"); | ||
|
||
public static bool SuppressInstrumentation | ||
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.
/// <summary>
/// Gets or sets a value indicating whether or not <see cref="Activity"/>Activity</see> object collection in the current context should be suppressed (dsiabled). Default value: False.
/// </summary>
/// <remarks>
/// Set <see cref="SuppressInstrumentation"/> to <see langword="true"/> when you want to turn off automatic <see cref="Activity"/> collection.
/// This is typically done to prevent infinte loops created by collection of internal operations, such as exporting spans over HTTP.
/// <code>
/// public override async Task<ExportResult> ExportAsync(IEnumerable<Activity> batchActivity, CancellationToken cancellationToken)
/// {
/// Sdk.SuppressInstrumentation = true;
/// try
/// {
/// await this.SendBatchActivityAsync(batchActivity, cancellationToken).ConfigureAwait(false);
/// return ExportResult.Success;
/// }
/// finally
/// {
/// Sdk.SuppressInstrumentation = false;
/// }
/// }
/// </code>
/// </remarks>
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 catch, will add it.
Not sure, the proposed name seems too long 😅 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. What if it wasn't exposed as a bool? Something more like log scope: 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. I believe this is what @reyang was proposing in the PR description. I think I do like the disposable idea. I'm currently playing with this implementation and I thing this would make things read nicer. 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. Yeah, @alanwest is helping on that part in a separate PR ❤️ |
||
{ | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
get | ||
{ | ||
return SuppressInstrumentationRuntimeContextSlot.Get(); | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
set | ||
{ | ||
SuppressInstrumentationRuntimeContextSlot.Set(value); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Creates MeterProvider with the configuration provided. | ||
|
@@ -60,7 +79,7 @@ public static MeterProvider CreateMeterProvider(Action<MeterBuilder> configure) | |
meterRegistry, | ||
metricProcessor, | ||
metricExporter, | ||
meterBuilder.MetricPushInterval == default(TimeSpan) ? defaultPushInterval : meterBuilder.MetricPushInterval, | ||
meterBuilder.MetricPushInterval == default(TimeSpan) ? DefaultPushInterval : meterBuilder.MetricPushInterval, | ||
cancellationTokenSource); | ||
|
||
var meterProviderSdk = new MeterProviderSdk(metricProcessor, meterRegistry, controller, cancellationTokenSource); | ||
|
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.
This would help the exporters/processors to quickly look up the suppress_instrumentation flag without a hash lookup.