Skip to content

Commit

Permalink
Support skipOtlp option in the autoinstrumentation plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
stevejgordon committed Nov 21, 2024
1 parent 80f0d81 commit 527bf02
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/Elastic.OpenTelemetry/AutoInstrumentationPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public class AutoInstrumentationPlugin
private readonly ILogger _logger;
private readonly EventListener _eventListener;

private readonly bool _skipOtlp;

/// <inheritdoc cref="AutoInstrumentationPlugin"/>
public AutoInstrumentationPlugin()
{
Expand All @@ -31,6 +33,11 @@ public AutoInstrumentationPlugin()

_logger = logger;
_eventListener = eventListener;

var skipOtlpString = Environment.GetEnvironmentVariable("ELASTIC_OTEL_SKIP_OTLP_EXPORTER");

if (skipOtlpString is not null && bool.TryParse(skipOtlpString, out var skipOtlp))
_skipOtlp = skipOtlp;
}

/// To access TracerProvider right after TracerProviderBuilder.Build() is executed.
Expand All @@ -45,22 +52,20 @@ public void MeterProviderInitialized(MeterProvider meterProvider)

/// To configure tracing SDK before Auto Instrumentation configured SDK
public TracerProviderBuilder BeforeConfigureTracerProvider(TracerProviderBuilder builder) =>
builder.UseElasticDefaults(_logger);

builder.UseElasticDefaults(_skipOtlp, _logger);

/// To configure tracing SDK after Auto Instrumentation configured SDK
public TracerProviderBuilder AfterConfigureTracerProvider(TracerProviderBuilder builder) =>
builder;

/// To configure metrics SDK before Auto Instrumentation configured SDK
public MeterProviderBuilder BeforeConfigureMeterProvider(MeterProviderBuilder builder) =>
builder.UseElasticDefaults(_logger);
builder.UseElasticDefaults(_skipOtlp, _logger);

/// To configure metrics SDK after Auto Instrumentation configured SDK
public MeterProviderBuilder AfterConfigureMeterProvider(MeterProviderBuilder builder) =>
builder;


/// To configure logs SDK (the method name is the same as for other logs options)
public void ConfigureLogsOptions(OpenTelemetryLoggerOptions options) =>
options.UseElasticDefaults(_logger);
Expand Down

0 comments on commit 527bf02

Please sign in to comment.