-
Notifications
You must be signed in to change notification settings - Fork 4.9k
ActivityContext.TryParse should support IsRemote #42575
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
Comments
Why this is not enough for you? ActivityContext is a struct and doing that wouldn't cause any real perf issue as it doesn't allocate and the struct size is really small. I don't think it is a good idea to expose a new API just to support this. CC @noahfalk |
It's more that it's error prone, and easy to forget Really I'd like to do Activity.StartActivity with trace parent, trace source, and isremote, but using activityContext seemed the next easiest alternative, but it needs a dance to get IsRemote set. |
I am not sure I understand this. How this is error prone? You can create your own helper method doing the functionality, it is simple and I wouldn't expect anyone can get it wrong. Easy to forget would be same as if someone manually creating ActivityContext object and forget to pass isRemote as it is optional parameters. Who cares about isRemote would never forget about it. |
API proposal: public readonly struct ActivityContext
{
public static bool TryParse(
string? traceParent,
string? traceState,
out System.Diagnostics.ActivityContext context,
bool isRemote = false) // New parameter with default set to current behavior.
{
} For me it isn't a question of whether the workaround is easy or not, it is a question of how do you know you need the workaround? You don't get immediate feedback that you made a misake. You might not even notice until in production when your sampling is off. If you do notice your sampling is off, it is natural to look at the sampler for issues. Triaging that all the way back to this API is difficult. I think adding the parameter would be a nice hint to users that they should consider whether or not the context belongs to a remote parent when it is created. |
@CodeBlanch thanks for the proposal. We cannot add an extra parameter to the existing method as it will be a breaking change. It is like removing a method. I suggest we add extra overload. Something like: public readonly struct ActivityContext
{
public static bool TryParse(string? traceParent, string? traceState, out System.Diagnostics.ActivityContext context)
+ public static bool TryParse(string? traceParent, string? traceState, bool isRemote, out System.Diagnostics.ActivityContext context)
} Note, isRomte is not defaulted parameter as I want to disnguish this overload from the already existing one. The other reason is I want to stick with the |
@tarekgh New method looks good to me. I suspected adding the parameter would be breaking but wasn't sure 😄 PS: How did you do that diff comment thing? That is neat. |
and having |
Looks good as proposed. namespace System.Diagnostics
{
public readonly partial struct ActivityContext
{
// existing
// public static bool TryParse(string? traceParent, string? traceState, out System.Diagnostics.ActivityContext context);
// new
public static bool TryParse(
string? traceParent,
string? traceState,
bool isRemote,
out System.Diagnostics.ActivityContext context);
}
} |
Edited and added the proposal by @tarekgh
Description
When using ActivitySource I wanted to support IsRemote (for opentelemetry), as the majority of the time any activity started with a w3c trace context will be remote.
To start an activity with IsRemote set needs an ActivityContext, the best option appears to be use:
ActivityContext.TryParse(traceParent, traceState, out var context)
However, a context then needs creating to copy the parsed context, and set IsRemote.
It would be useful if TryParse could provide a version that can pass IsRemote into the ActivityContext. I'd expect the majority of new activities that use TryParse are providing a traceparent and state from a remote caller.
Proposal
public readonly struct ActivityContext { public static bool TryParse(string? traceParent, string? traceState, out System.Diagnostics.ActivityContext context) + public static bool TryParse(string? traceParent, string? traceState, bool isRemote, out System.Diagnostics.ActivityContext context) }
Example
Alternatives
Users can manually add the following helper method but that means every user need this functionality will need to add this method.
The text was updated successfully, but these errors were encountered: