Skip to content

Commit 80d2d4d

Browse files
committed
Scenarios review
1 parent 013710f commit 80d2d4d

File tree

2 files changed

+44
-15
lines changed

2 files changed

+44
-15
lines changed

scenario2.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# Scenario 2: REST API call chain
22

3-
This scenario is an evolution from Scenario 1, containing a REST API in front of the time API. In this case trace will have to be transport between two processes over HTTP.
3+
This scenario is an evolution from Scenario 1, containing a REST API in front of the existing Time REST API. In this case trace will have to be transport between two processes over HTTP.
44

55
![Sample scenario 2](media/02-sample-scenario.png)
66

77
## Observability requirements
88

99
The additional requirement is:
1010

11-
1. End to end transaction details containing both REST APIs and the SQL dependency
11+
1. End-to-end transaction details containing both REST APIs and the SQL dependency
1212

1313
## Implementation
1414

@@ -25,7 +25,7 @@ public static void Main(string[] args)
2525

2626
The class `System.Diagnostics.Activity` is used by libraries to generate traces that can be observed by Diagnostic Listeners in order to generate spans/operations according to the tracing backend of choice. Examples are [Http Client](https://github.com/dotnet/corefx/blob/master/src/System.Diagnostics.DiagnosticSource/src/HttpCorrelationProtocol.md) and [Azure Service Bus](https://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-end-to-end-tracing).
2727

28-
As mentioned before, correlation happens by having spans sharing the same TraceID. To propagate the traceId used in first span http request headers are used. The forwarded value will then be used to argument new traces, correlating with the value used by the caller.
28+
As mentioned before, correlation happens by having spans sharing the same TraceID. To propagate the traceId used in first span, http request headers are used. The forwarded value will then be used to argument new traces, correlating with the value used by the caller.
2929

3030
|Name|SpanId|ParentId|TraceId|
3131
|-|-|-|-|
@@ -40,12 +40,12 @@ The header propagating the correlation is named `traceparent`, as [defined by W3
4040
00-cd4262a7f7adf040bdd892959cf8c4fc-4a28d39ff0e725f2-01
4141
```
4242

43-
As you can observe there are 4 fields in the header value, separated by a '-':
43+
There are 4 fields in the header value, separated by a '-':
4444

4545
- [Version](https://www.w3.org/TR/trace-context-1/#version): currently 00
4646
- [TraceId](https://www.w3.org/TR/trace-context-1/#trace-id): The trace identifier started by caller
4747
- [ParentId](https://www.w3.org/TR/trace-context-1/#parent-id): The span identifier that originated the call
48-
- [Trace flags](https://www.w3.org/TR/trace-context-1/#sampled-flag): current version only supported the flag `sampled` which indicates if the caller is sampling the request
48+
- [Trace flags](https://www.w3.org/TR/trace-context-1/#sampled-flag): current version only supported the flag `sampled`, which indicates if the caller is sampling the request
4949

5050
## Requirement validation
5151

@@ -63,7 +63,7 @@ The same applies to Application Insights:
6363

6464
![Application Insights 2 web apis tracing](media/02-ai-http-header-tracing.png)
6565

66-
The dependency graph in Application Insights is available under Application Map:
66+
The dependency graph in Application Insights is available under Application Map, displaying calls counter, avg. duration and error percentage:
6767

6868
![Application Insights Application Map](media/02-ai-dependencygraph-400.png)
6969

scenario3.md

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Scenario 3: Asynchronous transactions
22

3-
This scenario covers asynchronous transactions using RabbitMQ queues. In that case the correlation is our responsibility.
3+
This scenario covers asynchronous transactions using RabbitMQ queues. In this scenario, propagating correlated trace is our responsibility.
44

55
![Sample Scenario 3](media/03-sample-scenario.png)
66

@@ -12,7 +12,7 @@ This scenario covers asynchronous transactions using RabbitMQ queues. In that ca
1212

1313
## Implementation
1414

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 a each message.
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.
1616

1717
In publisher:
1818

@@ -57,9 +57,9 @@ using (var operation = telemetryClient.StartOperation<RequestTelemetry>("Process
5757

5858
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).
5959

60-
The second option is to create what a SDK provider would have to in order to make simplify trace collector implementation. Through the usage of System.Diagnostics.Activity the activities are created. The actual creation of spans happens by listening to the diagnostics source.
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).
6161

62-
Code added to RabbitMQ publisher to generate activities:
62+
This is the code added to RabbitMQ publisher to generate an activity:
6363

6464
```C#
6565
static DiagnosticSource diagnosticSource = new DiagnosticListener("Sample.RabbitMQ");
@@ -85,9 +85,9 @@ public void Publish(string message, string traceId, string spanId)
8585
}
8686
```
8787

88-
The collector needs to subscribe to diagnostics source and create the appropriate target SDK span object. The sample project has a simplified implementation. 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).
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).
8989

90-
For OpenTelemetry this is how it looks like:
90+
For OpenTelemetry, this is how it looks like:
9191

9292
```C#
9393
public class RabbitMQListener : ListenerHandler
@@ -112,7 +112,36 @@ subscriber = new DiagnosticSourceSubscriber(new RabbitMQListener("Sample.RabbitM
112112
subscriber.Subscribe();
113113
```
114114

115-
The metrics requirements is simple to achieve using Application insights SDK:
115+
To fulfill metrics requirements using OpenTelemetry, the sample application uses a Prometheus exporter.
116+
117+
```c#
118+
var prometheusExporterOptions = new PrometheusExporterOptions()
119+
{
120+
Url = "http://+:9184/metrics/",
121+
};
122+
123+
var prometheusExporter = new PrometheusExporter(prometheusExporterOptions);
124+
var simpleProcessor = new UngroupedBatcher(prometheusExporter, TimeSpan.FromSeconds(5));
125+
var meterFactory = MeterFactory.Create(simpleProcessor);
126+
var meter = meterFactory.GetMeter("Sample App");
127+
var counter = meter.CreateInt64Counter("Enqueued Item");
128+
129+
// Calling Start() will start a http handler on http://localhost:9184/metrics/
130+
prometheusExporter.Start();
131+
132+
133+
// Adding to the counter
134+
var context = default(SpanContext);
135+
var labelSet = new Dictionary<string, string>()
136+
{
137+
{ "Source", source }
138+
};
139+
140+
counter.Add(context, 1L, meter.GetLabelSet(labelSet));
141+
142+
```
143+
144+
Application Insights SDK also provides support to metrics, as the code below demonstrates:
116145

117146
```C#
118147
// Create the metric with custom dimension "Source"
@@ -140,13 +169,13 @@ As displayed above, the `Publish to RabbitMQ` activity has it's own span, for bo
140169

141170
### 3. Have metrics aggregating enqueued items by source
142171

143-
In the sample application metrics have been implemented with OpenTelemetry (Prometheus exporter) and Application Insights (through the SDK).
172+
In the sample application, metrics have been implemented with OpenTelemetry (Prometheus exporter) and Application Insights (through the SDK).
144173

145174
The metrics using Prometheus (and Grafana for visualization) looks like this:
146175

147176
![Grafana Custom Metrics](media/03-grafana-metrics.png)
148177

149-
The raw metrics are available in [](http://localhost:9184/metrics), as the example below:
178+
The raw metrics are available in [http://localhost:9184/metrics](http://localhost:9184/metrics), as the example below:
150179

151180
```text
152181
# HELP Enqueued_ItemSample AppEnqueued Item

0 commit comments

Comments
 (0)