Skip to content

Commit

Permalink
Dependency updates and new builder method added for configuring Open …
Browse files Browse the repository at this point in the history
…Telemetry
  • Loading branch information
melittleman committed Jan 29, 2024
1 parent 474a1e0 commit 45d9bd1
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
using Microsoft.AspNetCore.DataProtection;
using Microsoft.AspNetCore.Authentication.Cookies;

using OpenTelemetry.Trace;
using OpenTelemetry.Instrumentation.StackExchangeRedis;

using NRedisKit.Diagnostics;
using NRedisKit.Authentication;
using NRedisKit.Messaging;
Expand Down Expand Up @@ -166,7 +169,7 @@ internal static IRedisConnectionBuilder ConfigureRedisConnection(
/// </param>
/// <returns>The modified <see cref="IRedisConnectionBuilder" /> to be further chained to.</returns>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="builder"/> is null.</exception>
public static IRedisConnectionBuilder AddHealthCheck(this IRedisConnectionBuilder builder)
public static IRedisConnectionBuilder AddRedisHealthCheck(this IRedisConnectionBuilder builder)
{
if (builder is null) throw new ArgumentNullException(nameof(builder));

Expand Down Expand Up @@ -233,5 +236,22 @@ public static IRedisConnectionBuilder AddRedisStreamsProducer(
return builder;
}

public static IRedisConnectionBuilder AddRedisOpenTelemetry(
this IRedisConnectionBuilder builder,
Action<StackExchangeRedisInstrumentationOptions> configure)
{
if (builder is null) throw new ArgumentNullException(nameof(builder));

builder.Services.AddOpenTelemetry().WithTracing(b => b.AddRedisInstrumentation($"Redis:{builder.Name}", null, configure).ConfigureRedisInstrumentation((s, i) =>
{
IRedisConnectionProvider provider = s.GetRequiredService<IRedisConnectionProvider>();
IRedisContext context = provider.GetRequiredConnection(builder.Name);

i.AddConnection(context.Connection);
}));

return builder;
}

#endregion
}
8 changes: 4 additions & 4 deletions src/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace NRedisKit.Extensions;

internal static class StringExtensions
public static class StringExtensions
{
public static object? ChangeType(this string source, Type type)
internal static object? ChangeType(this string source, Type type)
{
// Try to 'Parse' the value into Type first as this will be
// more better for performance due to not requiring any boxing.
Expand All @@ -17,7 +17,7 @@ internal static class StringExtensions
: default;
}

private static bool TryGetStructOrEnum(this string source, Type type, out object value)
public static bool TryGetStructOrEnum(this string source, Type type, out object value)
{
if (type == typeof(Guid)) return source.TryGetGuid(out value);

Expand All @@ -31,7 +31,7 @@ private static bool TryGetStructOrEnum(this string source, Type type, out object
return false;
}

private static bool TryGetGuid(this string source, out object value)
public static bool TryGetGuid(this string source, out object value)
{
if (Guid.TryParse(source, out Guid result))
{
Expand Down
17 changes: 10 additions & 7 deletions src/NRedisKit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,20 @@

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="2.1.34" />
<PackageReference Include="Microsoft.AspNetCore.DataProtection" Version="6.0.14" />
<PackageReference Include="Microsoft.AspNetCore.DataProtection.StackExchangeRedis" Version="6.0.14" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
<PackageReference Include="Microsoft.AspNetCore.DataProtection" Version="8.0.1" />
<PackageReference Include="Microsoft.AspNetCore.DataProtection.StackExchangeRedis" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />

<PackageReference Include="IdentityModel" Version="6.0.0" />
<PackageReference Include="NRedisStack" Version="0.10.1" />
<PackageReference Include="OpenTelemetry" Version="1.7.0" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.7.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.StackExchangeRedis" Version="1.0.0-rc9.13" />
<PackageReference Include="StackExchange.Redis" Version="2.6.122" />
<PackageReference Include="System.Text.Json" Version="7.0.2" />
<PackageReference Include="System.Text.Json" Version="8.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions test/UnitTest/NRedisKit.UnitTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="Moq" Version="4.18.4" />
<PackageReference Include="StackExchange.Redis" Version="2.6.122" />
Expand Down

0 comments on commit 45d9bd1

Please sign in to comment.