Skip to content

Commit

Permalink
Allow redis instrumentation with dependency injected connection (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
vreynolds authored Jul 22, 2021
1 parent a745c8b commit 02969d8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
37 changes: 23 additions & 14 deletions src/Honeycomb.OpenTelemetry/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.Extensions.DependencyInjection;
using OpenTelemetry;
using OpenTelemetry.Trace;
using StackExchange.Redis;
using System.Collections.Generic;

namespace Honeycomb.OpenTelemetry
Expand All @@ -12,33 +13,41 @@ namespace Honeycomb.OpenTelemetry
public static class ServiceCollectionExtensions
{
/// <summary>
/// Configures the <see cref="IServiceCollection"/> to send telemetry data to Honycomb using options created from an instance of <see cref="IConfiguration"/>.
/// Configures the <see cref="IServiceCollection"/> to send telemetry data to Honeycomb using options created from an instance of <see cref="IConfiguration"/>.
/// </summary>
public static IServiceCollection UseHoneycomb(this IServiceCollection services, IConfiguration configuration)
{
return services.UseHoneycomb(HoneycombOptions.FromConfiguration(configuration));
}

/// <summary>
/// Configures the <see cref="IServiceCollection"/> to send telemetry data to Honycomb using an instance of <see cref="HoneycombOptions"/>.
/// Configures the <see cref="IServiceCollection"/> to send telemetry data to Honeycomb using an instance of <see cref="HoneycombOptions"/>.
/// </summary>
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<string, string> 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<string, string> 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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,23 @@ namespace Honeycomb.OpenTelemetry
public static class TracerProviderBuilderExtensions
{
/// <summary>
/// Configures the <see cref="TracerProviderBuilder"/> to send telemetry data to Honycomb using options created from command line arguments.
/// Configures the <see cref="TracerProviderBuilder"/> to send telemetry data to Honeycomb using options created from command line arguments.
/// </summary>
public static TracerProviderBuilder UseHoneycomb(this TracerProviderBuilder builder, string[] args)
{
return builder.UseHoneycomb(HoneycombOptions.FromArgs(args));
}

/// <summary>
/// Configures the <see cref="TracerProviderBuilder"/> to send telemetry data to Honycomb using options created from an instance of <see cref="IConfiguration"/>.
/// Configures the <see cref="TracerProviderBuilder"/> to send telemetry data to Honeycomb using options created from an instance of <see cref="IConfiguration"/>.
/// </summary>
public static TracerProviderBuilder UseHoneycomb(this TracerProviderBuilder builder, IConfiguration configuration)
{
return builder.UseHoneycomb(HoneycombOptions.FromConfiguration(configuration));
}

/// <summary>
/// Configures the <see cref="TracerProviderBuilder"/> to send telemetry data to Honycomb using an instance of <see cref="HoneycombOptions"/>.
/// Configures the <see cref="TracerProviderBuilder"/> to send telemetry data to Honeycomb using an instance of <see cref="HoneycombOptions"/>.
/// </summary>
public static TracerProviderBuilder UseHoneycomb(this TracerProviderBuilder builder, HoneycombOptions options)
{
Expand Down

0 comments on commit 02969d8

Please sign in to comment.