open-telemetry / opentelemetry-php

The OpenTelemetry PHP Library
https://opentelemetry.io/docs/instrumentation/php/
Apache License 2.0
741 stars 186 forks source link

SpanBuilder: Add convenience method for parent-less span #1407

Open cedricziel opened 2 weeks ago

cedricziel commented 2 weeks ago

Is your feature request related to a problem? When batch-processing messages from a queue, it is not great to have all message spans related to the parent span, but rather be traces on their own.

In the Java instrumentation, there is a convenience builder method called setNoParent, which sets an empty context to create a fresh trace.

Describe the solution you'd like Add a convenience method to the SpanBuilder to ease creation of parent-less spans.

Describe alternatives you've considered There's an unintuitive workaround which requires instrinsic knowledge about the SDK:

$span = $tracer-spanBuilder('process')
  ->setParent(Context::getRoot()) // set an empty root
  ->startSpan();

Additional context Add any other context about the feature request here.

brettmc commented 1 week ago

We actually used to have this, but it looks like it was consolidated into setParent some time ago: https://github.com/open-telemetry/opentelemetry-php/pull/820/files I think that setParent(false) is the same thing, if that helps but could be better documented?