Skip to content

Commit

Permalink
fix: Added missing extension to enable mediator tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
jhartmann123 committed Sep 11, 2024
1 parent de07b37 commit 543d456
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
6 changes: 6 additions & 0 deletions docs/AspNetCore/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,10 @@ container.RegisterMediatorTracingDecorators();
container.RegisterMediator( /* Mediator configuration */ );
```

Also, when configuring the OpenTelemetry-Tracer, you need to enable the instrumentation:
```
services.AddOpenTelemetry()
.WithTracing(tracer => tracer.AddMediatorInstrumentation());
```

Note that the order matters. You must register the tracing decorators before mediator.
3 changes: 2 additions & 1 deletion src/AspNetCore/src/OpenTelemetry/ContainerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ namespace Fusonic.Extensions.AspNetCore.OpenTelemetry;
public static class ContainerExtensions
{
/// <summary>
/// Adds decorators for tracing mediator requests and notifications.
/// Adds decorators for tracing mediator requests and notifications.<br/>
/// Note: You also need to call <see cref="TracerProviderBuilderExtensions.AddMediatorInstrumentation"/> to enable tracing.
/// </summary>
/// <param name="container">The SimpleInjector container</param>
public static void RegisterMediatorTracingDecorators(this Container container)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) Fusonic GmbH. All rights reserved.
// Licensed under the MIT License. See LICENSE file in the project root for license information.

using OpenTelemetry.Trace;

namespace Fusonic.Extensions.AspNetCore.OpenTelemetry;

public static class TracerProviderBuilderExtensions
{
/// <summary>
/// Enables tracing for mediator requests and notifications.<br/>
/// Note: You also need to call <see cref="ContainerExtensions.RegisterMediatorTracingDecorators"/> to enable tracing.
/// </summary>
public static TracerProviderBuilder AddMediatorInstrumentation(this TracerProviderBuilder builder)
=> builder.AddSource(MediatorTracer.ActivitySourceName);
}
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>9.3.0</Version>
<Version>9.3.1</Version>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

Expand Down

0 comments on commit 543d456

Please sign in to comment.