You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## 4. Differences in creating span from System.Diagnostics.Activity
37
37
38
-
When building traces for asynchronous transactions (publisher/consumer) the starting request duration is different depending on the SDK used.
38
+
When creating spans/operations from a System.Diagnostics.Activity, OpenTelemetry has 2 differences in comparison to Application Insights (between methods Tracer.StartActiveSpanFromActivity and TelemetryClient.StartOperation<RequestTelemetry>).
39
39
40
-
With Application Insights SDK the request duration seems to be the total time. On the other hand, using OpenTelemetry SDK, it seems to have only the self time.
- OpenTelemetry requires the activity to have been started (Activity.Start())
41
42
42
-
Application Insights SDK:
43
+
## ~~5. Difference in first request duration~~
44
+
45
+
~~When building traces for asynchronous transactions (publisher/consumer) the starting request duration is different depending on the SDK used.~~
46
+
47
+
~~With Application Insights SDK the request duration seems to be the total time. On the other hand, using OpenTelemetry SDK, it seems to have only the self time.~~
Copy file name to clipboardExpand all lines: scenario3.md
+54-55Lines changed: 54 additions & 55 deletions
Original file line number
Diff line number
Diff line change
@@ -12,80 +12,71 @@ This scenario covers asynchronous transactions using RabbitMQ queues. In this sc
12
12
13
13
## Implementation
14
14
15
-
It is necessary to write custom code to correlate RabbitMQ message consumption with the trace that generated the message. The sample application uses RabbitMQ message headers to include the trace parent of each message.
15
+
In order to correlate the publisher and consumer of a RabbitMQ message we need have to add the traceability ourselves. There is no built-in traceability as with HTTP requests in .NET Core 3.0. The sample application uses RabbitMQ message headers to include the trace parent of each message. Similar to the way Azure Service Bus does.
16
16
17
-
In publisher:
17
+
In the sample application, the publisher starts a System.Diagnostics.Activity before publishing a message to RabbitMQ. The full id (W3C format) is forwarded in the message header:
tracer.StartActiveSpan("Process single RabbitMQ message", parentContext, SpanKind.Consumer, outspan);
47
-
```
53
+
In this approach the final span/operation is created from an Activity. This is how the consumer sample application was built.
48
54
49
-
For Application Insights:
55
+
Activity extracting:
50
56
51
-
```C#
52
-
using (varoperation=telemetryClient.StartOperation<RequestTelemetry>("Process single RabbitMQ message", traceId, parentId))
53
-
{
54
-
...
55
-
}
57
+
```c#
58
+
// ExtractActivity creates the Activity setting the parent based on the RabbitMQ "traceparent" header
59
+
varactivity=rabbitMQMessage.ExtractActivity("Process single RabbitMQ message");
56
60
```
57
61
58
-
The requirement to track RabbitMQ publishing also requires additional code. The easier option is to use the target SDK and create spans/operations before calling RabbitMQ (as we did for SQL server in Open Telemetry).
59
-
60
-
The second option is to create System.Diagnostics.Activity objects, as a SDK provider would do. Collectors to OpenTelemetry or Application Insights subscribe to those activities, creating the the corresponding span (or dependency in Application Insights).
62
+
OpenTelemetry:
61
63
62
-
This is the code added to RabbitMQ publisher to generate an activity:
Another way to consume generated Activities is to subscribe to them, creating the the corresponding span (or dependency in Application Insights).
87
78
88
-
The sample project contains a simplified collector implementation for Application Insights and OpenTelemetry. For production quality please refer to OpenTelemetry and/or Application Insights built-in collectors and this [user guide](https://github.com/dotnet/corefx/blob/master/src/System.Diagnostics.DiagnosticSource/src/ActivityUserGuide.md).
79
+
The sample publisher (Sample.MainApi) contains a simplified collector implementation for Application Insights and OpenTelemetry (Sample.RabbitMQCollector project). For production quality please refer to OpenTelemetry and/or Application Insights built-in collectors and this [user guide](https://github.com/dotnet/corefx/blob/master/src/System.Diagnostics.DiagnosticSource/src/ActivityUserGuide.md).
89
80
90
81
For OpenTelemetry, this is how it looks like:
91
82
@@ -94,7 +85,9 @@ public class RabbitMQListener : ListenerHandler
0 commit comments