Skip to content

Keeps capturing traces after parent scope is closed? #1285

Open
@dziedrius

Description

@dziedrius

Describe the bug
I've added custom traces for our application startup and noticed strange behavior:
image

As long as I'm trying to instrument application startup, where logging is bootstrapped, background jobs are scheduled, etc., it seems that tracing agent captures active scope during that bootstrap and keeps using it even after scope is disposed, that makes it confusing and problematic (not sure are what side effects are - does this mean some leaking in the app?).

I've intentionally hovered on one of the scopes outside my custom scope - it is datadog pushing logs to web, (we're using serilog as logging framework) - so that is happening periodically without me controlling it, I don't wish to disable HttpClient integration - so I am out of ideas how to fix it.

I'm using default finishOnClose value - true.

To Reproduce
I don't have an isolated app to demonstrate this, but I've reproduced it like this:

using (Tracer.Instance.StartActive("testing-scope", serviceName: "datadogscopes"))
{
    Task.Run(async () =>
    {
        for (int i = 0; i < 20; i++)
        {
            using (Tracer.Instance.StartActive("inner-testing-scope", serviceName: "datadogscopes"))
            {
                Thread.Sleep(300);
            }
        }
    });              
}

It looks in datadog like this:
image

And here I probably can control behavior as for inner scope I can say "don't attach to parent", problem is with scopes that I can't control (integrations - sql, redis, httpclient).

Expected behavior
I would expect that after disposing scope nothing would be added to it anymore or at least I could control that (like it might be that for some multithreaded cases it makes sense to add something to the scope after disposing it, so it might be useful).

Runtime environment (please complete the following information):

  • Instrumentation mode: mixed (side car container + manual custom scopes)
  • Tracer version: 1.24.0
  • OS: App's container is running on official asp.net 3.1-alpine image
  • CLR: .NET Core 3.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:tracerThe core tracer library (Datadog.Trace, does not include OpenTracing, native code, or integrations)type:enhancementImprovement to an existing feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions