Add OTLP payload byte-size chunking to Agent365Exporter#237
Merged
Conversation
A365 OTLP traces endpoint enforces a 1 MB request body limit. The exporter previously batched by span count (512) with no byte-level enforcement, so batches of gen-AI spans could exceed 1 MB and get rejected (403/502/500). This adds two layers of defense: - Heuristic span size estimator (estimateSpanBytes) with generous over-estimation - Byte-size chunking (chunkBySize) that splits batches into sub-batches under maxPayloadBytes (default 900 KB, configurable via Agent365ExporterOptions) - All-or-nothing semantics: if any chunk fails, the entire batch fails and retries Per-span truncation (250 KB cap) already existed; this complements it at the batch level. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds batch-level OTLP payload size control to the Agent365 span exporter by estimating per-span serialized size and splitting export batches into multiple HTTP POST requests under a configurable byte limit (default 900 KB), complementing the existing per-span truncation cap.
Changes:
- Introduces
estimateSpanBytes/estimateValueBytesand genericchunkBySizeutilities for heuristic byte-size estimation and chunking. - Refactors
Agent365Exporter.exportGroupto map+truncate spans, chunk them, and POST each chunk sequentially. - Adds unit tests validating estimator behavior, chunking invariants, and truncation behavior; exports new utilities from package index.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/observability/core/payload-chunking.test.ts | Adds unit tests for span size estimation, chunking, and truncation verification. |
| packages/agents-a365-observability/src/tracing/exporter/utils.ts | Adds heuristic byte-size estimator and chunking helper used for request-size control. |
| packages/agents-a365-observability/src/tracing/exporter/Agent365ExporterOptions.ts | Adds maxPayloadBytes option (default 900,000 bytes). |
| packages/agents-a365-observability/src/tracing/exporter/Agent365Exporter.ts | Refactors group export to chunk spans by estimated size and POST per chunk. |
| packages/agents-a365-observability/src/index.ts | Exposes the new exporter utility functions from the package entrypoint. |
…65Exporter.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
- Use Buffer.byteLength for accurate UTF-8 byte logging - Use MappedSpan fields instead of splitting scopeKey by ':' - Remove internal utils from public exports - Fix JSDoc wording (envelope overhead, not header overhead) - Reduce oversized test array from 100k to 5.2k elements Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
juliomenendez
approved these changes
Apr 27, 2026
gwharris7
approved these changes
Apr 27, 2026
fpfp100
enabled auto-merge (squash)
April 27, 2026 18:27
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.
Summary
estimateSpanBytes) and byte-size chunking (chunkBySize) to split export batches into sub-batches under 900 KB (configurable viamaxPayloadBytesonAgent365ExporterOptions)exportGroupto map+truncate spans, chunk by estimated size, then POST each chunk with all-or-nothing retry semanticsTest plan
Unit tests
Span comparison: Base SDK vs A365 Distro
Compare spans between the base OTel SDK and the A365 distro to verify correctness and export fidelity.
Configurations under test:
isObservabilityExporterEnabledtruetrueConsoleSpanExporterAgent365Exporter(no remote)Agent365Exporter(remote)1. Span correctness (A365 enabled, export disabled)
Verify that spans produced by the A365 distro are correct and consistent with base SDK behavior when remote export is off.
Manual instrumentation (scope classes)
InvokeAgentScope,InferenceScope,ExecuteToolScopewith A365 distro initializedgen_ai.operation.name,gen_ai.system, custom attributes) match what the base SDK tracer would produceBaggageBuildercontext propagation (tenant ID, agent ID, correlation ID) is copied to span attributes by theSpanProcessorwithout altering the underlying span structureAuto-instrumentation (SpanProcessor enrichment)
SpanProcessorregisteredSpanProcessor.onStartcopies baggage entries to span attributes for genAI operations onlySpanProcessorwithout modification — attributes, timing, and status identical to base SDK2. Export correctness (A365 enabled, export enabled)
Verify that spans are exported faithfully through the
Agent365Exporterpipeline including chunking and truncation.Manual instrumentation
Auto-instrumentation
SpanProcessor-enriched attributes appear in the exported payloadComparison checklist
🤖 Generated with Claude Code