Repository navigation
Commit 040233c
authored
Add ASP.NET Core instrumentation to OpenTelemetry tracing (#3823)
## Why make this change?
- Closes #3559
- When OpenTelemetry is enabled, DAB exports no span for inbound REST,
GraphQL or MCP requests. The `TracerProvider` only registers
`HttpClientInstrumentation`, so the only exported spans are outbound
calls DAB makes itself (schema download, health self-checks). An
incoming `traceparent` is also not continued, which breaks distributed
traces going through DAB.
## What is this change?
- Registers `.AddAspNetCoreInstrumentation()` in the `WithTracing` block
of `Startup.cs`.
- The `OpenTelemetry.Instrumentation.AspNetCore` package (1.12.0) is
already referenced by `Azure.DataApiBuilder.Service.csproj` and
`Directory.Packages.props`, but it was never used. **No new dependency
and no version change.**
- ASP.NET Core already creates an activity for every request on the
`Microsoft.AspNetCore` activity source; without this call the
OpenTelemetry SDK does not subscribe to it, so those activities are
never sampled or exported.
- Existing DAB spans (`DABActivitySource`, e.g. `GET {entity}` / `QUERY
{entity}` in `RestController`) and HotChocolate spans now become
children of the server span, and the incoming W3C `traceparent` is
honored.
- SQL client spans (also mentioned in the issue) are intentionally left
out of this PR: `OpenTelemetry.Instrumentation.SqlClient` is not
available on the `data_api_builder_build_packages` feed, so adding it
would fail restore (`NU1301`) until a maintainer adds it to the feed.
Version `1.15.2` would be the compatible one (depends on
`OpenTelemetry.Api.ProviderBuilderExtensions >= 1.15.3`, matching the
current `OpenTelemetry.Exporter.OpenTelemetryProtocol` 1.15.3). Happy to
follow up in a separate PR.
## How was this tested?
- [x] Integration Tests
- Added
`OpenTelemetryTests.TestOpenTelemetryRecordsInboundHttpRequestSpan`. It
registers an `ActivityListener` on the `Microsoft.AspNetCore` source
that never samples by itself, sends a request to the `TestServer`, and
asserts that the server activity for that request path is `Recorded`.
The activity can only be recorded if the OpenTelemetry `TracerProvider`
subscribes to ASP.NET Core, so the test fails without the fix.
- [ ] Unit Tests
- Manual: the same one-line change applied on top of `v2.0.12`, running
against SQL Server with OTLP gRPC export to Grafana Alloy → Tempo.
Before: the OTEL SDK self-diagnostics log shows `Instrumentations added
= "HttpClientInstrumentation"` and no request spans. After: one `Server`
span per REST request is visible in Tempo.
## Sample Request(s)
With `runtime.telemetry.open-telemetry.enabled: true`:
```
GET http://localhost:5000/api/Book
```
now exports a `Server` span (`http.request.method=GET`,
`url.path=/api/Book`, `http.response.status_code=200`), with the
existing DAB spans for the request (`GET Book`, `QUERY Book`) nested
under it.
---------
Co-authored-by: clempiq <104780066+clementpiquin@users.noreply.github.com>1 parent 594e942 commit 040233c
2 files changed
Lines changed: 62 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
| 7 | + | |
| 8 | + | |
6 | 9 | | |
7 | 10 | | |
8 | 11 | | |
| |||
24 | 27 | | |
25 | 28 | | |
26 | 29 | | |
| 30 | + | |
27 | 31 | | |
28 | 32 | | |
29 | 33 | | |
| |||
88 | 92 | | |
89 | 93 | | |
90 | 94 | | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
91 | 150 | | |
92 | 151 | | |
93 | 152 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
213 | 213 | | |
214 | 214 | | |
215 | 215 | | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
216 | 219 | | |
217 | 220 | | |
218 | 221 | | |
| |||
0 commit comments