Skip to content

Commit

Permalink
feat: add attr server.port if is not default 6379
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagodaraujo committed Nov 6, 2024
1 parent 8d4befa commit eedaf7c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Func<object, (string?, string?)>> MessageDataGetter = new(() =>
{
var profiledCommandType = Type.GetType("StackExchange.Redis.Profiling.ProfiledCommand, StackExchange.Redis", throwOnError: true)!;
Expand Down Expand Up @@ -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)
{
Expand All @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

namespace OpenTelemetry.Instrumentation.StackExchangeRedis;

/// <summary>
/// Extension methods to simplify registering of Redis instrumentation.
/// </summary>
public static class StackExchangeRedisInstrumentationExtensions
{
/// <summary>
Expand Down

0 comments on commit eedaf7c

Please sign in to comment.