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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 63 additions & 4 deletions src/OpenTelemetry.Api/Trace/TracerProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,50 @@
/// </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?

/// <summary>
/// Gets a tracer with given name, version and tags.
/// </summary>
/// <param name="name">Name identifying the instrumentation library.</param>
/// <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(

Check failure on line 38 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / concurrency-tests / run-concurrency-tests (ubuntu-22.04, net8.0, OpenTelemetry.Api.Tests)

Symbol 'OpenTelemetry.Trace.TracerProvider.GetTracer(string! name, string? version = null, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string!, object?>>? tags = null) -> OpenTelemetry.Trace.Tracer!' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 38 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / concurrency-tests / run-concurrency-tests (ubuntu-22.04, net8.0, OpenTelemetry.Api.Tests)

Symbol 'OpenTelemetry.Trace.TracerProvider.GetTracer(string! name, string? version = null, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string!, object?>>? tags = null) -> OpenTelemetry.Trace.Tracer!' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 38 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / concurrency-tests / run-concurrency-tests (ubuntu-22.04, net8.0, OpenTelemetry.Tests)

Symbol 'OpenTelemetry.Trace.TracerProvider.GetTracer(string! name, string? version = null, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string!, object?>>? tags = null) -> OpenTelemetry.Trace.Tracer!' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 38 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / concurrency-tests / run-concurrency-tests (ubuntu-22.04, net8.0, OpenTelemetry.Tests)

Symbol 'OpenTelemetry.Trace.TracerProvider.GetTracer(string! name, string? version = null, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string!, object?>>? tags = null) -> OpenTelemetry.Trace.Tracer!' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 38 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (otel-linux-arm64, net9.0)

Symbol 'OpenTelemetry.Trace.TracerProvider.GetTracer(string! name, string? version = null, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string!, object?>>? tags = null) -> OpenTelemetry.Trace.Tracer!' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 38 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (ubuntu-22.04, net9.0)

Symbol 'OpenTelemetry.Trace.TracerProvider.GetTracer(string! name, string? version = null, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string!, object?>>? tags = null) -> OpenTelemetry.Trace.Tracer!' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 38 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (ubuntu-22.04, net9.0)

Symbol 'OpenTelemetry.Trace.TracerProvider.GetTracer(string! name, string? version = null, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string!, object?>>? tags = null) -> OpenTelemetry.Trace.Tracer!' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 38 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (ubuntu-22.04, net8.0)

Symbol 'OpenTelemetry.Trace.TracerProvider.GetTracer(string! name, string? version = null, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string!, object?>>? tags = null) -> OpenTelemetry.Trace.Tracer!' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 38 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (ubuntu-22.04, net8.0)

Symbol 'OpenTelemetry.Trace.TracerProvider.GetTracer(string! name, string? version = null, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string!, object?>>? tags = null) -> OpenTelemetry.Trace.Tracer!' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 38 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (ubuntu-22.04, net8.0)

Symbol 'OpenTelemetry.Trace.TracerProvider.GetTracer(string! name, string? version = null, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string!, object?>>? tags = null) -> OpenTelemetry.Trace.Tracer!' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 38 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (ubuntu-22.04, net8.0)

Symbol 'OpenTelemetry.Trace.TracerProvider.GetTracer(string! name, string? version = null, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string!, object?>>? tags = null) -> OpenTelemetry.Trace.Tracer!' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 38 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (otel-linux-arm64, net9.0)

Symbol 'OpenTelemetry.Trace.TracerProvider.GetTracer(string! name, string? version = null, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string!, object?>>? tags = null) -> OpenTelemetry.Trace.Tracer!' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 38 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / concurrency-tests / run-concurrency-tests (windows-latest, net8.0, OpenTelemetry.Tests)

Symbol 'OpenTelemetry.Trace.TracerProvider.GetTracer(string! name, string? version = null, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string!, object?>>? tags = null) -> OpenTelemetry.Trace.Tracer!' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 38 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / concurrency-tests / run-concurrency-tests (windows-latest, net8.0, OpenTelemetry.Tests)

Symbol 'OpenTelemetry.Trace.TracerProvider.GetTracer(string! name, string? version = null, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string!, object?>>? tags = null) -> OpenTelemetry.Trace.Tracer!' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 38 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (ubuntu-22.04, net9.0)

Symbol 'OpenTelemetry.Trace.TracerProvider.GetTracer(string! name, string? version = null, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string!, object?>>? tags = null) -> OpenTelemetry.Trace.Tracer!' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 38 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / validate-packages / run-package-validation-experimental

