List of NuGet packages and version that you are using (e.g. OpenTelemetry 0.4.0-beta.2):
Runtime version (e.g. net461, net48, netcoreapp2.1, netcoreapp3.1, etc. You can find this information from the *.csproj file):
A clear and concise description of what the bug is.
When setting up StackExchange.Redis telemetry in ConfigureServices(IServiceCollection services), telemetry messages are not created for the StackExchange.Redis calls.
What did you expect to see?
When calling an API route that contains Redis logic, I expected to see StackExchange.Redis telemetry messages in the console output.
What did you see instead?
No StackExchange.Redis telemetry messages are written to the console output.
A different route using the Http instrumentation writes System.Net.HttpClient telemetry to the console, so there seems to be a bug in the StackExchange.Redis instrumentation.
https://github.com/matthughes404/opentelemetry-redis-testing
We will close this issue if:
I first identified this problem testing out Lightstep, when I did not see the Redis traces show up in their UI. The AspNetCore traces showed up fine in Lightstep, however. To make sure that Lightstep was not the cause, I built a local-only project to reproduce the problem.
I don't think this is a bug, but maybe the documentation is unclear. In your repro case, you're getting a new connection multiplexer in your controller. The Redis instrumentation binds itself to the connection pool that you pass to it, so if you change your ConfigureServices to look like this...
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
var connection = ConnectionMultiplexer.Connect("localhost:6379");
services.AddSingleton<IConnectionMultiplexer>(connection);
services.AddOpenTelemetryTracing(builder => builder
.AddAspNetCoreInstrumentation()
.AddHttpClientInstrumentation()
.AddRedisInstrumentation(connection, opt => opt.FlushInterval = TimeSpan.FromSeconds(1))
.AddConsoleExporter());
}
And your RedisController to look like this...
public class RedisController : ControllerBase
{
private readonly ILogger<RedisController> _logger;
private readonly IConnectionMultiplexer _connectionMultiplexer;
public RedisController(ILogger<RedisController> logger, IConnectionMultiplexer multiplexer)
{
_logger = logger;
_connectionMultiplexer = multiplexer;
}
[HttpGet]
public IActionResult Get()
{
var redis = _connectionMultiplexer.GetDatabase();
var msg = redis.StringGet("testKey01");
_logger.LogInformation(msg);
return Ok(msg.ToString());
}
}
You should see Redis spans in the Console output.
Thanks @austinlparker for helping. Agree the doc doesn't make it obvious that only the connection passed to AddRedisInstrumentation will be instrumented. I'll make a doc fix.
https://github.com/open-telemetry/opentelemetry-dotnet/pull/1638 made a small doc fix to hopefully clarify this.
Thanks a lot... this worked!
Most helpful comment
I don't think this is a bug, but maybe the documentation is unclear. In your repro case, you're getting a new connection multiplexer in your controller. The Redis instrumentation binds itself to the connection pool that you pass to it, so if you change your
ConfigureServicesto look like this...And your RedisController to look like this...
You should see Redis spans in the Console output.