Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

* Support `Sdk.SuppressInstrumentation`/`SuppressInstrumentationScope`.
([#3372](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/3372))

## 1.13.0-beta.1

Released 2025-Oct-22
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" />
<PackageReference Include="Microsoft.Extensions.Options" />
<PackageReference Include="OpenTelemetry.Api.ProviderBuilderExtensions" />
<PackageReference Include="OpenTelemetry" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am concerned about this change. During stabilization effort, this package was removed (at least from HttpClient). We still do not have good solution to make similar things referencing only OpenTelemetry/Api package.

@open-telemetry/dotnet-maintainers, do you see any better option here (even long term, by adding this functionality on API level)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Brought this up at the .NET SIG on Nov 4 2025. Maintainers are looking at moving this functionality out of the SDK package.

Suppression is not currently part of the spec but is useful enough to find a better solution, even though it would technically make the API out of compliance.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Kielek Use Func<bool> to replace Sdk.SuppressInstrumentatio?

<PackageReference Include="StackExchange.Redis" />
<PackageReference Include="System.Reflection.Emit.Lightweight" Condition="'$([MSBuild]::GetTargetFrameworkIdentifier(`$(TargetFramework)`))' == '.NETStandard'" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public StackExchangeRedisConnectionInstrumentation(
var parent = Activity.Current;

// If no parent use the default session.
if (parent == null || parent.IdFormat != ActivityIdFormat.W3C)
if (parent == null || parent.IdFormat != ActivityIdFormat.W3C || Sdk.SuppressInstrumentation)
{
return this.defaultSession;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,43 @@ public async Task ProfilerSessionUsesTheSameDefault()
Assert.Equal(second, third);
}

[Fact]
public void ProfilerSessionUsesTheSameDefaultWhenSuppressInstrumentationScopeHasBegan()
{
var connectionOptions = new ConfigurationOptions
{
AbortOnConnectFail = false,
ConnectRetry = 0,
ConnectTimeout = 1_000,
};
connectionOptions.EndPoints.Add("localhost:6379");

var connection = ConnectionMultiplexer.Connect(connectionOptions);

using var instrumentation = new StackExchangeRedisConnectionInstrumentation(connection, name: null, new StackExchangeRedisInstrumentationOptions());
var profilerFactory = instrumentation.GetProfilerSessionsFactory();
var first = profilerFactory();

// start a root level activity
using var rootActivity = new Activity("Parent")
.SetParentId(ActivityTraceId.CreateRandom(), ActivitySpanId.CreateRandom(), ActivityTraceFlags.Recorded)
.Start();

Assert.NotNull(rootActivity.Id);

// get an initial profiler from root activity
Activity.Current = rootActivity;
var second = profilerFactory();
ProfilingSession? third;
using (SuppressInstrumentationScope.Begin())
{
third = profilerFactory();
}

Assert.NotEqual(first, second);
Assert.Equal(first, third);
}

[Trait("CategoryName", "RedisIntegrationTests")]
[SkipUnlessEnvVarFoundTheory(RedisEndPointEnvVarName)]
[InlineData("value1")]
Expand Down