Skip to content

Commit

Permalink
Add OpenTelemetry extension
Browse files Browse the repository at this point in the history
  • Loading branch information
Cooksauce committed Jan 29, 2024
1 parent ef61c13 commit 8165b65
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/NATS.Net.OpenTelemetry/NATS.Net.OpenTelemetry.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,12 @@

</PropertyGroup>

<ItemGroup>
<PackageReference Include="OpenTelemetry" Version="1.6.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\NATS.Client.Core\NATS.Client.Core.csproj" />
</ItemGroup>

</Project>
23 changes: 23 additions & 0 deletions src/NATS.Net.OpenTelemetry/OpenTelemetryTracingExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using NATS.Client.Core;

// ReSharper disable once CheckNamespace - Place in OTEL namespace for discoverability
namespace OpenTelemetry.Trace;

public static class OpenTelemetryTracingExtensions
{
/// <summary>
/// Enables trace collection on activity sources from the NATS.Client nuget package.
/// </summary>
/// <param name="builder"><see cref="TracerProviderBuilder"/> being configured.</param>
/// <param name="includeInternal">Include traces from internal messaging used for control flow and lower level usage during high level abstractions (e.g. JetStream, KvStore, etc)</param>
/// <returns>The same instance of <see cref="TracerProviderBuilder"/> to chain the calls.</returns>
public static TracerProviderBuilder AddNatsInstrumentation(this TracerProviderBuilder builder, bool includeInternal = false)
{
builder.AddSource("NATS.Client");

if (includeInternal)
builder.AddSource("NATS.Client.Internal");

return builder;
}
}

0 comments on commit 8165b65

Please sign in to comment.