open-telemetry / opentelemetry-dotnet

The OpenTelemetry .NET Client
https://opentelemetry.io
Apache License 2.0
3.21k stars 759 forks source link

[OpenTelemetry.Shims.OpenTracing] ScopeManagerShim.Active returns a Scope who's Dispose() is NOOP (it does not tell OpenTel about the `finish`) #2590

Open ndrwrbgs opened 2 years ago

ndrwrbgs commented 2 years ago

Bug Report

List of NuGet packages and version that you are using (e.g. OpenTelemetry 1.0.2):

Runtime version (e.g. net461, net48, netcoreapp3.1, net5.0 etc. You can find this information from the *.csproj file):

Symptom

ScopeManagerShim.Active returns a Scope whose Dispose() is NOOP (it does not tell OpenTel about the finish).

Specifically, this line in .Active: return new ScopeInstrumentation(currentSpan);

What is the expected behavior?

GlobalTracer.Instance.Active.Dispose() should correctly orchestrate the call back to OpenTel

What is the actual behavior?

Spans never get closed in OpenTel. There's no deconstructor on the ScopeInstrumentation either, so if Dispose is not explicitly called (with the disposeAction supplied) OpenTel never gets told about the span at all

Reproduce

Honestly, my network connection is being crazy slow right now, so I won't provide a whole repo. Here's the call format you'll observe it with though. If it's too much effort to reproduce please let me know and I'll provide more!

// Setup the tracer as done in the examples projects in this repo
var tracer = TracerProvider.Default.GetTracer(name: "OpenTracing-Shim");
var shim = new TracerShim(tracer, new TraceContextPropagator());
GlobalTracer.Register(shim); 

GlobalTracer.Instance.BuildSpan("test").StartActive(finishSpanOnDispose: true);
GlobalTracer.Instance.ScopeManager.Active.Dispose();

(proactive note in case the suggestion comes: I cannot simply refactor the call format, because the calls are actually being generated by a library which cannot save the state between them to reuse the object from Activate(). A workaround to call GlobalTracer.Instance.ActiveSpan.Finish() would work with this library, but deviate from the OpenTracing semantics)

github-actions[bot] commented 2 months ago

This issue was marked stale due to lack of activity and will be closed in 7 days. Commenting will instruct the bot to automatically remove the label. This bot runs once per day.

ndrwrbgs commented 2 months ago

Is there anything more I can provide to reproduce the issue?