Skip to content
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

Start Root Span Collects Current Active Span as Parent #2803

Closed
omamoo opened this issue Jan 20, 2022 · 7 comments · Fixed by #4890
Closed

Start Root Span Collects Current Active Span as Parent #2803

omamoo opened this issue Jan 20, 2022 · 7 comments · Fixed by #4890
Labels
bug Something isn't working

Comments

@omamoo
Copy link

omamoo commented Jan 20, 2022

Bug Report

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

  • NuGet: OpenTelemetry.Api Version 1.2.0-rc1

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

  • dotnet 6.0.101

Symptom

I defined simple Api endpoint with the following code:

[HttpGet]
public async Task TestOtel()
{
    using (TracerProvider.Default.
               GetTracer(ActivitySourceProvider.ActivitySourceName, ActivitySourceProvider.Version).
               StartActiveSpan("FirstSpan"))
    {
        await Task.Delay(5.Seconds());
        var rootSpan = 
            TracerProvider.Default.
                GetTracer(ActivitySourceProvider.ActivitySourceName, ActivitySourceProvider.Version).
                StartRootSpan("MyRootSpan"); 
        using (Tracer.WithSpan(rootSpan))
        {
            Task.Delay(5.Seconds());
        }
    }
}

What is the expected behavior?

I'm expecting to see two different traces:

  • First one is for incoming HTTP request (using AspDotNet instrumentation library) and one more nested span called "FirstSpan"
  • Second is for the MyRootSpan which created by using CreateRootSpan and activated with WithSpan method.

What is the actual behavior?

One trace with all span see attached image.

Additional Context

Image with trace at Jaeger:
image

Thanks for the help.

@omamoo omamoo added the bug Something isn't working label Jan 20, 2022
@omamoo
Copy link
Author

omamoo commented Feb 8, 2022

Anyone?

@alanwest
Copy link
Member

alanwest commented Feb 9, 2022

Yes, this might be a bug. I created a test #2878 that I think models your situation.

@omamoo
Copy link
Author

omamoo commented Feb 9, 2022

@alanwest Yes this is the exact case, thanks. How can I know if the test passes?

@alanwest
Copy link
Member

alanwest commented Feb 10, 2022

We'll leave this issue open as I'm not yet sure what the best fix will be.

In my opinion, the problem is due in part to the behavior of the StartActivity method when it is passed an empty parent context (i.e., starting a root span). StartActivity is called from StartRootSpan and is not part of the OpenTelemetry .NET project - it is part of .NET's System.Diagnostics library.

I'll raise this issue for discussion in the .NET SIG meeting agenda next week.

In the meantime, a work around for you may be to set Activity.Current = null prior to calling StartRootSpan. It is the fact that Activity.Current is not null which is causing MyRootSpan to be a child of FirstSpan in your case.


Turns out there's another issue already tracking the underlying issue #984. Looks like there was discussion to follow up with the runtime team, but not sure if that happened or not.

@omamoo
Copy link
Author

omamoo commented Feb 10, 2022

@alanwest Thanks for the update.

  • We are using the workaround as you described, so it's don't urgent.
  • I raised this issue because I couldn't find Root Activity creation is not supported (in presence of active parent) #984, they are the same.
  • Yes, the problem is with .NET diagnostics library and activity which is not null. But you won't change the API of span creation am I right? If I'll call CreateActiveSpan with null span context it still will use the parent span if exist as a parent?

Thanks.

@Oberon00
Copy link
Member

Oberon00 commented Feb 17, 2022

I don't think this is exactly the same as #984. While #984 is about the Activity API missing required basic functionality, this is about the OTel-specific StartRootSpan not doing what it says in its name.

@alanwest
Copy link
Member

I don't think this is exactly the same as #984. While #984 is about the Activity API missing required basic functionality, this is about the OTel-specific StartRootSpan not doing what it says in its name.

We discussed in this week's SIG meeting fixing this for the StartRootSpan API since we control that in this project, so I agree we should keep this bug open for that.

Separately, I just opened dotnet/runtime#65528 to address #984.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants