@@ -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 }
0 commit comments