Skip to content

Add OTLP payload byte-size chunking to Agent365Exporter#237

Merged
fpfp100 merged 4 commits into
mainfrom
users/pefan/fixexpanderforoversize
Apr 27, 2026
Merged

Add OTLP payload byte-size chunking to Agent365Exporter#237
fpfp100 merged 4 commits into
mainfrom
users/pefan/fixexpanderforoversize

Conversation

@fpfp100

@fpfp100 fpfp100 commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds heuristic span size estimator (estimateSpanBytes) and byte-size chunking (chunkBySize) to split export batches into sub-batches under 900 KB (configurable via maxPayloadBytes on Agent365ExporterOptions)
  • Refactors exportGroup to map+truncate spans, chunk by estimated size, then POST each chunk with all-or-nothing retry semantics
  • Existing per-span truncation (250 KB cap) is unchanged; this complements it at the batch level to prevent 1 MB server-side rejection (403/502/500)

Test plan

Unit tests

  • 12 new unit tests for estimator, chunking, and truncation verification
  • All 40 existing exporter tests pass
  • Full suite: 1262 tests across 62 suites, 0 failures

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:

Setting Base SDK A365 Distro (span correctness) A365 Distro (export correctness)
A365 distro initialized No Yes Yes
isObservabilityExporterEnabled N/A true true
A365 remote export N/A Disabled Enabled
Exporter ConsoleSpanExporter Agent365Exporter (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)

  • Create spans via InvokeAgentScope, InferenceScope, ExecuteToolScope with A365 distro initialized
  • Verify span attributes (gen_ai.operation.name, gen_ai.system, custom attributes) match what the base SDK tracer would produce
  • Verify parent-child span relationships are preserved (InvokeAgent → Inference → ExecuteTool)
  • Verify BaggageBuilder context propagation (tenant ID, agent ID, correlation ID) is copied to span attributes by the SpanProcessor without altering the underlying span structure
  • Verify span timing (start/end), status codes, and events are identical to base SDK output

Auto-instrumentation (SpanProcessor enrichment)

  • Create spans via the raw OTel tracer API (not scope classes) with the A365 SpanProcessor registered
  • Verify SpanProcessor.onStart copies baggage entries to span attributes for genAI operations only
  • Verify non-genAI spans pass through the SpanProcessor without modification — attributes, timing, and status identical to base SDK
  • Verify span count: same number of spans recorded in both configurations
  • Verify trace/span IDs: format and propagation consistent between base and distro

2. Export correctness (A365 enabled, export enabled)

Verify that spans are exported faithfully through the Agent365Exporter pipeline including chunking and truncation.

Manual instrumentation

  • Create spans via scope classes and verify the exported OTLP payload contains all expected spans with correct attributes
  • Verify per-span truncation (250 KB cap) is applied without data loss on non-oversized spans
  • Verify byte-size chunking splits batches correctly — no spans dropped, duplicated, or reordered across chunks
  • Verify each chunk POST contains valid OTLP structure with correct resource and scope metadata

Auto-instrumentation

  • Create spans via raw OTel tracer API and verify SpanProcessor-enriched attributes appear in the exported payload
  • Verify genAI spans include baggage-derived attributes in export; non-genAI spans are filtered out by the exporter
  • Verify retry semantics: failed chunk export retries the full chunk, not individual spans

Comparison checklist

  • A365 distro adds baggage-derived attributes but does not remove or alter base span attributes
  • Exported span count matches recorded span count (for genAI spans)
  • No data loss from chunking/truncation — all spans under size limits are exported intact

🤖 Generated with Claude Code

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>
Copilot AI review requested due to automatic review settings April 22, 2026 20:36
@fpfp100
fpfp100 requested a review from a team as a code owner April 22, 2026 20:36

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.

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 / estimateValueBytes and generic chunkBySize utilities for heuristic byte-size estimation and chunking.
  • Refactors Agent365Exporter.exportGroup to 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.

Comment thread packages/agents-a365-observability/src/tracing/exporter/utils.ts
Comment thread packages/agents-a365-observability/src/tracing/exporter/Agent365Exporter.ts Outdated
…65Exporter.ts

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 24, 2026 18:37

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.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.

Comment thread packages/agents-a365-observability/src/tracing/exporter/utils.ts
Comment thread packages/agents-a365-observability/src/index.ts Outdated
Comment thread tests/observability/core/payload-chunking.test.ts Outdated
- 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>
@fpfp100
fpfp100 enabled auto-merge (squash) April 27, 2026 18:27
Copilot AI review requested due to automatic review settings April 27, 2026 18:27
@fpfp100
fpfp100 merged commit e05b3b6 into main Apr 27, 2026
8 of 9 checks passed
@fpfp100
fpfp100 deleted the users/pefan/fixexpanderforoversize branch April 27, 2026 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants