-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Description
Regarding Span Creation the OpenTelemetry specification states that the API must accept:
The parent Context or an indication that the new Span should be a root Span.
The current ActivitySource.StartActivity API does not allow for this if Activity.Current != null. The following code creates a new activity as a child of Activity.Current.
var rootSpan = activitySource.StartActivity(
"RootSpan",
ActivityKind.Internal,
parentContext: default)One solution may be to set Activity.Current = null when StartActivity receives parentContext = default, but then it may be debatable whether Activity.Current should then be set to:
- the newly created root activity, or
- be restored to the previous value of Activity.Current prior to returning from
StartActivity.
The OpenTelemetry specification also states:
In languages with implicit Context propagation, Span creation MUST NOT set the newly created Span as the active Span in the current Context by default, but this functionality MAY be offered additionally as a separate operation.
This implies that StartActivity should not affect the value of Activity.Current, but since it already does today it may be reasonable to set Activity.Current to the newly created root activity.
Another option could be to introduce a new API StartRootActivity that starts a new activity but does not affect Activity.Current. It would be up to the user to manage Activity.Current.
This need was originally outlined in open-telemetry/opentelemetry-dotnet#984.