OpenTelemetry.Instrumentation.StackExchangeRedis 1.12.0-beta.2

Prefix Reserved
This is a prerelease version of OpenTelemetry.Instrumentation.StackExchangeRedis.
dotnet add package OpenTelemetry.Instrumentation.StackExchangeRedis --version 1.12.0-beta.2
                    
NuGet\Install-Package OpenTelemetry.Instrumentation.StackExchangeRedis -Version 1.12.0-beta.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="OpenTelemetry.Instrumentation.StackExchangeRedis" Version="1.12.0-beta.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="OpenTelemetry.Instrumentation.StackExchangeRedis" Version="1.12.0-beta.2" />
                    
Directory.Packages.props
<PackageReference Include="OpenTelemetry.Instrumentation.StackExchangeRedis" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add OpenTelemetry.Instrumentation.StackExchangeRedis --version 1.12.0-beta.2
                    
#r "nuget: OpenTelemetry.Instrumentation.StackExchangeRedis, 1.12.0-beta.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package OpenTelemetry.Instrumentation.StackExchangeRedis@1.12.0-beta.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=OpenTelemetry.Instrumentation.StackExchangeRedis&version=1.12.0-beta.2&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=OpenTelemetry.Instrumentation.StackExchangeRedis&version=1.12.0-beta.2&prerelease
                    
Install as a Cake Tool

StackExchange.Redis Instrumentation for OpenTelemetry

Status
Stability Beta
Code Owners @matt-hensley

NuGet version badge NuGet download count badge codecov.io

This is an Instrumentation Library, which instruments StackExchange.Redis and collects traces about outgoing calls to Redis.

This component is based on the OpenTelemetry semantic conventions for traces. These conventions are Experimental, and hence, this package is a pre-release. Until a stable version is released, there can be breaking changes.

Steps to enable OpenTelemetry.Instrumentation.StackExchangeRedis

Step 1: Install Package

Add a reference to the OpenTelemetry.Instrumentation.StackExchangeRedis package. Also, add any other instrumentations & exporters you will need.

dotnet add package OpenTelemetry.Instrumentation.StackExchangeRedis

Step 2: Enable StackExchange.Redis Instrumentation at application startup

StackExchange.Redis instrumentation must be enabled at application startup. AddRedisInstrumentation method on TracerProviderBuilder must be called to enable Redis instrumentation, passing the IConnectionMultiplexer instance used to make Redis calls. Only those Redis calls made using the same instance of the IConnectionMultiplexer will be instrumented.

The following example demonstrates adding StackExchange.Redis instrumentation to a console application. This example also sets up the OpenTelemetry Console exporter, which requires adding the package OpenTelemetry.Exporter.Console to the application.

using OpenTelemetry.Trace;

public class Program
{
    public static void Main(string[] args)
    {
        // Connect to the server.
        using var connection = ConnectionMultiplexer.Connect("localhost:6379");

        using var tracerProvider = Sdk.CreateTracerProviderBuilder()
            .AddRedisInstrumentation(connection)
            .AddConsoleExporter()
            .Build();
    }
}

For an ASP.NET Core application, adding instrumentation is typically done in the ConfigureServices of your Startup class. Refer to documentation for OpenTelemetry.Instrumentation.AspNetCore.

For an ASP.NET application, adding instrumentation is typically done in the Global.asax.cs. Refer to documentation for OpenTelemetry.Instrumentation.AspNet.

Specify the Redis connection

The following sections cover different ways to specify the StackExchange.Redis connection(s) that will be instrumented and captured by OpenTelemetry.

Pass a Redis connection when calling AddRedisInstrumentation

The simplest thing to do is pass a created connection to the AddRedisInstrumentation extension method:

using var connection = ConnectionMultiplexer.Connect("localhost:6379");

using var tracerProvider = Sdk.CreateTracerProviderBuilder()
    .AddRedisInstrumentation(connection)
    .Build();

Whatever connection is specified will be collected by OpenTelemetry.

Use the application IServiceProvider

Users using the OpenTelemetry.Extensions.Hosting package may prefer to manage the Redis connection via the application IServiceCollection. To support this scenario, if a connection is not passed to the AddRedisInstrumentation extension manually one will be resolved one using the IServiceProvider:

appBuilder.Services.AddSingleton<IConnectionMultiplexer>(
    sp => MyRedisConnectionHelper.CreateConnection(sp));

appBuilder.Services
    .AddOpenTelemetry()
    .WithTracing(tracing => tracing.AddRedisInstrumentation());

Whatever connection is found in the IServiceProvider will be collected by OpenTelemetry.

Interact with StackExchangeRedisInstrumentation directly

For full control of the Redis connection(s) being instrumented the ConfigureRedisInstrumentation extension is provided to expose the StackExchangeRedisInstrumentation class directly:

StackExchangeRedisInstrumentation redisInstrumentation = null;

using var tracerProvider = Sdk.CreateTracerProviderBuilder()
    .AddRedisInstrumentation()
    .ConfigureRedisInstrumentation(instrumentation => redisInstrumentation = instrumentation)
    .Build();

using var connection1 = ConnectionMultiplexer.Connect("localhost:6379");
redisInstrumentation.AddConnection(connection1);

using var connection2 = ConnectionMultiplexer.Connect("localhost:6380");
redisInstrumentation.AddConnection(connection2);

Connections may be added or removed at any time.

Advanced configuration

This instrumentation can be configured to change the default behavior by using StackExchangeRedisCallsInstrumentationOptions.

FlushInterval

StackExchange.Redis has its own internal profiler. OpenTelemetry converts each profiled command from the internal profiler to an Activity for collection. By default, this conversion process flushes profiled commands on a 10 second interval. The FlushInterval option can be used to adjust this interval.

