Skip to content

[Diagnostics] Give every batch item its own request span - #10393

Merged
tobias-tengler merged 4 commits into
mainfrom
tte/batch-request-spans
Sep 15, 2026
Merged

tobias-tengler merged 4 commits into
mainfrom
tte/batch-request-spans

Conversation

@tobias-tengler

Copy link
Copy Markdown
Member

No description provided.

A GraphQL over HTTP batch shares a single transport span across items that
execute concurrently, so folding each item's operation details into that
shared span produced interleaved, meaningless tags. Mark the transport span
as a batch when a batch or operation batch request starts, and have the
execution listeners fall through to a dedicated request span per item
instead of reusing it.
@github-actions

github-actions Bot commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Patch coverage

69.2% of changed lines covered (18/26)

File Covered Changed Patch %
…/Diagnostics/Listeners/ActivityServerDiagnosticListener.cs 6 10 60.0% 🔴
…/Listeners/FusionActivityServerDiagnosticListener.cs 6 10 60.0% 🔴
…/src/Diagnostics.Core/Spans/Http/ExecuteHttpRequestSpan.cs 4 4 100.0% 🟢
…/Diagnostics/Listeners/ActivityExecutionDiagnosticListener.cs 1 1 100.0% 🟢
…/Listeners/FusionActivityExecutionDiagnosticEventListener.cs 1 1 100.0% 🟢
Uncovered changed lines (JSON)
{
  "sha": "9604bb089f4ccc75ba72391aa98732b24245dfbf",
  "files": [
    { "path": "src/HotChocolate/Diagnostics/src/Diagnostics/Listeners/ActivityServerDiagnosticListener.cs", "ranges": [[47, 48], [65, 66]] },
    { "path": "src/HotChocolate/Fusion/src/Fusion.Diagnostics/Listeners/FusionActivityServerDiagnosticListener.cs", "ranges": [[48, 49], [66, 67]] }
  ]
}

Project coverage: 57.9% (288533/497963 lines)

@tobias-tengler
tobias-tengler marked this pull request as ready for review September 15, 2026 08:32
Copilot AI lite review requested due to automatic review settings September 15, 2026 08:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Variable-batching handling and operation-batch regression coverage remain unresolved.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Updates standard and Fusion diagnostics so concurrent HTTP batch items receive independent request spans.

Changes:

  • Marks transport spans as batch-aware.
  • Creates dedicated spans for batch items.
  • Adds regression tests and runtime snapshots.
File summaries
File Summary
src/HotChocolate/Fusion/test/Fusion.Diagnostics.Tests/FusionActivityServerDiagnosticListenerTests.cs Adds Fusion batch tracing coverage.
src/HotChocolate/Fusion/test/Fusion.Diagnostics.Tests/__snapshots__/FusionActivityServerDiagnosticListenerTests.Http_Post_BatchRequest_Should_Give_Every_Item_Its_Own_Request_Span_Default.snap Captures default Fusion activity output.
src/HotChocolate/Fusion/test/Fusion.Diagnostics.Tests/__snapshots__/FusionActivityServerDiagnosticListenerTests.Http_Post_BatchRequest_Should_Give_Every_Item_Its_Own_Request_Span_Default_NET11_0.snap Captures .NET 11 Fusion activity output.
src/HotChocolate/Fusion/src/Fusion.Diagnostics/Listeners/FusionActivityServerDiagnosticListener.cs Marks Fusion HTTP batches.
src/HotChocolate/Fusion/src/Fusion.Diagnostics/Listeners/FusionActivityExecutionDiagnosticEventListener.cs Creates per-item Fusion request spans.
src/HotChocolate/Diagnostics/test/Diagnostics.Tests/ActivityServerDiagnosticListenerTests.cs Adds standard batch tracing coverage.
src/HotChocolate/Diagnostics/test/Diagnostics.Tests/__snapshots__/ActivityServerDiagnosticListenerTests.Http_Post_BatchRequest_Should_Give_Every_Item_Its_Own_Request_Span_Default.snap Captures default activity output.
src/HotChocolate/Diagnostics/test/Diagnostics.Tests/__snapshots__/ActivityServerDiagnosticListenerTests.Http_Post_BatchRequest_Should_Give_Every_Item_Its_Own_Request_Span_Default_NET11_0.snap Captures .NET 11 activity output.
src/HotChocolate/Diagnostics/src/Diagnostics/Listeners/ActivityServerDiagnosticListener.cs Marks standard HTTP batches.
src/HotChocolate/Diagnostics/src/Diagnostics/Listeners/ActivityExecutionDiagnosticListener.cs Creates per-item request spans.
src/HotChocolate/Diagnostics/src/Diagnostics.Core/Spans/Http/ExecuteHttpRequestSpan.cs Tracks batch state and request details.
Review details

Suppressed comments (4)

src/HotChocolate/Diagnostics/src/Diagnostics/Listeners/ActivityServerDiagnosticListener.cs:51

  • Variable batching does not reach StartBatchRequest: ExecutorSession.ExecuteSingleAsync calls StartSingleRequest, then an array-valued variables payload becomes a VariableBatchRequest that DefaultRequestExecutor runs concurrently. Because this path leaves IsBatch false, the default execution listener still reuses the shared ExecuteHttpRequestSpan, so concurrent items can write their operation tags onto the same activity. Detect variable batching in StartSingleRequest and mark the transport span as a batch as well, with a regression test.
        span.MarkAsBatch();

src/HotChocolate/Diagnostics/test/Diagnostics.Tests/ActivityServerDiagnosticListenerTests.cs:158

  • This new test covers only JSON request batching. The changed StartOperationBatchRequest path is also responsible for marking operation batches so each operation gets its own request span, but there is no diagnostic test for a ?batch=... request; a regression in that branch would pass unnoticed. Please add an operation-batch snapshot test here as well.
    public async Task Http_Post_BatchRequest_Should_Give_Every_Item_Its_Own_Request_Span_Default()

src/HotChocolate/Fusion/src/Fusion.Diagnostics/Listeners/FusionActivityServerDiagnosticListener.cs:52

  • Variable batching does not reach StartBatchRequest: ExecutorSession.ExecuteSingleAsync calls StartSingleRequest, then an array-valued variables payload becomes a VariableBatchRequest that DefaultRequestExecutor runs concurrently. Because this path leaves IsBatch false, the default execution listener still reuses the shared ExecuteHttpRequestSpan, so concurrent items can write their operation tags onto the same activity. Detect variable batching in StartSingleRequest and mark the transport span as a batch as well, with a regression test.
        span.MarkAsBatch();

src/HotChocolate/Fusion/test/Fusion.Diagnostics.Tests/FusionActivityServerDiagnosticListenerTests.cs:93

  • This new test covers only JSON request batching. The changed StartOperationBatchRequest path is also responsible for marking operation batches so each operation gets its own request span, but there is no Fusion diagnostics test for a ?batch=... request; a regression in that branch would pass unnoticed. Please add an operation-batch snapshot test here as well.
    public async Task Http_Post_BatchRequest_Should_Give_Every_Item_Its_Own_Request_Span_Default()
  • Files reviewed: 11/11 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

The existing coverage only exercised the JSON request batch path. An operation
batch (?batchOperations=[A,B]) reaches StartOperationBatchRequest instead, a
separate MarkAsBatch call site, so it needs its own default-scope snapshot.
Add one for both the HotChocolate and Fusion listeners.
The code states the condition directly, so the surrounding prose added nothing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants