-
Notifications
You must be signed in to change notification settings - Fork 780
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
OpenTelemetry.Shims.OpenTracing Invalid 'SpanContext' when not sampled #4087
Comments
I spent some time today digging into this. First, I put together a smaller repro sample as a unit test for easier debugging: using System.Diagnostics;
using Microsoft.Extensions.DependencyInjection;
using OpenTelemetry.Context.Propagation;
using OpenTelemetry.Shims.OpenTracing;
using OpenTelemetry.Trace;
using OpenTracing;
using Xunit;
[Fact]
public void Investigate4087_AlwaysOff()
{
string serviceName = "Investigate4087";
var exportedItems = new List<Activity>();
var services = new ServiceCollection();
services.AddOpenTelemetry()
.WithTracing(b => b
.AddSource(serviceName)
.AddInMemoryExporter(exportedItems)
.SetSampler(new AlwaysOffSampler())); // this fails
//.SetSampler(new AlwaysOnSampler())); // this works
services.AddSingleton<ITracer>(sp =>
{
var tracerProvider = sp.GetRequiredService<TracerProvider>();
var tracer = new TracerShim(tracerProvider.GetTracer(serviceName), Propagators.DefaultTextMapPropagator);
return tracer;
});
IServiceProvider serviceProvider = services.BuildServiceProvider();
var tracer = serviceProvider.GetRequiredService<ITracer>();
using (var parent = tracer.BuildSpan("parent").StartActive())
using (var child = tracer.BuildSpan("child").StartActive())
{
}
} Part of the cause is in opentelemetry-dotnet/src/OpenTelemetry.Api/Trace/Tracer.cs Lines 176 to 180 in d0829ff
The
Here, the Span Context is Invalid because of the default values and fails here:
opentelemetry-dotnet/src/OpenTelemetry.Shims.OpenTracing/SpanShim.cs Lines 44 to 51 in d0829ff
|
While digging into the relationship between Samplers and StartActivity I found this: opentelemetry-dotnet/src/OpenTelemetry/Trace/TracerProviderSdk.cs Lines 234 to 245 in d0829ff
In summary, when using the AlwaysOffSampler, the PropogateOrIgnoreData() is effectively determining to not create a new Activity. -- |
@TimothyMothra @open-telemetry/dotnet-maintainers While some other aspects are mentioned on this issue it seems that we can close it as fixed via #4668 |
@pjanotti Confirmed! @open-telemetry/dotnet-maintainers I think this Issue could be assigned to the current milestone and closed. :) |
Bug Report
List of [all OpenTelemetry NuGet packages]:
Runtime version:
Symptom
When using shim package
What is the expected behavior?
Return some noop instance.
What is the actual behavior?
ArgumentException thrown from SpanShim ctor.
Reproduce
Reproduced error:
https://github.com/konczykl/OpenTracingShimError
Additional Context
Problem exists if we are not sampling spans - underlying activity is not created resulting in default SpanContext.
Parent span's activity is set as PropagationData and gets created but child's activity is null.
The text was updated successfully, but these errors were encountered: