| | 1 | | // Copyright (c) ZeroC, Inc. |
| | 2 | |
|
| | 3 | | using IceRpc.Telemetry; |
| | 4 | | using System.Diagnostics; |
| | 5 | |
|
| | 6 | | namespace IceRpc.Extensions.DependencyInjection; |
| | 7 | |
|
| | 8 | | /// <summary>Provides an extension method for <see cref="IDispatcherBuilder" /> to add the telemetry middleware. |
| | 9 | | /// </summary> |
| | 10 | | public static class TelemetryDispatcherBuilderExtensions |
| | 11 | | { |
| | 12 | | /// <summary>Adds a <see cref="TelemetryMiddleware" /> to the dispatcher builder.</summary> |
| | 13 | | /// <param name="builder">The builder being configured.</param> |
| | 14 | | /// <returns>The builder being configured.</returns> |
| | 15 | | public static IDispatcherBuilder UseTelemetry(this IDispatcherBuilder builder) => |
| 0 | 16 | | builder.ServiceProvider.GetService(typeof(ActivitySource)) is ActivitySource activitySource ? |
| 0 | 17 | | builder.Use(next => new TelemetryMiddleware(next, activitySource)) : |
| 0 | 18 | | throw new InvalidOperationException( |
| 0 | 19 | | $"Could not find service of type '{nameof(ActivitySource)}' in the service container."); |
| | 20 | | } |