Skip to content

[Bundles] Log entry size and search index stats - #5933

Open
apurvabhaleMS wants to merge 3 commits into
mainfrom
personal/abhale/bundle-limits-telemetry
Open

apurvabhaleMS wants to merge 3 commits into
mainfrom
personal/abhale/bundle-limits-telemetry

Conversation

@apurvabhaleMS

@apurvabhaleMS apurvabhaleMS commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Description

Adds bundle size, per-entry size, and per-entry search index statistics to the existing bundleStatistics log. This data is needed to choose safe defaults for upcoming bundle limits (bundle size, resource size, and search index values per resource) before any limit is enforced. This PR only adds logging; request behavior does not change.

New fields in bundleStatistics:

"totalBundleBytes": 24117248,
"entrySize": {
  "over5MiB": 2, "over10MiB": 1, "over20MiB": 0,
  "large": [ { "index": 3, "resourceType": "DocumentReference", "bytes": 11534336 } ]
},
"searchIndex": {
  "over100": 1, "over250": 1, "over500": 0,
  "heavy": [ { "index": 12, "resourceType": "Observation", "indexValues": 1450 } ]
}
Field Meaning
totalBundleBytes Request Content-Length; falls back to the sum of serialized entries when absent (chunked requests)
entrySize.overXMiB Number of entries whose request body is larger than X MiB
entrySize.large Top 5 entries larger than 5 MiB, largest first
searchIndex.overN Number of entries whose resource produced more than N search index values
searchIndex.heavy Top 5 entries with more than 100 search index values, highest first

How the data is collected:

  • Entry size: BundleHandler.GenerateRequest already serializes each entry to bytes; the length is stored on ResourceExecutionContext. Sizes are registered for all entries when statistics are created, so they are logged even if the bundle fails partway.
  • Search index values: ResourceWrapperFactory.Create stores searchIndices.Count on the request context only when ExecutingBatchOrTransaction is true. The sequential and parallel bundle paths read it from the entry's request context after the entry executes.
  • No additional serialization, SQL calls, or log lines are introduced.

Related issues

Addresses AB#195352.

Testing

  • New unit tests:
    • BundleHandlerStatisticsTests: buckets, top-5 ordering and cap, totalBundleBytes, and empty summaries.
    • ResourceWrapperFactoryTests: count stored for bundle entries; not stored outside a bundle.
    • BundleHandlerTests: end-to-end statistics for sequential and parallel batches; totalBundleBytes uses Content-Length when present.
  • R4 API unit tests (BundleHandlerTests, BundleHandlerStatisticsTests): 44 passed. R4 Core unit tests (ResourceWrapperFactoryTests): 7 passed. R4 and STU3 build without warnings.

FHIR Team Checklist

  • Update the title of the PR to be succinct and less than 65 characters
  • Add a milestone to the PR for the sprint that it is merged (i.e. add S47)
  • Tag the PR with the type of update: Bug, Build, Dependencies, Enhancement, New-Feature or Documentation
  • Tag the PR with Open source, Azure API for FHIR (CosmosDB or common code) or Azure Healthcare APIs (SQL or common code) to specify where this change is intended to be released.
  • Tag the PR with Schema Version backward compatible or Schema Version backward incompatible or Schema Version unchanged if this adds or updates Sql script which is/is not backward compatible with the code.
  • When changing or adding behavior, if your code modifies the system design or changes design assumptions, please create and include an ADR.
  • CI is green before merge Build Status
  • Review squash-merge requirements

Semver Change (docs)

Patch

Add total bundle size, per-entry size buckets with the top large entries, and per-entry search index value buckets with the top heavy entries to the bundleStatistics log. This data informs the defaults for the upcoming bundle size and search parameter limits.
@apurvabhaleMS
apurvabhaleMS requested a review from a team as a code owner October 16, 2026 19:03
@apurvabhaleMS apurvabhaleMS added Enhancement Enhancement on existing functionality. Azure API for FHIR Label denotes that the issue or PR is relevant to the Azure API for FHIR Azure Healthcare APIs Label denotes that the issue or PR is relevant to the FHIR service in the Azure Healthcare APIs Schema Version unchanged No-PaaS-breaking-change No-ADR ADR not needed labels Oct 16, 2026
@apurvabhaleMS
apurvabhaleMS requested a balanced review from Copilot October 16, 2026 19:03
@apurvabhaleMS apurvabhaleMS added this to the FY27\Q2\2Wk\2Wk08 milestone Oct 16, 2026

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

PATCH search-index telemetry attributes counts to payload types rather than the indexed target resource types.

1 open finding
What changed in this PR

Extends existing bundle telemetry to inform future limits without enforcing new request restrictions.

Changes:

  • Logs total bundle bytes and per-entry size summaries.
  • Captures search-index counts in sequential and parallel execution.
  • Adds tests for collection, thresholds, and top-five summaries.
File Description
src/​Microsoft.Health.Fhir.Shared.Core.UnitTests/​Features/​Persistence/​ResourceWrapperFactoryTests.cs Tests bundle-only index-count capture.
src/​Microsoft.Health.Fhir.Shared.Api/​Features/​Resources/​Bundle/​BundleHandlerStatistics.cs Adds size and index-count summaries.
src/​Microsoft.Health.Fhir.Shared.Api/​Features/​Resources/​Bundle/​BundleHandlerParallelOperations.cs Collects parallel-entry statistics.
src/​Microsoft.Health.Fhir.Shared.Api/​Features/​Resources/​Bundle/​BundleHandler.cs Records entry sizes, bundle totals, and index counts.
src/​Microsoft.Health.Fhir.Shared.Api.UnitTests/​Features/​Resources/​Bundle/​BundleHandlerTests.cs Tests collection paths and Content-Length handling.
src/​Microsoft.Health.Fhir.Shared.Api.UnitTests/​Features/​Resources/​Bundle/​BundleHandlerStatisticsTests.cs Tests buckets, ordering, caps, and empty summaries.
src/​Microsoft.Health.Fhir.Core/​Features/​Persistence/​ResourceWrapperFactory.cs Stores index counts on bundle-entry request contexts.

🧠 Review effort: Balanced


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

Comment thread src/Microsoft.Health.Fhir.Shared.Api/Features/Resources/Bundle/BundleHandler.cs Outdated
Rename totalBundleBytes to bundleRequestBodyBytes and log null when Content-Length is absent. Rename entrySize to resourceSize and measure Binary JSON Patch entries by their base64-encoded data size. Record search index values even when an entry is cancelled during the 429 retry delay.
Use the routed resource type for search index statistics so PATCH entries are attributed to the indexed resource instead of the Parameters/Binary payload. Filter measured resources with Where per code scanning.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Azure API for FHIR Label denotes that the issue or PR is relevant to the Azure API for FHIR Azure Healthcare APIs Label denotes that the issue or PR is relevant to the FHIR service in the Azure Healthcare APIs Enhancement Enhancement on existing functionality. No-ADR ADR not needed No-PaaS-breaking-change Schema Version unchanged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants