Commit fc81dab
[tracing] hangfire autoinstrumentation (#6904)
## Summary of changes
This PR introduces automatic instrumentation for Hangfire in the Datadog .NET Tracer. The following new files and code components were added to enable distributed tracing and error reporting for Hangfire background jobs:
-
Core instrumentation logic (`HangfireCommon.cs`, `HangfireConstants.cs`)
-
Duck typing interfaces for Hangfire contexts and jobs to access runtime data (`IBackgroundJobProxy.cs`, `IPerformContextProxy.cs`, `ICreatingContextProxy.cs`, etc.)
-
Datadog job filters for server and client sides (`DatadogHangfireServerFilter.cs`, `DatadogHangfireClientFilter.cs`)
-
Integration hooks to inject filters into Hangfire (`JobFilterCollectionctorIntegration.cs`)
- Tagging support for Hangfire spans (`HangfireTags.cs`)
- Integration tests for Hangfire tracing (`HangfireTests.cs`)
-
Sample application updates to demonstrate Hangfire usage (`Samples.Hangfire/Program.cs`, `TestJob.cs`)
- Addition of `Hangfire` to the `IntegrationId` enum.
## Reason for change
- Remove reliance on OTEL instrumentation
## Implementation details
-
Job filters are injected into Hangfire at runtime using calltarget instrumentation on `JobFilterCollection` construction.
-
Context propagation is handled via Datadog’s span context mechanisms, ensuring distributed traces are continued between job enqueueing and execution.
-
Server-side filter creates a Datadog span for each job executed; errors are captured and reported on the span.
- Client-side filter propagates trace context when jobs are enqueued.
-
Duck typing is used to interact with Hangfire types at runtime, making the instrumentation robust to API changes.
-
Tags are added to spans for job ID, creation time, and resource names for easier identification in Datadog.
- All new code adheres to Datadog’s licensing and coding standards.
## Test coverage
-
Integration tests (`HangfireTests.cs`) verify that traces are submitted for Hangfire jobs, distributed trace context is propagated, and errors are properly recorded in the spans.
-
The sample application demonstrates covering typical Hangfire usage scenarios, including successful and failed jobs.
-
Tests confirm service name tagging, error status, and correct trace propagation
## Other details
<!-- Fixes #{issue} -->
<!-- 1 parent 5b42318 commit fc81dab
File tree
68 files changed
+4251
-6845
lines changed- tracer
- build
- _build/Honeypot
- dependabot/integrations
- src
- Datadog.Trace.Trimming/build
- Datadog.Tracer.Native/Generated
- Datadog.Trace
- ClrProfiler/AutoInstrumentation/Hangfire
- Configuration
- Generated
- net461/Datadog.Trace.SourceGenerators
- EnumExtensionsGenerator
- InstrumentationDefinitionsGenerator
- TagListGenerator
- TelemetryMetricGenerator
- net6.0/Datadog.Trace.SourceGenerators
- EnumExtensionsGenerator
- InstrumentationDefinitionsGenerator
- TagListGenerator
- TelemetryMetricGenerator
- netcoreapp3.1/Datadog.Trace.SourceGenerators
- EnumExtensionsGenerator
- InstrumentationDefinitionsGenerator
- TagListGenerator
- TelemetryMetricGenerator
- netstandard2.0/Datadog.Trace.SourceGenerators
- EnumExtensionsGenerator
- InstrumentationDefinitionsGenerator
- TagListGenerator
- TelemetryMetricGenerator
- Tagging
- Telemetry/Metrics
- test
- Datadog.Trace.ClrProfiler.IntegrationTests
- Datadog.Trace.TestHelpers
- snapshots
- test-applications/integrations/Samples.Hangfire
- Infrastructure
- Jobs
- Properties
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
68 files changed
+4251
-6845
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
441 | 441 | | |
442 | 442 | | |
443 | 443 | | |
| 444 | + | |
| 445 | + | |
444 | 446 | | |
445 | 447 | | |
446 | 448 | | |
| |||
1059 | 1061 | | |
1060 | 1062 | | |
1061 | 1063 | | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
1062 | 1068 | | |
1063 | 1069 | | |
1064 | 1070 | | |
| |||
1243 | 1249 | | |
1244 | 1250 | | |
1245 | 1251 | | |
| 1252 | + | |
1246 | 1253 | | |
1247 | 1254 | | |
1248 | 1255 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
619 | 619 | | |
620 | 620 | | |
621 | 621 | | |
| 622 | + | |
| 623 | + | |
622 | 624 | | |
623 | 625 | | |
624 | 626 | | |
| |||
1493 | 1495 | | |
1494 | 1496 | | |
1495 | 1497 | | |
| 1498 | + | |
| 1499 | + | |
| 1500 | + | |
| 1501 | + | |
1496 | 1502 | | |
1497 | 1503 | | |
1498 | 1504 | | |
| |||
1748 | 1754 | | |
1749 | 1755 | | |
1750 | 1756 | | |
| 1757 | + | |
1751 | 1758 | | |
1752 | 1759 | | |
1753 | 1760 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
2 | 13 | | |
3 | 14 | | |
4 | 15 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
15 | 75 | | |
16 | 76 | | |
17 | 77 | | |
| |||
0 commit comments