Add ASP.NET Core instrumentation to OpenTelemetry tracing - #3823
Open
piqpiq (lepiqpiqclem) wants to merge 2 commits into
Open
piqpiq (lepiqpiqclem) wants to merge 2 commits into
piqpiq (lepiqpiqclem) wants to merge 2 commits into
Conversation
Registers AddAspNetCoreInstrumentation() so every inbound REST, GraphQL and MCP request produces a server span and continues the incoming traceparent. The OpenTelemetry.Instrumentation.AspNetCore package was already referenced but unused. Closes Azure#3559
piqpiq (lepiqpiqclem)
requested review from
Alekhya-Polavarapu,
Aniruddh Munde (Aniruddh25),
Jerry Nixon (JerryNixon),
RubenCerna2079,
aaronburtle,
Mohit G (gmohit21),
rusamant,
Sourabh Jain (sourabh1007),
Souvik Ghosh (souvikghosh04),
Stuart Padley (stuartpa) and
vadeveka
as code owners
September 22, 2026 23:19
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Author
|
@microsoft-github-policy-service agree |
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The test does not verify trace-context propagation; also correct the OpenTelemetry spelling nit.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 1
Open (1)
What changed in this PR
Adds ASP.NET Core OpenTelemetry instrumentation so inbound DAB requests emit server spans and participate in distributed tracing.
Changes:
- Registers
AddAspNetCoreInstrumentation(). - Adds an integration test for inbound server-span recording.
| File | Summary |
|---|---|
src/Service/Startup.cs |
Enables ASP.NET Core request tracing. |
src/Service.Tests/Configuration/Telemetry/OpenTelemetryTests.cs |
Tests inbound server-span creation. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Why make this change?
TracerProvideronly registersHttpClientInstrumentation, so the only exported spans are outbound calls DAB makes itself (schema download, health self-checks). An incomingtraceparentis also not continued, which breaks distributed traces going through DAB.What is this change?
.AddAspNetCoreInstrumentation()in theWithTracingblock ofStartup.cs.OpenTelemetry.Instrumentation.AspNetCorepackage (1.12.0) is already referenced byAzure.DataApiBuilder.Service.csprojandDirectory.Packages.props, but it was never used. No new dependency and no version change.Microsoft.AspNetCoreactivity source; without this call the OpenTelemetry SDK does not subscribe to it, so those activities are never sampled or exported.DABActivitySource, e.g.GET {entity}/QUERY {entity}inRestController) and HotChocolate spans now become children of the server span, and the incoming W3Ctraceparentis honored.OpenTelemetry.Instrumentation.SqlClientis not available on thedata_api_builder_build_packagesfeed, so adding it would fail restore (NU1301) until a maintainer adds it to the feed. Version1.15.2would be the compatible one (depends onOpenTelemetry.Api.ProviderBuilderExtensions >= 1.15.3, matching the currentOpenTelemetry.Exporter.OpenTelemetryProtocol1.15.3). Happy to follow up in a separate PR.How was this tested?
OpenTelemetryTests.TestOpenTelemetryRecordsInboundHttpRequestSpan. It registers anActivityListeneron theMicrosoft.AspNetCoresource that never samples by itself, sends a request to theTestServer, and asserts that the server activity for that request path isRecorded. The activity can only be recorded if the OpenTelemetryTracerProvidersubscribes to ASP.NET Core, so the test fails without the fix.v2.0.12, running against SQL Server with OTLP gRPC export to Grafana Alloy → Tempo. Before: the OTEL SDK self-diagnostics log showsInstrumentations added = "HttpClientInstrumentation"and no request spans. After: oneServerspan per REST request is visible in Tempo.Sample Request(s)
With
runtime.telemetry.open-telemetry.enabled: true:now exports a
Serverspan (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.