diff --git a/src/Honeycomb.OpenTelemetry/ServiceCollectionExtensions.cs b/src/Honeycomb.OpenTelemetry/ServiceCollectionExtensions.cs index d0b8a43..4f20b3b 100644 --- a/src/Honeycomb.OpenTelemetry/ServiceCollectionExtensions.cs +++ b/src/Honeycomb.OpenTelemetry/ServiceCollectionExtensions.cs @@ -2,6 +2,7 @@ using Microsoft.Extensions.DependencyInjection; using OpenTelemetry; using OpenTelemetry.Trace; +using StackExchange.Redis; using System.Collections.Generic; namespace Honeycomb.OpenTelemetry @@ -12,7 +13,7 @@ namespace Honeycomb.OpenTelemetry public static class ServiceCollectionExtensions { /// - /// Configures the to send telemetry data to Honycomb using options created from an instance of . + /// Configures the to send telemetry data to Honeycomb using options created from an instance of . /// public static IServiceCollection UseHoneycomb(this IServiceCollection services, IConfiguration configuration) { @@ -20,25 +21,33 @@ public static IServiceCollection UseHoneycomb(this IServiceCollection services, } /// - /// Configures the to send telemetry data to Honycomb using an instance of . + /// Configures the to send telemetry data to Honeycomb using an instance of . /// public static IServiceCollection UseHoneycomb(this IServiceCollection services, HoneycombOptions options) { return services - .AddOpenTelemetryTracing(builder => builder - .UseHoneycomb(options) - .AddAspNetCoreInstrumentation(opts => + .AddOpenTelemetryTracing(hostingBuilder => hostingBuilder.Configure(((serviceProvider, builder) => { - opts.RecordException = true; - opts.Enrich = (activity, eventName, _) => - { - if (eventName == "OnStartActivity") - foreach (KeyValuePair entry in Baggage.Current) + builder + .UseHoneycomb(options) + .AddAspNetCoreInstrumentation(opts => + { + opts.RecordException = true; + opts.Enrich = (activity, eventName, _) => { - activity.SetTag(entry.Key, entry.Value); - } - }; - }) + if (eventName == "OnStartActivity") + foreach (KeyValuePair entry in Baggage.Current) + { + activity.SetTag(entry.Key, entry.Value); + } + }; + }); + if (options.RedisConnection == null && + serviceProvider.GetService(typeof(IConnectionMultiplexer)) != null) + { + builder.AddRedisInstrumentation(); + } + })) ) .AddSingleton(TracerProvider.Default.GetTracer(options.ServiceName)); } diff --git a/src/Honeycomb.OpenTelemetry/TracerProviderBuilderExtensions.cs b/src/Honeycomb.OpenTelemetry/TracerProviderBuilderExtensions.cs index 10c6c2d..b8a5bc6 100644 --- a/src/Honeycomb.OpenTelemetry/TracerProviderBuilderExtensions.cs +++ b/src/Honeycomb.OpenTelemetry/TracerProviderBuilderExtensions.cs @@ -13,7 +13,7 @@ namespace Honeycomb.OpenTelemetry public static class TracerProviderBuilderExtensions { /// - /// Configures the to send telemetry data to Honycomb using options created from command line arguments. + /// Configures the to send telemetry data to Honeycomb using options created from command line arguments. /// public static TracerProviderBuilder UseHoneycomb(this TracerProviderBuilder builder, string[] args) { @@ -21,7 +21,7 @@ public static TracerProviderBuilder UseHoneycomb(this TracerProviderBuilder buil } /// - /// Configures the to send telemetry data to Honycomb using options created from an instance of . + /// Configures the to send telemetry data to Honeycomb using options created from an instance of . /// public static TracerProviderBuilder UseHoneycomb(this TracerProviderBuilder builder, IConfiguration configuration) { @@ -29,7 +29,7 @@ public static TracerProviderBuilder UseHoneycomb(this TracerProviderBuilder buil } /// - /// Configures the to send telemetry data to Honycomb using an instance of . + /// Configures the to send telemetry data to Honeycomb using an instance of . /// public static TracerProviderBuilder UseHoneycomb(this TracerProviderBuilder builder, HoneycombOptions options) {