opentelemetry-dart icon indicating copy to clipboard operation
opentelemetry-dart copied to clipboard

Context.current.span doesn't find the current span

Open constantberthereau opened this issue 2 months ago • 3 comments

I don't know if it's a real problem or a mistake, but i'm trying to close a span without store span in a variable.

Here is my code:

CollectorExporter exporter = otel_sdk.CollectorExporter(
  Uri.parse("https://test/v1/traces"),
);
BatchSpanProcessor processor = otel_sdk.BatchSpanProcessor(exporter);
SimpleSpanProcessor simpleProcessor =
    otel_sdk.SimpleSpanProcessor(otel_sdk.ConsoleExporter());
TracerProvider provider = otel_sdk.TracerProviderBase(
  processors: <otel_sdk.SpanProcessor>[processor, simpleProcessor],
  resource: otel_sdk.Resource(<Attribute>[
    Attribute.fromString("service.name", name),
    Attribute.fromString("telemetry.sdk.version", "1.6.0"),
    Attribute.fromString("telemetry.sdk.name", "opentelemetry"),
  ]),
);
registerGlobalTracerProvider(provider);

Span span= globalTracerProvider.getTracer('Mobilité').startSpan(
      'parentSpan',
    );

await Future.delayed(const Duration(seconds: 3));

Context.current.span.end(); 

I think, the problem come from Context.current.span. It doesn't find the span in the current context.

constantberthereau avatar May 03 '24 08:05 constantberthereau