-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Ending an activity will not restore the previously active one for explicit parents #46721
Comments
Tagging subscribers to this area: @tarekgh, @tommcdon, @pjanotti Issue DetailsCopied from open-telemetry/opentelemetry-dotnet#1677 SymptomActivity.Current becomes Following shows how to repro this with OpenTelemetry, but this can be reproed by setting up any Activitylistener. Reproduceusing System;
using System.Diagnostics;
using OpenTelemetry;
using OpenTelemetry.Trace;
public class Program
{
private static readonly ActivitySource MyActivitySource = new ActivitySource(
"MyCompany.MyProduct.MyLibrary");
public static void Main()
{
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.SetSampler(new AlwaysOnSampler())
.AddSource("MyCompany.MyProduct.MyLibrary")
.Build();
using (var activity = MyActivitySource.StartActivity("SayHello"))
{
Console.WriteLine("Current before: {0}", Activity.Current?.DisplayName);
using (var child = MyActivitySource.StartActivity("SayWorld", ActivityKind.Internal, activity.Context))
{
Console.WriteLine("Current child: {0}", Activity.Current?.DisplayName);
}
Console.WriteLine("Current after: {0}", Activity.Current?.DisplayName ?? "(null)");
}
}
} Actual Output:
Expected output would be that the last line is Additional contextResponsible line in I think the Activity should capture a "previous" Activity independently of the Parent Activity and then always set that as active when stopping it.
|
@cijothomas I am wondering how this suppose to work from the OTel specification point of view? I mean:
what value you'll get? CC @noahfalk |
The Activity API is not conformant to the spec at all, see https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/api.md#span-creation:
Which the activity API violates. It also says in https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/api.md#end:
Which the activity API also does not conform to. As per the spec for End, |
Also note that the spec requires a concept of a "wrapped" SpanContext, i.e. a SpanContext can be wrapped in a non-recording Span so that it can be active in a context: https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/api.md#wrapping-a-spancontext-in-a-span
|
I'm happy to explore what we can do to improve things, but I do want to be up-front that spec conformance is not the only consideration which drives .NET's design in this space. The Activity API long pre-dated OpenTelemetry's spec and there is a huge ecosystem of .NET apps that our customers depend on us not to break when they upgrade. Re-defining the behavior of existing APIs is always an area we are going to proceed cautiously. |
I understand. That's why I suggested in open-telemetry/opentelemetry-dotnet#1677 (and copied here) that
This may also break any use cases that rely on the activity being null when it is not after that change, but that would be a much smaller change. |
Copied from open-telemetry/opentelemetry-dotnet#1677
Symptom
Activity.Current becomes
null
whenever any Activity with explicit parent is ended. I would instead have expected that the previously active activity would be restored, independent of whether it was the parent or not.Following shows how to repro this with OpenTelemetry, but this can be reproed by setting up any Activitylistener.
Reproduce
Actual Output:
Expected output would be that the last line is
Current after: SayHello
.Additional context
Responsible line in
Activity.Stop
:https://github.com/dotnet/runtime/blob/v5.0.1/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Activity.cs#L629
I think the Activity should capture a "previous" Activity independently of the Parent Activity and then always set that as active when stopping it.
The text was updated successfully, but these errors were encountered: