Skip to content

Commit d4b6e70

Browse files
committed
Updated /identityserver/diagnostics/otel to describe how logs are added to OTel traces. Includes 2 images of the structured logs in otel
1 parent 3470c30 commit d4b6e70

3 files changed

Lines changed: 35 additions & 9 deletions

File tree

92.2 KB
Loading
91.8 KB
Loading

src/content/docs/identityserver/diagnostics/otel.md

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,20 @@ redirect_from:
1919
Added in Duende IdentityServer v6.1 and expanded in v7.0
2020
:::
2121

22-
[OpenTelemetry](https://opentelemetry.io) is a collection of tools, APIs, and SDKs for generating and collecting
22+
[OpenTelemetry](https://opentelemetry.io) (OTel) is a collection of tools, APIs, and SDKs for generating and collecting
2323
telemetry data (metrics, logs, and traces). This is very useful for analyzing software performance and behavior,
2424
especially in highly distributed systems.
2525

26-
.NET 8 comes with first class support for OpenTelemetry. IdentityServer emits traces, metrics, and logs.
2726

28-
### Metrics
27+
## OpenTelemetry Signals
2928

30-
Metrics are high level statistic counters. They provide an aggregated overview and can be used to set monitoring rules.
29+
OpenTelemetry signals are the information collected and processed to describe the internal activity of the system. The most common signals are traces, metrics, and logs.
3130

32-
### Logs
31+
.NET 8+ comes with first class support for OpenTelemetry. IdentityServer emits traces, metrics, and logs you can collect.
32+
33+
### Metrics
3334

34-
OpenTelemetry in .NET 8 exports the logs written to the standard ILogger system. The logs are augmented with
35-
trace ids to be able to correlate log entries with traces.
35+
Metrics are high level statistic counters. They provide an aggregated overview and can be used to set monitoring rules.
3636

3737
### Traces
3838

@@ -45,20 +45,46 @@ IdentityServer to get a new access token and then calls the API. The API reads t
4545
url and then gets the keys from jwks endpoint.
4646
![.NET Aspire dashboard showing Duende IdentityServer traces](images/aspire_traces.png)
4747

48+
### Logs
49+
50+
OpenTelemetry in .NET 8+ can export logs written to the standard `ILogger` system. The logs are augmented with
51+
trace ids and correlated with traces.
52+
53+
This is an example of a structured log message from a web application calling an API (also displayed using our
54+
[Aspire sample](/identityserver/samples/diagnostics.mdx)).
55+
56+
![.NET Aspire dashboard showing Duende IdentityServer Structured Logs](images/aspire_structured_logs.png)
57+
58+
Here is an example of that same log message appearing in the trace. Aspire displays the log entry details as dots on the trace timeline.
59+
60+
![.NET Aspire dashboard showing Duende IdentityServer a trace with a log entry](images/aspire_structured_logs_in_trace.png)
61+
4862
## Setup
4963

5064
To start emitting OpenTelemetry tracing and metrics information you need to:
5165

5266
* add the OpenTelemetry libraries to your IdentityServer and client applications
53-
* start collecting traces and Metrics from the various IdentityServer sources (and other sources e.g. ASP.NET Core)
67+
* start collecting traces and metrics from the various IdentityServer sources (and other sources e.g. ASP.NET Core)
68+
* add the OpenTelemetry configuration to your service setup
5469

5570
For development a simple option is to export the tracing information to the console and use the Prometheus
5671
exporter to create a human-readable `/metrics` endpoint for the metrics.
5772

58-
Add the OpenTelemetry configuration to your service setup.
73+
```bash
74+
dotnet add package OpenTelemetry
75+
dotnet add package OpenTelemetry.Extensions.Hosting
76+
dotnet add package OpenTelemetry.Instrumentation.AspNetCore
77+
dotnet add package OpenTelemetry.Exporter.OpenTelemetryProtocol
78+
```
5979

6080
```csharp
6181
// Program.cs
82+
using OpenTelemetry.Resources;
83+
84+
//Correlate logs with traces
85+
builder.Logging.AddOpenTelemetry();
86+
87+
//Enable OpenTelemetry
6288
var openTelemetry = builder.Services.AddOpenTelemetry();
6389

6490
openTelemetry.ConfigureResource(r => r

0 commit comments

Comments
 (0)