Skip to content
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

Support redis instrumentation for keyed service #1157

Merged
merged 6 commits into from
Jan 13, 2024

Conversation

Kahbazi
Copy link
Member

@Kahbazi Kahbazi commented Nov 30, 2023

Temporary fixes #1045

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-codeflow for labeling automated codeflow. intentionally a different color! label Nov 30, 2023
Comment on lines 53 to 58
var instrumentation = Activator.CreateInstance(
typeof(StackExchangeRedisInstrumentation),
BindingFlags.NonPublic | BindingFlags.Instance,
null,
new object[] { sp.GetRequiredService<IOptionsMonitor<StackExchangeRedisInstrumentationOptions>>() },
null) as StackExchangeRedisInstrumentation;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use UnsafeAccessor?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

internal static class TempOpenTelemetry
{
[UnsafeAccessor(UnsafeAccessorKind.Constructor)]
static extern StackExchangeRedisInstrumentation CreateInstrumentation(IOptionsMonitor<StackExchangeRedisInstrumentationOptions> options);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is beautiful 😄

@danmoseley danmoseley added area-integrations Issues pertaining to Aspire Integrations packages and removed area-codeflow for labeling automated codeflow. intentionally a different color! labels Dec 6, 2023

if (connection != null)
{
instrumentation.AddConnection(Options.DefaultName, connection);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
instrumentation.AddConnection(Options.DefaultName, connection);
instrumentation.AddConnection(serviceKey.ToString(), connection);

? What happens if there are more than 1 keyed Redis connections?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current implementation for non-keyed redis connection uses Options.DefaultName I wanted to keep the implementation consistence with it.

I think the name is used to get named options for StackExchangeRedisInstrumentationOptions
https://github.com/open-telemetry/opentelemetry-dotnet-contrib/blob/fbfd66495359a88738bc0f5611bc7728c568ce5a/src/OpenTelemetry.Instrumentation.StackExchangeRedis/StackExchangeRedisInstrumentation.cs#L44

and for the Thread name responsible for creating redis Activity.
https://github.com/open-telemetry/opentelemetry-dotnet-contrib/blob/fbfd66495359a88738bc0f5611bc7728c568ce5a/src/OpenTelemetry.Instrumentation.StackExchangeRedis/StackExchangeRedisConnectionInstrumentation.cs#L56

? What happens if there are more than 1 keyed Redis connections?
The same thing that if there are more than 1 non-keyed redis connections. I don't see any problem. Am I missing something?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the name is used to get named options

This is the part I was missing.

I think this fine for now, but when we take open-telemetry/opentelemetry-dotnet-contrib#1457, we should probably be specifying the name, so someone can configure these options separately from the other Redis connections.

@joperezr joperezr added the community-contribution Indicates that the PR has been added by a community member label Dec 11, 2023
Copy link
Member

@eerhardt eerhardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Kahbazi for the bug fix!

I added the test we discussed above. LGTM. Will merge this once CI passes.

@eerhardt eerhardt enabled auto-merge (squash) January 12, 2024 23:41
@eerhardt eerhardt merged commit 3ae1e8f into dotnet:main Jan 13, 2024
8 checks passed
@Kahbazi Kahbazi deleted the kahbazi/RedisKeyedService branch January 13, 2024 12:50
@github-actions github-actions bot locked and limited conversation to collaborators Apr 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-integrations Issues pertaining to Aspire Integrations packages community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support tracing when AddRedis used with a serviceKey
5 participants