Skip to content
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

Add ActivitySource Tags #102678

Merged
merged 2 commits into from
May 30, 2024
Merged

Add ActivitySource Tags #102678

merged 2 commits into from
May 30, 2024

Conversation

tarekgh
Copy link
Member

@tarekgh tarekgh commented May 24, 2024

Fixes #93795.

Copy link

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@tarekgh
Copy link
Member Author

tarekgh commented May 24, 2024

@noahfalk could you please have a look.

CC @reyang @cijothomas @CodeBlanch @lmolkova

if (tags is not null)
{
var tagList = new List<KeyValuePair<string, object?>>(tags);
tagList.Sort((left, right) => string.Compare(left.Key, right.Key, StringComparison.Ordinal));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the usecase for the sorting here?
Also, should this do de-duplication, given Activity Tags are deduped when set via SetTag?

Copy link
Member Author

@tarekgh tarekgh May 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the usecase for the sorting here?

We apply the same approach for Meter. The reason is to avoid creating duplicate meters with the same parameters and tags in the cached objects used in DI. While ActivitySource is not currently used in DI, implementing this now ensures consistent behavior and eliminates the need for changes if we decide to support ActivitySource/tracing configuration in the future.

should this do de-duplication, given Activity Tags are deduped when set via SetTag?

Any reason? Should this be the responsibility of the callers? We didn't do that with the Meter tags.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this do de-duplication, given Activity Tags are deduped when set via SetTag?

Any reason? Should this be the responsibility of the callers? We didn't do that with the Meter tags.

Because Activity.SetTag already does de-duplication, setting some precedence!
For metrics, BCL does not do any deduping of tags!

Copy link
Member Author

@tarekgh tarekgh May 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am fine with this if you see it as important. However, I want to understand the scenario better. Who is going to create a new ActivitySource and potentially have duplicate tags? I don't see this as a likely scenario since the creators of the ActivitySource will know exactly which tags they want to use. SetTag scenario is different as different parties can call it on the same activity object in different time. This is not the case for ActivitySource creation.

public ActivitySource(string name, string? version = "") { throw null; }
public ActivitySource(string name, string? version = "", System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, object?>>? tags = default) { throw null; }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would we need to do the [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] on this one too when we support schemaUrl as a parameter? (#63651)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, when adding a new constructor with extra optional parameter, we can add the [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] to the existing one.

I was thinking in the future if we add more options, we may start having ActivitySourceOptions and a constructor take this options object.

@noahfalk
Copy link
Member

noahfalk commented May 28, 2024

DiagnosticSourceEventSource has ActivityStart and ActivityStop events. Currently the expectation is that all tags would be located in Activity tags, but now if some instrumentation will using ActivitySource scoped tags instead we need to add those tags to the events to ensure that out-of-process consumers still have all the data available. This is pretty much the same issue as #93767 but for ActivitySource tags instead of Meter tags.

Aside from that, LGTM 👍

@tarekgh
Copy link
Member Author

tarekgh commented May 28, 2024

@noahfalk isn't Meter scoped tags already done 13337d8? I am seeing #93767 is a different issue which we still need to fix.

@noahfalk
Copy link
Member

@noahfalk isn't Meter scoped tags already done 13337d8?

That commit added Meter tags to Begin/End instrument reporting events, but it did not add the tags to the value publishing events. So for some events it remains ambiguous and for other events it is not ambiguous any longer. Fixing #93767 I assume is going to add Meter tags (and other data) to the value published events so that they are also not ambiguous.

The ActivityStart/Stop events for distributed tracing are analogous to the value published events for metrics.

@tarekgh
Copy link
Member Author

tarekgh commented May 29, 2024

I think tags are not enough to disambiguate. Yes, we should propagate the tags with the events, but ambiguity can still happen. like creating two meters/instruments with same name, version, scope, and tags. I don't know if we need to care much about that though. I recall it is reported that this happened in a real scenario.

Anyway, for the sake of this PR, I'll add the tags to the Start/Stop activity events.

@noahfalk
Copy link
Member

noahfalk commented May 29, 2024

I think tags are not enough to disambiguate... but ambiguity can still happen. like creating two meters/instruments with same name, version, scope, and tags.

Its fine if multiple ActivitySource objects with properties set to the same values are indistinguishable via out-of-proc events. That part is a non-goal :) The case I think we need to care about is given some Activity occurred, we should be able to enumerate all the tags, both the Activity-scoped ones and the ActivitySource scoped ones.

@CodeBlanch
Copy link
Contributor

DiagnosticSourceEventSource has ActivityStart and ActivityStop events. Currently the expectation is that all tags would be located in Activity tags, but now if some instrumentation will using ActivitySource scoped tags instead we need to add those tags to the events to ensure that out-of-process consumers still have all the data available. This is pretty much the same issue as #93767 but for ActivitySource tags instead of Meter tags.

Aside from that, LGTM 👍

@noahfalk Some random thoughts here. I've been working on a dotnet-monitor prototype to listen out of proc and send that data using OTel SDK. There's other stuff on ActivitySource for example version which I can't get at using the events. In metrics we have instrument published events currently. Could we have something in tracing for activity source published which would fire off the static details when the first activity is started for some source? If we add some unique id/count to the meter/source that could be included on the individual starts/stop/measurement events to tie back to the static data so we wouldn't need to duplicate it every time (expensive).

@tarekgh
Copy link
Member Author

tarekgh commented May 29, 2024

@CodeBlanch we can discuss this more, but I want to say this is out of scope for this PR. We can use #93767 to discuss this more and look at your scenarios. Or you can log a new issue with your requests, and we can triage it accordingly.

@noahfalk
Copy link
Member

Tarek and I confirmed that the DiagnosticSourceEventSource DSL can be used to define a TRANSFORM_SPEC that evaluates Activity.Source.Tags without needing any explicit changes to the event definitions.

@tarekgh tarekgh merged commit 3393b4d into dotnet:main May 30, 2024
83 checks passed
@tarekgh
Copy link
Member Author

tarekgh commented May 30, 2024

There's other stuff on ActivitySource for example version which I can't get at using the events.

@CodeBlanch I think you can use the same idea mentioned by @noahfalk in the comment #102678 (comment) to get the ActivitySource version.

Ruihan-Yin pushed a commit to Ruihan-Yin/runtime that referenced this pull request May 30, 2024
* Add ActivitySource Tags

* Fix failing test
@github-actions github-actions bot locked and limited conversation to collaborators Jun 29, 2024
@tarekgh tarekgh deleted the AddActivitySourceTags branch August 6, 2024 20:04
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature request]: Support instrumentation scope attributes on ActivitySource
5 participants