The following example shows how to use FlushInterval.

using var tracerProvider = Sdk.CreateTracerProviderBuilder()
    .AddRedisInstrumentation(
        connection,
        options => options.FlushInterval = TimeSpan.FromSeconds(5))
    .AddConsoleExporter()
    .Build();

SetVerboseDatabaseStatements

StackExchange.Redis by default does not give detailed database statements like what key or script was used during an operation. The SetVerboseDatabaseStatements option can be used to enable gathering this more detailed information.

The following example shows how to use SetVerboseDatabaseStatements.

using var tracerProvider = Sdk.CreateTracerProviderBuilder()
    .AddRedisInstrumentation(
        connection,
        options => options.SetVerboseDatabaseStatements = true)
    .AddConsoleExporter()
    .Build();

Enrich

This option allows one to enrich the activity with additional information from the raw IProfiledCommand object. The Enrich action is called only when activity.IsAllDataRequested is true. It contains the activity itself (which can be enriched), and the source profiled command object.

The following code snippet shows how to add additional tags using Enrich.

using var tracerProvider = Sdk.CreateTracerProviderBuilder()
    .AddRedisInstrumentation(opt => opt.Enrich = (activity, command) =>
    {
        if (command.ElapsedTime < TimeSpan.FromMilliseconds(100))
        {
            activity.SetTag("is_fast", true);
        }
    })
    .Build();

References

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (38)

Showing the top 5 NuGet packages that depend on OpenTelemetry.Instrumentation.StackExchangeRedis:

Package Downloads
Grafana.OpenTelemetry

Full Grafana distribution of OpenTelemetry .NET

Honeycomb.OpenTelemetry.CommonInstrumentations

Honeycomb's OpenTelemetry common instrumentations package. Adds support for many common instrumentation libraries for you.

SPG.Common.AspNetCore

ASP.NET core helper classes used by SPG products

GreatUtilities.Web

Essencial tools to agile development.

Newguys.Telemetry

Package Description

GitHub repositories (10)

Showing the top 10 popular GitHub repositories that depend on OpenTelemetry.Instrumentation.StackExchangeRedis:

Repository Stars
Dotnet-Boxed/Templates
.NET project templates with batteries included, providing the minimum amount of code required to get you going faster.
exceptionless/Exceptionless
Exceptionless application
thangchung/clean-architecture-dotnet
🕸 Yet Another .NET Clean Architecture, but for Microservices project. It uses Minimal Clean Architecture with DDD-lite, CQRS-lite, and just enough Cloud-native patterns apply on the simple eCommerce sample and run on Tye with Dapr extension 🍻
GZTimeWalker/GZCTF
The GZ::CTF project, an open source CTF platform.
Aguafrommars/TheIdServer
OpenID/Connect, OAuth2, WS-Federation and SAML 2.0 server based on Duende IdentityServer and ITFoxtec Identity SAML 2.0 with its admin UI
mikolaj-jankowski/Clean-Architecture-And-Domain-Driven-Design-Solution-Template
.NET Core template in DDD and Clean Architecture approach.
Universalis-FFXIV/Universalis
A crowdsourced market board API for FFXIV.
Azure/modern-web-app-pattern-dotnet
The Modern Web App Pattern is a set of objectives to help you apply an iterative change to modernize a cloud deployed monolith. This content builds on the Reliable Web App. This repo contains a reference implementation of a Modern Web App for .NET.
SapiensAnatis/Dawnshard
Server emulator for Dragalia Lost
marinasundstrom/YourBrand
Prototype enterprise system for e-commerce and consulting services
Version Downloads Last Updated
1.12.0-beta.2 309 7/28/2025
1.12.0-beta.1 165,572 5/6/2025
1.11.0-beta.2 425,623 3/5/2025
1.11.0-beta.1 313,370 1/27/2025
1.10.0-beta.1 291,068 12/9/2024
1.9.0-beta.1 2,960,882 7/23/2024
1.0.0-rc9.15 1,344,356 6/18/2024
1.0.0-rc9.14 2,300,755 4/5/2024
1.0.0-rc9.13 970,182 1/4/2024
1.0.0-rc9.12 978,257 11/1/2023
1.0.0-rc9.11 12,543 10/31/2023
1.0.0-rc9.10 2,711,839 6/9/2023
1.0.0-rc9.9 199,882 5/25/2023
1.0.0-rc9.8 2,219,317 2/28/2023
1.0.0-rc9.7 2,378,467 7/25/2022
1.0.0-rc9.6 356,689 6/30/2022
1.0.0-rc9.5 707,869 6/7/2022
1.0.0-rc9.4 144,299 6/3/2022
1.0.0-rc9.3 393,257 4/20/2022
1.0.0-rc9.2 112,587 4/13/2022
1.0.0-rc9.1 129,931 3/30/2022
1.0.0-rc9 668,324 2/3/2022
1.0.0-rc8 894,278 10/8/2021
1.0.0-rc7 253,742 7/13/2021
1.0.0-rc6 40,014 6/26/2021
1.0.0-rc5 6,493 6/9/2021
1.0.0-rc4 112,043 4/23/2021
1.0.0-rc3 99,415 3/19/2021
1.0.0-rc2 174,638 1/30/2021
1.0.0-rc1.1 78,640 11/18/2020
0.8.0-beta.1 1,059 11/5/2020
0.7.0-beta.1 1,016 10/16/2020
0.6.0-beta.1 40,223 9/16/2020
0.5.0-beta.2 1,618 8/28/2020
0.4.0-beta.2 33,507 7/25/2020
0.3.0-beta.1 517 7/23/2020