Azure / Azure/data-api-builder
[Bug]: No server-side HTTP request trace spans
- Vorherrschende Sprache
- C#
- Sterne
- 1.5k
- Forks
- 370
- Ø Merge
- 3 T. 22 Std.
- Gemergte PRs (30 T.)
- 9
Beschreibung
When you call a DAB endpoint (REST, GraphQL, or MCP), no trace span is created for that request. The only spans DAB produces are outbound HTTP calls it makes itself — downloading its JSON schema from GitHub and pinging its own health endpoint. Inbound API traffic is invisible in traces.
This means you **cannot** use distributed tracing to follow a request through DAB. If a downstream service passes a `traceparent` header, DAB will not create a child span, breaking the trace chain.
## Expected
Every inbound HTTP request should produce a server-side span. In a standard ASP.NET Core app, this happens automatically when the OTEL SDK is configured with `AddAspNetCoreInstrumentation()`. A call to `GET /api/Todo` should appear in your trace viewer like this:
```
Span: GET /api/Todo
Kind: Server
Duration: 220ms
Attributes:
http.request.method = GET
url.path = /api/Todo
http.response.status_code = 200
http.route = /api/{entityName}/{primaryKeyRoute?}
```
Ideally, child spans would also appear for the SQL query DAB executes under the hood, giving a full picture:
```
[Server] GET /api/Todo ── 220ms
└─ [Client] SELECT ... FROM dbo.Todo ── 18ms
```
## Actual
The only 4 spans captured across 28+ API requests were all outbound (`Kind: Client`):
| # | What it is | Why it exists |
|---|-----------|---------------|
| Span 1 | `GET github.com` | DAB downloads its JSON schema file at startup |
| Span 2 | `GET release-assets.githubusercontent.com` | Redirect target of span 1 |
| Span 3 | `GET localhost:5000/api/...` | DAB's health check calls itself |
| Span 4 | `GET localhost:5000/api/...` | Another health self-check |
None of these represent a user's API call.
## Fix
DAB's OTEL `TracerProvider` setup needs to register the ASP.NET Core instrumentation source. In the `Startup.cs` (or wherever the OTEL SDK is configured), add:
```csharp
builder.Services.AddOpenTelemetry()
.WithTracing(tracing => tracing
.AddAspNetCoreInstrumentation() // <-- missing today
.AddSqlClientInstrumentation() // <-- also recommended
.AddHttpClientInstrumentation() // already present (System.Net.Http spans work)
.AddOtlpExporter(/* ... */)
);
```
`AddAspNetCoreInstrumentation()` hooks into the `Microsoft.AspNetCore.Hosting.HttpRequestIn` ActivitySource that ASP.NET Core already emits. Without it, those Activities are created but never sampled or exported.
Beitragsleitfaden
Rechercherichtung
Beginne in Startup.cs oder dort, wo der OTEL TracerProvider konfiguriert wird, und untersuche die vorhandene Einrichtung für das Tracing von HTTP-Clients. Reproduziere das Problem mit einer eingehenden REST-, GraphQL- oder MCP-Anfrage und vergleiche die exportierten Spans mit dem erwarteten Server-Span und der Propagierung von traceparent. Als abgeschlossen gilt die Aufgabe, wenn eingehende Anfragen als Server-Spans erscheinen; SQL-Kind-Spans werden vom Issue ebenfalls empfohlen.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- csharp
- Bereich
- api, backend, observability
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Ruhig
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 55/100