-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[API Proposal]: Activity.IsStopped (functionality required to conform to OpenTelemetry specification) #63353
Comments
Tagging subscribers to this area: @tarekgh, @tommcdon, @pjanotti, @safern Issue DetailsBackground and motivationAs far as I know, the Activity class is meant to provide all the functionality required by the OpenTelemetry tracing specification for the concept that is called "Span" in OTel terms. However, I could not find a way to get the following from Activity:
At first, I thought one could check if In some situations, one could could use the callback from the Source and maintain a ConditionalWeakTable to record whether an Activity has stopped, but this is rather cumbersome, slow and not possible if you do not have control over the activities' source. It seems that Activity already has this implemented as private functinality as a property Exposing the existing name IsFinished would also be an acceptable IMHO (I think the most OTel-like name would be HasEnded, but since End is called Stop, my primary suggestion is IsStopped). The interface in OpenTelemetry Java is here https://github.com/open-telemetry/opentelemetry-java/blob/v1.9.1/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/ReadableSpan.java#L64-L71 and here https://github.com/open-telemetry/opentelemetry-java/blob/v1.9.1/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/data/SpanData.java#L117-L122 CC @open-telemetry/dotnet-approvers API Proposalnamespace System.Diagnostics.Generic
{
public class Activity: IDisposable
{
// ...
public bool IsStopped { get; }
// ...
}
} API Usagevar a = new Activity("foo");
Debug.Assert(!a.IsStopped);
a.Start();
Debug.Assert(!a.IsStopped);
a.Stop();
Debug.Assert(a.IsStopped); In an ActivityListener.ActivityStopped callback, Alternative DesignsIf RisksNone known. This proposal would add a new property exposing existing functionality that is required as an API surface by the OpenTelemetry specification.
|
The proposal looks reasonable to me. |
Yeah, this looks fine to me too. |
Is this considered part of the API or SDK? (this is part of the SDK spec). |
Looks it is part of the SDK but how the SDK can implement that without having |
Tagging subscribers to this area: @dotnet/area-system-diagnostics-activity Issue DetailsBackground and motivationAs far as I know, the Activity class is meant to provide all the functionality required by the OpenTelemetry tracing specification for the concept that is called "Span" in OTel terms. However, I could not find a way to get the following from Activity:
At first, I thought one could check if In some situations, one could could use the callback from the Source and maintain a ConditionalWeakTable to record whether an Activity has stopped, but this is rather cumbersome, slow and not possible if you do not have control over the activities' source. It seems that Activity already has this implemented as private functinality as a property Exposing the existing name IsFinished would also be an acceptable IMHO (I think the most OTel-like name would be HasEnded, but since End is called Stop, my primary suggestion is IsStopped). The interface in OpenTelemetry Java is here https://github.com/open-telemetry/opentelemetry-java/blob/v1.9.1/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/ReadableSpan.java#L64-L71 and here https://github.com/open-telemetry/opentelemetry-java/blob/v1.9.1/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/data/SpanData.java#L117-L122 API Proposalnamespace System.Diagnostics.Generic
{
public class Activity: IDisposable
{
// ...
public bool IsStopped { get; }
// ...
}
} API Usagevar a = new Activity("foo");
Debug.Assert(!a.IsStopped);
a.Start();
Debug.Assert(!a.IsStopped);
a.Stop();
Debug.Assert(a.IsStopped); In an ActivityListener.ActivityStopped callback, Alternative DesignsIf RisksNone known. This proposal would add a new property exposing existing functionality that is required as an API surface by the OpenTelemetry specification.
|
What I can think of (not necessarily against the proposal, just to call out that there might be many different solutions):
|
The end timestamp is already exposed, but can be set without stopping the Activity (see the issue description). The SDK might be able to solve this with events, but it then SHOULD ensure that users of the SDK have a way to tell if a Activity they received in SpanProcessor.OnStart is stopped at any later point in time (https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/sdk.md#onstart "It SHOULD be possible to keep a reference to this span object and updates to the span SHOULD be reflected in it."). As stated in the issue description, this would probably require a ConditionalWeakTable. |
Do we have any other scenarios that need to keep the references of the span objects? If not, then it is not worth it to introduce that just for checking spans is stopped or not. The other idea could be to set some tag or custom property on the Activity when receiving the stop event and use it when you want to check. I am still thinking exposing Activity.IsStopped would be a cleaner solution here. |
If there is no more feedback, can we move forward with the proposal? @reyang any more feedback? Thanks! |
Nope. I guess it is possible to implement this efficiently in the SDK without having to introduce a new API to the runtime. But I don't see adding a new runtime API as bad idea if there is good reason and use case. |
Looks good as proposed namespace System.Diagnostics
{
public partial class Activity
{
public bool IsStopped { get; }
}
} |
Background and motivation
As far as I know, the Activity class is meant to provide all the functionality required by the OpenTelemetry tracing specification for the concept that is called "Span" in OTel terms.
However, I could not find a way to get the following from Activity:
-- https://github.com/open-telemetry/opentelemetry-specification/blob/v1.8.0/specification/trace/sdk.md#additional-span-interfaces
At first, I thought one could check if
Activity.Duration != TimeSpan.Zero
, but while this is indeed true for all stopped/ended activities, even activities that are still running can have a non-zero duration ifSetEndTime
was called butStop
/Dispose
was not.In some situations, one could could use the callback from the Source and maintain a ConditionalWeakTable to record whether an Activity has stopped, but this is rather cumbersome, slow and not possible if you do not have control over the activities' source.
It seems that Activity already has this implemented as private functinality as a property
IsFinished
: https://github.com/dotnet/runtime/blob/v6.0.1/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Activity.cs#L1301-L1303Exposing the existing name IsFinished would also be an acceptable IMHO (I think the most OTel-like name would be HasEnded, but since End is called Stop, my primary suggestion is IsStopped).
The interface in OpenTelemetry Java is here https://github.com/open-telemetry/opentelemetry-java/blob/v1.9.1/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/ReadableSpan.java#L64-L71 and here https://github.com/open-telemetry/opentelemetry-java/blob/v1.9.1/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/data/SpanData.java#L117-L122
API Proposal
API Usage
In an ActivityListener.ActivityStopped callback,
IsStopped
of the notifying Activity must also be true to conform to OTel semantics.Alternative Designs
If
SetEndTime
would always unconditionallyStop
the activity, the check for nonzeroDuration
could be used instead of using a separate property. However, that would probably be an unacceptable breaking change. Note: The XML doc ofDuration
claims that callingSetEndTime
ends the activity (is ending the same as stopping?) but unless Duration != Zero does logically end the activity (without invoking a listener), this does not seem to be true.Alternative Workaround
OpenTelemetry SDK is already listening to Activity Start and Stop events, it can manually either create a weak reference table mapping the Activity object to its wrapper span object and then mark the span ended when receiving Stop event. Another idea is to set some property/tag value on the Activity when receiving the stop event. These are not clean solutions considering the simplicity we'll get if we added the proposed API.
Risks
None known. This proposal would add a new property exposing existing functionality that is required as an API surface by the OpenTelemetry specification.
The text was updated successfully, but these errors were encountered: