Skip to content

Commit e393a38

Browse files
committed
docs(diagnostics): example to add activity source to open telemetry
1 parent b1c4454 commit e393a38

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,37 @@ using (new BackgroundJobServer())
110110
}
111111
```
112112

113+
Observability
114+
-------------
115+
116+
**Open Telemetry**
117+
118+
OpenTelemetry is an open-source standard for distributed tracing, which allows you to collect and analyze data about the performance of your systems. Hangfire can be configured to use OpenTelemetry to instrument message handling, so that you can collect telemetry data about messages as they flow through your system.
119+
120+
Hangfire is instrumented to start a Producer activity when either a recurring job or background job is scheduled, and start a Consumer activity when a job runs. The distributed trace correlation information of the creation context is persisted with the job and used for the consumer (even if run on a different server), allows jobs to be correlated.
121+
122+
For more information see: <https://opentelemetry.io/docs/specs/semconv/messaging/messaging-spans/>
123+
124+
**Tracing**
125+
126+
This example is using following packages:
127+
- `OpenTelemetry.Extensions.Hosting`
128+
- `OpenTelemetry.Exporter.Console`
129+
130+
```csharp
131+
using OpenTelemetry.Trace;
132+
133+
var builder = WebApplication.CreateBuilder(args);
134+
135+
builder.Services.AddOpenTelemetry()
136+
.WithTracing(b => b
137+
.AddSource(DiagnosticHeaders.DefaultListenerName) // Hangfire ActivitySource
138+
.AddConsoleExporter() // Any OTEL suportable exporter can be used here
139+
);
140+
```
141+
142+
That's it you application will start exporting Hangfire related traces within your application.
143+
113144
Questions? Problems?
114145
---------------------
115146

0 commit comments

Comments
 (0)