Symbol 'OpenTelemetry.Trace.TracerProvider.GetTracer(string! name, string? version = null, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string!, object?>>? tags = null) -> OpenTelemetry.Trace.Tracer!' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 38 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / validate-packages / run-package-validation-stable

Symbol 'OpenTelemetry.Trace.TracerProvider.GetTracer(string! name, string? version = null, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string!, object?>>? tags = null) -> OpenTelemetry.Trace.Tracer!' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 38 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net462)

Symbol 'OpenTelemetry.Trace.TracerProvider.GetTracer(string! name, string? version = null, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string!, object?>>? tags = null) -> OpenTelemetry.Trace.Tracer!' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 38 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / concurrency-tests / run-concurrency-tests (windows-latest, net8.0, OpenTelemetry.Api.Tests)

Symbol 'OpenTelemetry.Trace.TracerProvider.GetTracer(string! name, string? version = null, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string!, object?>>? tags = null) -> OpenTelemetry.Trace.Tracer!' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 38 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / concurrency-tests / run-concurrency-tests (windows-latest, net8.0, OpenTelemetry.Api.Tests)

Symbol 'OpenTelemetry.Trace.TracerProvider.GetTracer(string! name, string? version = null, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string!, object?>>? tags = null) -> OpenTelemetry.Trace.Tracer!' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 38 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net8.0)

Symbol 'OpenTelemetry.Trace.TracerProvider.GetTracer(string! name, string? version = null, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string!, object?>>? tags = null) -> OpenTelemetry.Trace.Tracer!' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 38 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net462)

Symbol 'OpenTelemetry.Trace.TracerProvider.GetTracer(string! name, string? version = null, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string!, object?>>? tags = null) -> OpenTelemetry.Trace.Tracer!' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 38 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net8.0)

Symbol 'OpenTelemetry.Trace.TracerProvider.GetTracer(string! name, string? version = null, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string!, object?>>? tags = null) -> OpenTelemetry.Trace.Tracer!' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 38 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net9.0)

Symbol 'OpenTelemetry.Trace.TracerProvider.GetTracer(string! name, string? version = null, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string!, object?>>? tags = null) -> OpenTelemetry.Trace.Tracer!' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 38 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net9.0)

Symbol 'OpenTelemetry.Trace.TracerProvider.GetTracer(string! name, string? version = null, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string!, object?>>? tags = null) -> OpenTelemetry.Trace.Tracer!' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check warning on line 38 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / lint-dotnet-format / run-dotnet-format-experimental

Symbol 'OpenTelemetry.Trace.TracerProvider.GetTracer(string! name, string? version = null, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string!, object?>>? tags = null) -> OpenTelemetry.Trace.Tracer!' is not part of the declared public API

Check warning on line 38 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / lint-dotnet-format / run-dotnet-format-stable

Symbol 'OpenTelemetry.Trace.TracerProvider.GetTracer(string! name, string? version = null, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string!, object?>>? tags = null) -> OpenTelemetry.Trace.Tracer!' is not part of the declared public API
Copy link
Contributor

Choose a reason for hiding this comment

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

[AllowNull] string name,
string? version = null,
IEnumerable<KeyValuePair<string, object?>>? tags = null)
{
var tracers = this.Tracers;
if (tracers == null)
{
// Note: Returns a no-op Tracer once dispose has been called.
return new(activitySource: null);
}

var key = new TracerKey(name, version, tags);

if (!tracers.TryGetValue(key, out var tracer))
{
lock (tracers)
{
if (this.Tracers == null)
{
// Note: We check here for a race with Dispose and return a
// no-op Tracer in that case.
return new(activitySource: null);
}

tracer = new(new(key.Name, key.Version, key.Tags));
bool result = tracers.TryAdd(key, tracer);
#if DEBUG
System.Diagnostics.Debug.Assert(result, "Write into tracers cache failed");
#endif
}
}

return tracer;
}
#else
/// <summary>
/// Gets a tracer with given name and version.
/// </summary>
Expand Down Expand Up @@ -60,18 +104,17 @@
return new(activitySource: null);
}

