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 optional tags support to TracerProvider.GetTracer for .NET 9 #6111

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

alimahboubi
Copy link

Fixes #6016
Design discussion issue #6016

Changes

This PR introduces support for adding default tags to a specific Tracer by leveraging the new ActivitySource constructor overload in .NET 9, which accepts IEnumerable<KeyValuePair<string, object?>>? tags. The changes include:

  1. Added a new overload for TracerProvider.GetTracer in .NET 9 and above, which accepts an optional tags parameter.

  2. Extended the TracerKey record struct to include the Tags property for .NET 9 and above, ensuring that tracers with different tags are uniquely identified.

  3. Updated the Tracer creation logic to pass the tags parameter to the ActivitySource constructor when applicable.

  4. Maintained backward compatibility for pre-.NET 9 environments by keeping the existing GetTracer method without the tags parameter.

These changes align with the feature request to support default tags for specific tracers, similar to the enhancements made in System.Diagnostics.ActivitySource.

Merge requirement checklist

  • CONTRIBUTING guidelines followed (license requirements, nullable enabled, static analysis, etc.)
  • Unit tests added/updated
  • Appropriate CHANGELOG.md files updated for non-trivial changes
  • Changes in public API reviewed (if applicable)

@alimahboubi alimahboubi requested a review from a team as a code owner January 28, 2025 20:35
Copy link

linux-foundation-easycla bot commented Jan 28, 2025

CLA Signed


The committers listed above are authorized under a signed CLA.

@github-actions github-actions bot added the pkg:OpenTelemetry.Api Issues related to OpenTelemetry.Api NuGet package label Jan 28, 2025
@@ -27,6 +27,50 @@ protected TracerProvider()
/// </summary>
public static TracerProvider Default { get; } = new TracerProvider();

#if NET9_0_OR_GREATER
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 reason for introducing the new API in .NET 9 or later?

/// <param name="version">Version of the instrumentation library.</param>
/// <param name="tags">Tags associated with the tracer.</param>
/// <returns>Tracer instance.</returns>
public Tracer GetTracer(
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

@rajkumar-rangaraj rajkumar-rangaraj left a comment

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg:OpenTelemetry.Api Issues related to OpenTelemetry.Api NuGet package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[feature request] Support for adding default tags to specific Tracer
2 participants