88using DotNetCore . CAP . Diagnostics ;
99using OpenTelemetry ;
1010using OpenTelemetry . Context . Propagation ;
11- using OpenTelemetry . Trace ;
1211using CapEvents = DotNetCore . CAP . Diagnostics . CapDiagnosticListenerNames ;
1312
1413namespace DotNetCore . CAP . OpenTelemetry ;
@@ -52,7 +51,7 @@ public void OnNext(KeyValuePair<string, object?> evt)
5251 ActivityKind . Internal , parentContext ) ;
5352 if ( activity != null )
5453 {
55- activity . SetTag ( "message .name" , eventData . Operation ) ;
54+ activity . SetTag ( "messaging.destination .name" , eventData . Operation ) ;
5655 activity . AddEvent ( new ActivityEvent ( "CAP message persistence start..." ,
5756 DateTimeOffset . FromUnixTimeMilliseconds ( eventData . OperationTimestamp ! . Value ) ) ) ;
5857
@@ -61,7 +60,8 @@ public void OnNext(KeyValuePair<string, object?> evt)
6160 Propagator . Inject ( new PropagationContext ( Activity . Current . Context , Baggage . Current ) ,
6261 eventData . Message ,
6362 ( msg , key , value ) => { msg . Headers [ key ] = value ; } ) ;
64- } ;
63+ }
64+ ;
6565 }
6666 }
6767 break ;
@@ -84,7 +84,7 @@ public void OnNext(KeyValuePair<string, object?> evt)
8484 {
8585 var exception = eventData . Exception ! ;
8686 activity . SetStatus ( ActivityStatusCode . Error , exception . Message ) ;
87- activity . RecordException ( exception ) ;
87+ activity . AddException ( exception ) ;
8888 activity . Stop ( ) ;
8989 }
9090 }
@@ -108,12 +108,22 @@ public void OnNext(KeyValuePair<string, object?> evt)
108108 if ( activity != null )
109109 {
110110 activity . SetTag ( "messaging.system" , eventData . BrokerAddress . Name ) ;
111- activity . SetTag ( "messaging.destination" , eventData . Operation ) ;
112- activity . SetTag ( "messaging.destination_kind" , "topic" ) ;
113- activity . SetTag ( "messaging.url" , eventData . BrokerAddress . Endpoint ? . Replace ( "-1" , "5672" ) ) ;
114- activity . SetTag ( "messaging.message_id" , eventData . TransportMessage . GetId ( ) ) ;
115- activity . SetTag ( "messaging.message_payload_size_bytes" , eventData . TransportMessage . Body . Length ) ;
116-
111+ activity . SetTag ( "messaging.message.id" , eventData . TransportMessage . GetId ( ) ) ;
112+ activity . SetTag ( "messaging.message.body.size" , eventData . TransportMessage . Body . Length ) ;
113+ activity . SetTag ( "messaging.message.conversation_id" , eventData . TransportMessage . GetCorrelationId ( ) ) ;
114+ activity . SetTag ( "messaging.destination.name" , eventData . Operation ) ;
115+ if ( eventData . BrokerAddress . Endpoint is { } endpoint )
116+ {
117+ var parts = endpoint . Split ( ':' ) ;
118+ if ( parts . Length > 0 )
119+ {
120+ activity . SetTag ( "server.address" , parts [ 0 ] ) ;
121+ }
122+ if ( parts . Length > 1 && int . TryParse ( parts [ 1 ] , out var port ) )
123+ {
124+ activity . SetTag ( "server.port" , port ) ;
125+ }
126+ }
117127 activity . AddEvent ( new ActivityEvent ( "Message publishing start..." ,
118128 DateTimeOffset . FromUnixTimeMilliseconds ( eventData . OperationTimestamp ! . Value ) ) ) ;
119129
@@ -143,7 +153,7 @@ public void OnNext(KeyValuePair<string, object?> evt)
143153 {
144154 var exception = eventData . Exception ! ;
145155 activity . SetStatus ( ActivityStatusCode . Error , exception . Message ) ;
146- activity . RecordException ( exception ) ;
156+ activity . AddException ( exception ) ;
147157 activity . Stop ( ) ;
148158 }
149159 }
@@ -166,12 +176,24 @@ public void OnNext(KeyValuePair<string, object?> evt)
166176 if ( activity != null )
167177 {
168178 activity . SetTag ( "messaging.system" , eventData . BrokerAddress . Name ) ;
169- activity . SetTag ( "messaging.destination" , eventData . Operation ) ;
170- activity . SetTag ( "messaging.destination_kind" , "topic" ) ;
171- activity . SetTag ( "messaging.url" , eventData . BrokerAddress . Endpoint ? . Replace ( "-1" , "5672" ) ) ;
172- activity . SetTag ( "messaging.message_id" , eventData . TransportMessage . GetId ( ) ) ;
173- activity . SetTag ( "messaging.message_payload_size_bytes" , eventData . TransportMessage . Body . Length ) ;
174-
179+ activity . SetTag ( "messaging.message.id" , eventData . TransportMessage . GetId ( ) ) ;
180+ activity . SetTag ( "messaging.message.body.size" , eventData . TransportMessage . Body . Length ) ;
181+ activity . SetTag ( "messaging.operation.type" , "receive" ) ;
182+ activity . SetTag ( "messaging.client.id" , eventData . TransportMessage . GetExecutionInstanceId ( ) ) ;
183+ activity . SetTag ( "messaging.destination.name" , eventData . Operation ) ;
184+ activity . SetTag ( "messaging.consumer.group.name" , eventData . TransportMessage . GetGroup ( ) ) ;
185+ if ( eventData . BrokerAddress . Endpoint is { } endpoint )
186+ {
187+ var parts = endpoint . Split ( ':' ) ;
188+ if ( parts . Length > 0 )
189+ {
190+ activity . SetTag ( "server.address" , parts [ 0 ] ) ;
191+ }
192+ if ( parts . Length > 1 && int . TryParse ( parts [ 1 ] , out var port ) )
193+ {
194+ activity . SetTag ( "server.port" , port ) ;
195+ }
196+ }
175197 activity . AddEvent ( new ActivityEvent ( "CAP message persistence start..." ,
176198 DateTimeOffset . FromUnixTimeMilliseconds ( eventData . OperationTimestamp ! . Value ) ) ) ;
177199 }
@@ -197,7 +219,7 @@ public void OnNext(KeyValuePair<string, object?> evt)
197219 {
198220 var exception = eventData . Exception ! ;
199221 activity . SetStatus ( ActivityStatusCode . Error , exception . Message ) ;
200- activity . RecordException ( exception ) ;
222+ activity . AddException ( exception ) ;
201223 activity . Stop ( ) ;
202224 }
203225 }
@@ -224,8 +246,7 @@ public void OnNext(KeyValuePair<string, object?> evt)
224246
225247 if ( activity != null )
226248 {
227- activity . SetTag ( "messaging.operation" , "process" ) ;
228- activity . SetTag ( "code.function" , eventData . MethodInfo . Name ) ;
249+ activity . SetTag ( "code.function.name" , eventData . MethodInfo . Name ) ;
229250
230251 activity . AddEvent ( new ActivityEvent ( "Begin invoke the subscriber:" + eventData . MethodInfo . Name ,
231252 DateTimeOffset . FromUnixTimeMilliseconds ( eventData . OperationTimestamp ! . Value ) ) ) ;
@@ -252,7 +273,7 @@ public void OnNext(KeyValuePair<string, object?> evt)
252273 {
253274 var exception = eventData . Exception ! ;
254275 activity . SetStatus ( ActivityStatusCode . Error , exception . Message ) ;
255- activity . RecordException ( exception ) ;
276+ activity . AddException ( exception ) ;
256277 activity . Stop ( ) ;
257278 }
258279 }
0 commit comments