Skip to content

Commit 2aec5ad

Browse files
Update OpenTelemetry.Instrumentation.StackExchangeRedis (#18532)
Updated vendored code for OpenTelemetry.Instrumentation.StackExchangeRedis to https://github.com/open-telemetry/opentelemetry-dotnet-contrib/releases/tag/Instrumentation.StackExchangeRedis-1.16.0-beta.1.
1 parent 3c41f8b commit 2aec5ad

3 files changed

Lines changed: 24 additions & 13 deletions

File tree

src/Vendoring/OpenTelemetry.Instrumentation.StackExchangeRedis/Implementation/RedisProfilerEntryToActivityConverter.cs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,17 @@ static bool GetCommandAndKey(
101101
StackExchangeRedisConnectionInstrumentation.ActivitySourceNew :
102102
StackExchangeRedisConnectionInstrumentation.ActivitySource;
103103

104+
var creationTags =
105+
options.EmitOldAttributes && options.EmitNewAttributes ? StackExchangeRedisConnectionInstrumentation.BothCreationTags :
106+
options.EmitNewAttributes ? StackExchangeRedisConnectionInstrumentation.NewCreationTags :
107+
options.EmitOldAttributes ? StackExchangeRedisConnectionInstrumentation.OldCreationTags :
108+
[];
109+
104110
var activity = activitySource.StartActivity(
105111
name,
106112
ActivityKind.Client,
107113
parentActivity?.Context ?? default,
108-
[
109-
.. options.EmitOldAttributes ? StackExchangeRedisConnectionInstrumentation.OldCreationTags : [],
110-
.. options.EmitNewAttributes ? StackExchangeRedisConnectionInstrumentation.NewCreationTags : [],
111-
],
114+
creationTags,
112115
startTime: command.CommandCreated);
113116

114117
if (activity == null)
@@ -120,11 +123,11 @@ static bool GetCommandAndKey(
120123

121124
if (activity.IsAllDataRequested)
122125
{
123-
// see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/database.md
126+
// See https://github.com/open-telemetry/semantic-conventions/blob/v1.42.0/docs/db/database-spans.md
124127

125128
// Timing example:
126-
// command.CommandCreated; //2019-01-10 22:18:28Z
127129

130+
// command.CommandCreated; // 2019-01-10 22:18:28Z
128131
// command.CreationToEnqueued; // 00:00:32.4571995
129132
// command.EnqueuedToSending; // 00:00:00.0352838
130133
// command.SentToResponse; // 00:00:00.0060586
@@ -169,7 +172,7 @@ static bool GetCommandAndKey(
169172

170173
if (options.EmitNewAttributes)
171174
{
172-
string? queryText = command.Command;
175+
var queryText = command.Command;
173176
if (options.SetVerboseDatabaseStatements && !string.IsNullOrEmpty(commandAndKey))
174177
{
175178
queryText = commandAndKey;
@@ -189,9 +192,10 @@ static bool GetCommandAndKey(
189192
{
190193
if (command.EndPoint is IPEndPoint ipEndPoint)
191194
{
192-
activity.SetTag(SemanticConventions.AttributeServerAddress, ipEndPoint.Address.ToString());
195+
var address = ipEndPoint.Address.ToString();
196+
activity.SetTag(SemanticConventions.AttributeServerAddress, address);
193197
activity.SetTag(SemanticConventions.AttributeServerPort, ipEndPoint.Port);
194-
activity.SetTag(SemanticConventions.AttributeNetworkPeerAddress, ipEndPoint.Address.ToString());
198+
activity.SetTag(SemanticConventions.AttributeNetworkPeerAddress, address);
195199
activity.SetTag(SemanticConventions.AttributeNetworkPeerPort, ipEndPoint.Port);
196200
}
197201
else if (command.EndPoint is DnsEndPoint dnsEndPoint)
@@ -202,8 +206,9 @@ static bool GetCommandAndKey(
202206
#if NET
203207
else if (command.EndPoint is UnixDomainSocketEndPoint unixDomainSocketEndPoint)
204208
{
205-
activity.SetTag(SemanticConventions.AttributeServerAddress, unixDomainSocketEndPoint.ToString());
206-
activity.SetTag(SemanticConventions.AttributeNetworkPeerAddress, unixDomainSocketEndPoint.ToString());
209+
var address = unixDomainSocketEndPoint.ToString();
210+
activity.SetTag(SemanticConventions.AttributeServerAddress, address);
211+
activity.SetTag(SemanticConventions.AttributeNetworkPeerAddress, address);
207212
}
208213
#endif
209214
}

src/Vendoring/OpenTelemetry.Instrumentation.StackExchangeRedis/StackExchangeRedisConnectionInstrumentation.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ internal sealed class StackExchangeRedisConnectionInstrumentation : IDisposable
2222
internal static readonly Version SemanticConventionsVersion = new(1, 23, 0);
2323
internal static readonly ActivitySource ActivitySource = ActivitySourceFactory.Create(typeof(StackExchangeRedisConnectionInstrumentation), SemanticConventionsVersion, name: ActivitySourceName);
2424

25-
internal static readonly Version SemanticConventionsVersionNew = new(1, 28, 0);
25+
internal static readonly Version SemanticConventionsVersionNew = new(1, 42, 0);
2626
internal static readonly ActivitySource ActivitySourceNew = ActivitySourceFactory.Create(typeof(StackExchangeRedisConnectionInstrumentation), SemanticConventionsVersionNew, name: ActivitySourceName);
2727

2828
internal static readonly ActivitySource ActivitySourceBoth = ActivitySourceFactory.Create(typeof(StackExchangeRedisConnectionInstrumentation), null, name: ActivitySourceName);
@@ -39,6 +39,12 @@ internal sealed class StackExchangeRedisConnectionInstrumentation : IDisposable
3939
new(SemanticConventions.AttributeDbSystemName, "redis")
4040
];
4141

42+
internal static readonly IEnumerable<KeyValuePair<string, object?>> BothCreationTags =
43+
[
44+
new(SemanticConventions.AttributeDbSystem, "redis"),
45+
new(SemanticConventions.AttributeDbSystemName, "redis"),
46+
];
47+
4248
internal readonly ConcurrentDictionary<(ActivityTraceId TraceId, ActivitySpanId SpanId), (Activity Activity, ProfilingSession Session)> Cache
4349
= new();
4450

src/Vendoring/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ git checkout tags/Instrumentation.ConfluentKafka-0.1.0-alpha.2
2323
```console
2424
git clone https://github.com/open-telemetry/opentelemetry-dotnet-contrib.git
2525
git fetch --tags
26-
git checkout tags/Instrumentation.StackExchangeRedis-1.15.1-beta.2
26+
git checkout tags/Instrumentation.StackExchangeRedis-1.16.0-beta.1
2727
```
2828

2929
### Instructions

0 commit comments

Comments
 (0)