-
Notifications
You must be signed in to change notification settings - Fork 102
Add OpenTelemetry Package #1172
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1fca144
otel: add OpenTelemetry package
mtmk 807a4d8
Merge branch 'release/3.0' into nats-otel-pkg
mtmk 176e367
otel: add options configure overload
mtmk eb45395
otel: add subject-pattern trace filter helper
mtmk a252d58
Merge remote-tracking branch 'origin/release/3.0' into nats-otel-pkg
mtmk 72ee48e
Merge remote-tracking branch 'origin/release/3.0' into nats-otel-pkg
mtmk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| namespace NATS.Client.Core; | ||
|
|
||
| /// <summary> | ||
| /// Telemetry identifiers for NATS .NET. Use these when configuring OpenTelemetry | ||
| /// or any other listener directly. The same name is used for both the | ||
| /// <see cref="System.Diagnostics.ActivitySource"/> and the | ||
| /// <see cref="System.Diagnostics.Metrics.Meter"/>. | ||
| /// </summary> | ||
| public static class NatsTelemetry | ||
| { | ||
| public const string SourceName = "NATS.Net"; | ||
| } | ||
17 changes: 17 additions & 0 deletions
17
src/NATS.Client.OpenTelemetry/NATS.Client.OpenTelemetry.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <!-- NuGet Packaging --> | ||
| <PackageTags>opentelemetry;tracing;metrics;observability;nats</PackageTags> | ||
| <Description>OpenTelemetry instrumentation for NATS .NET. Adds the ActivitySource and Meter for the client to a TracerProviderBuilder or MeterProviderBuilder.</Description> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="OpenTelemetry.Api" Version="1.15.3" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\NATS.Client.Core\NATS.Client.Core.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
22 changes: 22 additions & 0 deletions
22
src/NATS.Client.OpenTelemetry/NatsInstrumentationExtensions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| using NATS.Client.Core; | ||
| using OpenTelemetry.Metrics; | ||
| using OpenTelemetry.Trace; | ||
|
|
||
| namespace NATS.Client.OpenTelemetry; | ||
|
|
||
| public static class NatsInstrumentationExtensions | ||
| { | ||
| /// <summary> | ||
| /// Adds the NATS .NET client <see cref="System.Diagnostics.ActivitySource"/> to the tracer provider, | ||
| /// enabling distributed tracing for publish, subscribe, and request/reply operations. | ||
| /// </summary> | ||
| public static TracerProviderBuilder AddNatsClientInstrumentation(this TracerProviderBuilder builder) => | ||
| builder.AddSource(NatsTelemetry.SourceName); | ||
|
|
||
| /// <summary> | ||
| /// Adds the NATS .NET client <see cref="System.Diagnostics.Metrics.Meter"/> to the meter provider, | ||
| /// enabling messaging metrics (published/consumed counters, operation duration, and more). | ||
| /// </summary> | ||
| public static MeterProviderBuilder AddNatsClientInstrumentation(this MeterProviderBuilder builder) => | ||
| builder.AddMeter(NatsTelemetry.SourceName); | ||
|
mtmk marked this conversation as resolved.
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
tests/NATS.Net.OpenTelemetry.Tests/NatsInstrumentationExtensionsTest.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| using NATS.Client.OpenTelemetry; | ||
| using OpenTelemetry; | ||
| using OpenTelemetry.Metrics; | ||
| using OpenTelemetry.Trace; | ||
|
|
||
| namespace NATS.Client.Core.Tests; | ||
|
|
||
| public class NatsInstrumentationExtensionsTest | ||
| { | ||
| [Fact] | ||
| public void AddNatsClientInstrumentation_builds_tracer_provider() | ||
| { | ||
| using var provider = Sdk.CreateTracerProviderBuilder() | ||
| .AddNatsClientInstrumentation() | ||
| .Build(); | ||
|
|
||
| provider.Should().NotBeNull(); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void AddNatsClientInstrumentation_builds_meter_provider() | ||
| { | ||
| using var provider = Sdk.CreateMeterProviderBuilder() | ||
| .AddNatsClientInstrumentation() | ||
| .Build(); | ||
|
|
||
| provider.Should().NotBeNull(); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void SourceName_is_NATS_Net() | ||
| { | ||
| NatsTelemetry.SourceName.Should().Be("NATS.Net"); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.