-
Notifications
You must be signed in to change notification settings - Fork 305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[redis] Support manual connection management #1193
[redis] Support manual connection management #1193
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #1193 +/- ##
=======================================
Coverage ? 73.16%
=======================================
Files ? 260
Lines ? 9130
Branches ? 0
=======================================
Hits ? 6680
Misses ? 2450
Partials ? 0
|
src/OpenTelemetry.Instrumentation.StackExchangeRedis/TracerProviderBuilderExtensions.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved, but just sharing an idea. Curious about your thoughts.
StackExchangeRedisInstrumentation redisInstrumentation = null; | ||
|
||
using var tracerProvider = Sdk.CreateTracerProviderBuilder() | ||
.AddRedisInstrumentation() | ||
.ConfigureRedisInstrumentation(instrumentation => redisInstrumentation = instrumentation) | ||
.Build(); | ||
|
||
using var connection1 = ConnectionMultiplexer.Connect("localhost:6379"); | ||
redisInstrumentation.AddConnection(connection1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have strong feelings against this pattern, but it does seem a bit awkward to me. Given that we add instrumentation to a tracer provider it might feel more natural if we had a way to ask the tracer provider for a handle to the instrumentation. Something like
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.AddRedisInstrumentation()
.Build();
using var connection1 = ConnectionMultiplexer.Connect("localhost:6379");
tracerProvider.GetInstrumentation<StackExchangeRedisInstrumentation>().AddConnection(connection1);
But I also don't feel strongly about adding a GetInstrumentation
method to TracerProvider either since this Redis instrumentation is the only instrumentation where this seems to make sense today - and of course most of our instrumentation classes are not public anyways.
This is just food for thought, at the end of the day I understand this is the advanced scenario.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a very interesting idea. We had the need somewhere (PrometheusExporter?) to find the registered exporter so this type of thing does seem to have some utility. But I'm not sure we have seen enough need to justify a public API.
This particular API (ConfigureRedisInstrumentation
) isn't actually needed at all. Users could do this...
var builder = Sdk.CreateTracerProviderBuilder()
.AddRedisInstrumentation();
StackExchangeRedisInstrumentation redisInstrumentation = null;
((IDeferredTracerProviderBuilder)builder).Configure((sp, builder) =>
redisInstrumentation = sp.GetRequiredService<StackExchangeRedisInstrumentation>());
using var tracerProvider = builder.Build();
I just thought it was so nasty we should have a helper to clean it up 🤣
Using IServiceCollection
style it is much nicer:
appBuilder.Services.AddOpenTelemetry().WithTracing(builder => builder.AddRedisInstrumentation());
var app = appBuilder.Build();
var instrumentation = app.Services.GetRequiredService<StackExchangeRedisInstrumentation>();
The reason the first one is so nasty is in the "Sdk.Create" style we don't expose the IServiceProvider
directly so it is kind of hard to get at. Might also be a useful public API addition to expose the IServiceProvider
behind the provider instance?
…tps://github.com/CodeBlanch/opentelemetry-dotnet-contrib into stackexchangeredis-ConfigureRedisInstrumentation
|
||
lock (this.InstrumentedConnections) | ||
{ | ||
var instrumentation = new StackExchangeRedisConnectionInstrumentation(connection, options); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to allow multiple connections? If yes, we should probably update the thread name to be distinct when instantiating multiple instances of StackExchangeRedisConnectionInstrumentation
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes one of the goals was to support multiple connections. You can actually have multiple connections today by calling AddRedisInstrumentation
repeatedly. Let me tackle this as a follow-up. Thinking maybe I can move the thread up a level so we don't have as many.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When our application calls AddRedisInstrumentation
multiple times (to instrument different connections), we get duplicate spans in our traces (one for each instrumented connection even though the Redis call is only being directed to one of those connections). Is there a way to avoid the duplicate spans?
Seeing this duplicate span behavior so far in the following versions:
OpenTelemetry.Instrumentation.StackExchangeRedis v1.0.0-rc9.9
OpenTelemetry.Instrumentation.StackExchangeRedis v1.0.0-rc9.8
OpenTelemetry.Instrumentation.StackExchangeRedis v1.0.0-rc9.7
Can continue testing up to the current version if that helps.
I submitted this PR (#2001) in an attempt to address what we are seeing in our application, but the changes haven't been well received, so they may not be merged.
Open to other solutions, but so far coming up empty.
This feature is now available in OpenTelemetry.Instrumentation.StackExchangeRedis v1.0.0-rc9.9 |
[This is an alternative design to what was proposed on #1139]
/cc @lucasoares @lachmatt
Changes
StackExchangeRedisInstrumentation
to allow for manual management of the instrumented Redis connectionsUsage
Public API Changes
TODOs
CHANGELOG.md
updated for non-trivial changes