tracer = new(new(key.Name, key.Version));
#if DEBUG
tracer = new (new (key.Name, key.Version));

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / concurrency-tests / run-concurrency-tests (ubuntu-22.04, net8.0, OpenTelemetry.Api.Tests)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / concurrency-tests / run-concurrency-tests (ubuntu-22.04, net8.0, OpenTelemetry.Api.Tests)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / concurrency-tests / run-concurrency-tests (ubuntu-22.04, net8.0, OpenTelemetry.Api.Tests)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / concurrency-tests / run-concurrency-tests (ubuntu-22.04, net8.0, OpenTelemetry.Api.Tests)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / concurrency-tests / run-concurrency-tests (ubuntu-22.04, net8.0, OpenTelemetry.Tests)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / concurrency-tests / run-concurrency-tests (ubuntu-22.04, net8.0, OpenTelemetry.Tests)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / concurrency-tests / run-concurrency-tests (ubuntu-22.04, net8.0, OpenTelemetry.Tests)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / concurrency-tests / run-concurrency-tests (ubuntu-22.04, net8.0, OpenTelemetry.Tests)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (otel-linux-arm64, net9.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (otel-linux-arm64, net9.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (otel-linux-arm64, net9.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (otel-linux-arm64, net9.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (otel-linux-arm64, net9.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (otel-linux-arm64, net9.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (otel-linux-arm64, net9.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (otel-linux-arm64, net9.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (ubuntu-22.04, net9.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (ubuntu-22.04, net9.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (ubuntu-22.04, net9.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (ubuntu-22.04, net9.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (ubuntu-22.04, net9.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (ubuntu-22.04, net9.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (ubuntu-22.04, net8.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (ubuntu-22.04, net8.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (ubuntu-22.04, net8.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (ubuntu-22.04, net8.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (ubuntu-22.04, net8.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (ubuntu-22.04, net8.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (ubuntu-22.04, net8.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (ubuntu-22.04, net8.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (ubuntu-22.04, net8.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (ubuntu-22.04, net8.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (ubuntu-22.04, net8.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (ubuntu-22.04, net8.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (otel-linux-arm64, net9.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (otel-linux-arm64, net9.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (otel-linux-arm64, net9.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (otel-linux-arm64, net9.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (otel-linux-arm64, net9.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (otel-linux-arm64, net9.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (otel-linux-arm64, net9.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (otel-linux-arm64, net9.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / concurrency-tests / run-concurrency-tests (windows-latest, net8.0, OpenTelemetry.Tests)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / concurrency-tests / run-concurrency-tests (windows-latest, net8.0, OpenTelemetry.Tests)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / concurrency-tests / run-concurrency-tests (windows-latest, net8.0, OpenTelemetry.Tests)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / concurrency-tests / run-concurrency-tests (windows-latest, net8.0, OpenTelemetry.Tests)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / concurrency-tests / run-concurrency-tests (windows-latest, net8.0, OpenTelemetry.Tests)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / concurrency-tests / run-concurrency-tests (windows-latest, net8.0, OpenTelemetry.Tests)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (ubuntu-22.04, net9.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (ubuntu-22.04, net9.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (ubuntu-22.04, net9.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (ubuntu-22.04, net9.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (ubuntu-22.04, net9.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (ubuntu-22.04, net9.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (ubuntu-22.04, net9.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (ubuntu-22.04, net9.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / validate-packages / run-package-validation-experimental

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / validate-packages / run-package-validation-experimental

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / validate-packages / run-package-validation-experimental

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / validate-packages / run-package-validation-experimental

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / validate-packages / run-package-validation-experimental

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / validate-packages / run-package-validation-experimental

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / validate-packages / run-package-validation-stable

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / validate-packages / run-package-validation-stable

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / validate-packages / run-package-validation-stable

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / validate-packages / run-package-validation-stable

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / validate-packages / run-package-validation-stable

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / validate-packages / run-package-validation-stable

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net462)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net462)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net462)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net462)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net462)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net462)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net462)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net462)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / concurrency-tests / run-concurrency-tests (windows-latest, net8.0, OpenTelemetry.Api.Tests)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / concurrency-tests / run-concurrency-tests (windows-latest, net8.0, OpenTelemetry.Api.Tests)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / concurrency-tests / run-concurrency-tests (windows-latest, net8.0, OpenTelemetry.Api.Tests)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / concurrency-tests / run-concurrency-tests (windows-latest, net8.0, OpenTelemetry.Api.Tests)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / concurrency-tests / run-concurrency-tests (windows-latest, net8.0, OpenTelemetry.Api.Tests)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / concurrency-tests / run-concurrency-tests (windows-latest, net8.0, OpenTelemetry.Api.Tests)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net8.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net8.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net8.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net8.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net8.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net8.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net8.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net8.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net462)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net462)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net462)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net462)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net462)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net462)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net462)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net462)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net8.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net8.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net8.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net8.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net8.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net8.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net8.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net8.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net9.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net9.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net9.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net9.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net9.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net9.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net9.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-experimental / build-test (windows-latest, net9.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net9.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net9.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net9.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net9.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net9.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net9.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net9.0)

Check failure on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / build-test-project-stable / build-test (windows-latest, net9.0)

Check warning on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / lint-dotnet-format / run-dotnet-format-experimental

The keyword 'new' should not be followed by a space

Check warning on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / lint-dotnet-format / run-dotnet-format-experimental

The keyword 'new' should not be followed by a space

Check warning on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / lint-dotnet-format / run-dotnet-format-experimental

The keyword 'new' should not be followed by a space

Check warning on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / lint-dotnet-format / run-dotnet-format-experimental

The keyword 'new' should not be followed by a space

Check warning on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / lint-dotnet-format / run-dotnet-format-experimental

The keyword 'new' should not be followed by a space

Check warning on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / lint-dotnet-format / run-dotnet-format-experimental

The keyword 'new' should not be followed by a space

Check warning on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / lint-dotnet-format / run-dotnet-format-stable

The keyword 'new' should not be followed by a space

Check warning on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / lint-dotnet-format / run-dotnet-format-stable

The keyword 'new' should not be followed by a space

Check warning on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / lint-dotnet-format / run-dotnet-format-stable

The keyword 'new' should not be followed by a space

Check warning on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / lint-dotnet-format / run-dotnet-format-stable

The keyword 'new' should not be followed by a space

Check warning on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / lint-dotnet-format / run-dotnet-format-stable

The keyword 'new' should not be followed by a space

Check warning on line 107 in src/OpenTelemetry.Api/Trace/TracerProvider.cs

View workflow job for this annotation

GitHub Actions / lint-dotnet-format / run-dotnet-format-stable

The keyword 'new' should not be followed by a space
bool result = tracers.TryAdd(key, tracer);
#if DEBUG
System.Diagnostics.Debug.Assert(result, "Write into tracers cache failed");
#else
tracers.TryAdd(key, tracer);
#endif
}
}

return tracer;
}
#endif

/// <inheritdoc/>
protected override void Dispose(bool disposing)
Expand Down Expand Up @@ -99,6 +142,21 @@
base.Dispose(disposing);
}

#if NET9_0_OR_GREATER
internal readonly record struct TracerKey
{
public readonly string Name;
public readonly string? Version;
public readonly IEnumerable<KeyValuePair<string, object?>>? Tags;

public TracerKey(string? name, string? version, IEnumerable<KeyValuePair<string, object?>>? tags)
{
this.Name = name ?? string.Empty;
this.Version = version;
this.Tags = tags?.OrderBy(e => e.Key);
}
}
#else
internal readonly record struct TracerKey
{
public readonly string Name;
Expand All @@ -110,4 +168,5 @@
this.Version = version;
}
}
#endif
}
90 changes: 86 additions & 4 deletions test/OpenTelemetry.Api.Tests/Trace/TracerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@
Assert.NotNull(span3.Activity);
Assert.Equal(span3.Activity.SpanId, Tracer.CurrentSpan.Context.SpanId);

var spanContext = new SpanContext(ActivityTraceId.CreateRandom(), ActivitySpanId.CreateRandom(), ActivityTraceFlags.Recorded);
var spanContext = new SpanContext(ActivityTraceId.CreateRandom(), ActivitySpanId.CreateRandom(),
ActivityTraceFlags.Recorded);

Check warning on line 239 in test/OpenTelemetry.Api.Tests/Trace/TracerTest.cs

View workflow job for this annotation

GitHub Actions / lint-dotnet-format / run-dotnet-format-experimental

The parameters should all be placed on the same line or each parameter should be placed on its own line

Check warning on line 239 in test/OpenTelemetry.Api.Tests/Trace/TracerTest.cs

View workflow job for this annotation

GitHub Actions / lint-dotnet-format / run-dotnet-format-stable

The parameters should all be placed on the same line or each parameter should be placed on its own line
var span4 = this.tracer.StartActiveSpan("Test", SpanKind.Client, spanContext);
Assert.NotNull(span4.Activity);
Assert.Equal(span4.Activity.SpanId, Tracer.CurrentSpan.Context.SpanId);
Expand Down Expand Up @@ -303,8 +304,8 @@
Tracer? tracer1;

using (var tracerProvider = Sdk.CreateTracerProviderBuilder()
.AddSource("mytracer")
.Build())
.AddSource("mytracer")
.Build())
{
provider = tracerProvider;
tracer1 = tracerProvider.GetTracer("mytracer");
Expand Down Expand Up @@ -338,7 +339,8 @@
this.output.WriteLine($"Bugs, if any: {string.Join("\n", test.TestReport.BugReports)}");

var dir = Directory.GetCurrentDirectory();
if (test.TryEmitReports(dir, $"{nameof(this.TracerConcurrencyTest)}_CoyoteOutput", out IEnumerable<string> reportPaths))
if (test.TryEmitReports(dir, $"{nameof(this.TracerConcurrencyTest)}_CoyoteOutput",
out IEnumerable<string> reportPaths))

Check warning on line 343 in test/OpenTelemetry.Api.Tests/Trace/TracerTest.cs

View workflow job for this annotation

GitHub Actions / lint-dotnet-format / run-dotnet-format-experimental

The parameters should all be placed on the same line or each parameter should be placed on its own line

Check warning on line 343 in test/OpenTelemetry.Api.Tests/Trace/TracerTest.cs

View workflow job for this annotation

GitHub Actions / lint-dotnet-format / run-dotnet-format-stable

The parameters should all be placed on the same line or each parameter should be placed on its own line
{
foreach (var reportPath in reportPaths)
{
Expand Down Expand Up @@ -407,7 +409,87 @@
Assert.Empty(tracers);
}
}

Check warning on line 412 in test/OpenTelemetry.Api.Tests/Trace/TracerTest.cs

View workflow job for this annotation

GitHub Actions / lint-dotnet-format / run-dotnet-format-experimental

Code should not contain multiple blank lines in a row

Check warning on line 412 in test/OpenTelemetry.Api.Tests/Trace/TracerTest.cs

View workflow job for this annotation

GitHub Actions / lint-dotnet-format / run-dotnet-format-stable

Code should not contain multiple blank lines in a row

#if NET9_0_OR_GREATER
[Fact]
public void GetTracer_WithTags_ReturnsSameInstanceForSameTags()
{
var tags1 = new List<KeyValuePair<string, object?>> { new("tag1", "value1"), new("tag2", "value2") };
var tags2 = new List<KeyValuePair<string, object?>> { new("tag1", "value1"), new("tag2", "value2") };

using var tracerProvider = new TestTracerProvider();
var tracer1 = tracerProvider.GetTracer("test", "1.0.0", tags1);
var tracer2 = tracerProvider.GetTracer("test", "1.0.0", tags2);

Assert.Equivalent(tracer1, tracer2);
}

[Fact]
public void GetTracer_WithTags_ReturnsDifferentInstancesForDifferentTags()
{
var tags1 = new List<KeyValuePair<string, object?>> { new("tag1", "value1") };
var tags2 = new List<KeyValuePair<string, object?>> { new("tag2", "value2") };

using var tracerProvider = new TestTracerProvider();
var tracer1 = tracerProvider.GetTracer("test", "1.0.0", tags1);
var tracer2 = tracerProvider.GetTracer("test", "1.0.0", tags2);

Assert.NotEqual(tracer1, tracer2);
}

[Fact]
public void GetTracer_WithTags_OrdersTagsByKey()
{
var tags1 = new List<KeyValuePair<string, object?>> { new("tag2", "value2"), new("tag1", "value1"), };
var tags2 = new List<KeyValuePair<string, object?>> { new("tag1", "value1"), new("tag2", "value2"), };

using var tracerProvider = new TestTracerProvider();
var tracer1 = tracerProvider.GetTracer("test", "1.0.0", tags1);
var tracer2 = tracerProvider.GetTracer("test", "1.0.0", tags2);

Assert.Equivalent(tracer1, tracer2);
}

[Fact]
public void GetTracer_WithTagsAndWithoutTags_ReturnsDifferentInstances()
{
var tags = new List<KeyValuePair<string, object?>> { new("tag1", "value1") };

using var tracerProvider = new TestTracerProvider();
var tracerWithTags = tracerProvider.GetTracer("test", "1.0.0", tags);
var tracerWithoutTags = tracerProvider.GetTracer("test", "1.0.0");

Assert.NotSame(tracerWithTags, tracerWithoutTags);
}

[Fact]
public void GetTracer_WithTags_AppliesTagsToActivities()
{
var exportedItems = new List<Activity>();
var tags = new List<KeyValuePair<string, object?>> { new("tracerTag", "tracerValue") };

using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.AddSource("test")
.AddInMemoryExporter(exportedItems)
.SetSampler(new AlwaysOnSampler())
.Build();

var tracer = tracerProvider.GetTracer("test", "1.0.0", tags);

using (var span = tracer.StartActiveSpan("TestSpan"))
{
// Activity started by the tracer with tags
}

Assert.Single(exportedItems);
var activity = exportedItems[0];

// Verify the tracer's tags are applied to the activity
Assert.Contains(activity.Source.Tags, kvp => kvp.Key == "tracerTag" && (string)kvp.Value == "tracerValue");
}
#endif

public void Dispose()
{
Activity.Current = null;
Expand Down
Loading