Skip to content

Using TracerShim results in ConditionalWeakTable ArgumentException: "An item with the same key has already been added." #5439

@tvandenheuvel

Description

@tvandenheuvel

Bug Report

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

AspNetCore app

  • Npgsql.OpenTelemetry 8.0.2
  • OpenTelemetry 1.7.0
  • OpenTelemetry.Exporter.Console 1.7.0
  • OpenTelemetry.Extensions.Hosting 1.7.0
  • OpenTelemetry.Instrumentation.AspNetCore 1.7.1
  • OpenTelemetry.Instrumentation.Http 1.7.1
  • OpenTelemetry.Instrumentation.Runtime 1.7.0
  • OpenTelemetry.Shims.OpenTracing 1.7.0-beta.1

Library

  • OpenTracing 0.12.1

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

  • net8.0 aspnetcore webapp
  • net6.0 library

Symptom

When building and starting child spans using the TracerShim injected as OpenTracer ITracer, the ScopeManagerShim throws a ArgumentException

What is the expected behavior?

That a span is created and activated

What is the actual behavior?

System.ArgumentException: An item with the same key has already been added.
   at System.Runtime.CompilerServices.ConditionalWeakTable`2.Add(TKey key, TValue value)
   at OpenTelemetry.Shims.OpenTracing.ScopeManagerShim.Activate(ISpan span, Boolean finishSpanOnDispose)
   at OpenTelemetry.Shims.OpenTracing.SpanBuilderShim.StartActive(Boolean finishSpanOnDispose)
   at SubLibrary.SubClassWithOpenTracing.RecursiveChildSpan(String input, Int32 recursiveDepth) in .\OpenTelemetryTesting\SubLibrary\SubClassWithOpenTracing.cs:line 24
   at SubLibrary.SubClassWithOpenTracing.ParentSpan(String input) in.\OpenTelemetryTesting\SubLibrary\SubClassWithOpenTracing.cs:line 18
   at OpenTelemetryTesting.Program.<>c__DisplayClass0_0.<Main>b__0() in .\OpenTelemetryTesting\OpenTelemetryTesting\Program.cs:line 28
   at lambda_method2(Closure, Object, HttpContext)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)

Reproduce

https://github.com/tvandenheuvel/OpenTelemetryTesting

We will close this issue if:

  • The repro project you share with us is complex. We can't investigate custom
    projects, so don't point us to such, please.
  • If we can not reproduce the behavior you're reporting.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions