From eedaf7ceccb2a35ee31eb29bcbb6268c6e82403c Mon Sep 17 00:00:00 2001 From: Tiago Araujo Date: Fri, 16 Aug 2024 19:02:00 +0100 Subject: [PATCH] feat: add attr server.port if is not default 6379 --- .../RedisProfilerEntryInstrumenter.cs | 17 +++++++++++++---- ...ackExchangeRedisInstrumentationExtensions.cs | 3 +++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/OpenTelemetry.Instrumentation.StackExchangeRedis/Implementation/RedisProfilerEntryInstrumenter.cs b/src/OpenTelemetry.Instrumentation.StackExchangeRedis/Implementation/RedisProfilerEntryInstrumenter.cs index 36eb26e208..73d63a212d 100644 --- a/src/OpenTelemetry.Instrumentation.StackExchangeRedis/Implementation/RedisProfilerEntryInstrumenter.cs +++ b/src/OpenTelemetry.Instrumentation.StackExchangeRedis/Implementation/RedisProfilerEntryInstrumenter.cs @@ -7,15 +7,18 @@ using System.Reflection.Emit; using OpenTelemetry.Trace; using StackExchange.Redis.Profiling; + #if NET using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; -#endif +#endif namespace OpenTelemetry.Instrumentation.StackExchangeRedis.Implementation; internal static class RedisProfilerEntryInstrumenter { + private const int DefaultPort = 6379; + private static readonly Lazy> MessageDataGetter = new(() => { var profiledCommandType = Type.GetType("StackExchange.Redis.Profiling.ProfiledCommand, StackExchange.Redis", throwOnError: true)!; @@ -154,9 +157,12 @@ static bool GetCommandAndKey( activity?.SetTag(SemanticConventions.AttributeNetPeerPort, port); meterTags?.Add(SemanticConventions.AttributeServerAddress, ip); - meterTags?.Add(SemanticConventions.AttributeServerPort, port); meterTags?.Add(SemanticConventions.AttributeNetworkPeerAddress, ip); - meterTags?.Add(SemanticConventions.AttributeNetworkPeerPort, port); + if (port != DefaultPort) + { + meterTags?.Add(SemanticConventions.AttributeServerPort, port); + meterTags?.Add(SemanticConventions.AttributeNetworkPeerPort, port); + } } else if (command.EndPoint is DnsEndPoint dnsEndPoint) { @@ -167,7 +173,10 @@ static bool GetCommandAndKey( activity?.SetTag(SemanticConventions.AttributeNetPeerPort, port); meterTags?.Add(SemanticConventions.AttributeServerAddress, host); - meterTags?.Add(SemanticConventions.AttributeServerPort, port); + if (port != DefaultPort) + { + meterTags?.Add(SemanticConventions.AttributeServerPort, port); + } } else { diff --git a/src/OpenTelemetry.Instrumentation.StackExchangeRedis/StackExchangeRedisInstrumentationExtensions.cs b/src/OpenTelemetry.Instrumentation.StackExchangeRedis/StackExchangeRedisInstrumentationExtensions.cs index 1001c30339..36c64cb802 100644 --- a/src/OpenTelemetry.Instrumentation.StackExchangeRedis/StackExchangeRedisInstrumentationExtensions.cs +++ b/src/OpenTelemetry.Instrumentation.StackExchangeRedis/StackExchangeRedisInstrumentationExtensions.cs @@ -11,6 +11,9 @@ namespace OpenTelemetry.Instrumentation.StackExchangeRedis; +/// +/// Extension methods to simplify registering of Redis instrumentation. +/// public static class StackExchangeRedisInstrumentationExtensions { ///