-
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]: new ActivitySource.CreateActivity overload #103245
Comments
Tagging subscribers to this area: @dotnet/area-system-diagnostics-activity |
Wouldn't it be possible to leverage the new |
If that would work downstream on netfx then yes. This specific use case is from the AspNet opentelemetry code not the AspNetCore. |
Good point! It might be bit tricky and also need changes to ActivityCreationOptions to move to Separately, I think |
@Wraith2 I suggest the following too:
an example needing a lot of tags: https://github.com/open-telemetry/semantic-conventions/blob/main/docs/http/http-spans.md The following attributes can be important for making sampling decisions and SHOULD be provided at span creation time (if provided at all): client.address |
I don't think we need such overloads. We can have the one that takes |
I think the 1,2,3 tag overloads is just for convenience, not for perf. |
I am seeing using TagList is much simpler.
|
Seems reasonable. If the TagList taken as an instance into the activity rather than enumerated and the individual items copied then the boxing of the quite large TagList won't have been wasteful. |
Let's say we add overloads which accept public class ActivitySource
{
public Activity? CreateActivity(
string name,
ActivityKind kind,
ActivityContext parentContext,
in TagList tags = default,
IEnumerable<ActivityLink>? links = null,
ActivityIdFormat idFormat = ActivityIdFormat.Unknown
) {}
public Activity? StartActivity(
string name,
ActivityKind kind,
ActivityContext parentContext,
in TagList tags = default,
IEnumerable<ActivityLink>? links = null,
DateTimeOffset startTime = default
) {}
} 👍 from me so far. But on Line 108 in c5e8f83
Seems like we would end up with an allocation/boxing due to that. So we may need to do something there as well? |
@CodeBlanch right, that is what @cijothomas mentioned in #103245 (comment). We'll look more at the details when the time come 😄 |
Background and motivation
When creating an activity using ActivitySource there are currently two overloads available which allow you to pass tags which will be available to samplers.
If you want to pass a single tag to the sampler there isn't a good way to do it. without excessive allocations.
KeyValuePair<string, object?>
type contains references.ReadOnlySpan<>
is a ref struct, doesn't implement enumerable and can't be boxed.ArraySegment<>
it'll box the array segment because it's a struct.The easiest thing to do is a simple single value array allocation and if you want to amortize it you'll have to manage the array pooling yourself. It would be good to have a lower allocation path to create the activity in this case because the activity is being created for every incoming request.
This came up while trying to extend OpenTelemetry TelemetryHttpModule open-telemetry/opentelemetry-dotnet-contrib#1871 (comment)
API Proposal
API Usage
Alternative Designs
If it possible to provide a way to call one of the existing overloads and avoiding per call allocations which will be discarded then that may be acceptable.
Risks
No response
The text was updated successfully, but these errors were encountered: