Skip to content

Fix exporting of very large spans and payloads - #1027

Merged
alexmojaki merged 5 commits into
mainfrom
alex/check-size-in-exporter
Apr 21, 2025
Merged

alexmojaki merged 5 commits into
mainfrom
alex/check-size-in-exporter

Conversation

@alexmojaki

@alexmojaki alexmojaki commented Apr 21, 2025 •

Copy link
Copy Markdown
Contributor

Replaces #1026

  • Measures the OTLP trace export body size before compression. This should prevent an edge case where the SDK could send a highly compressed payload of many spans that the backend would reject for being too big. Instead it will split the payload in two as usual.
  • When a single span exceeds the SDK's 5MB limit, just send it.
    • The backend has since increased its limit, so we shouldn't have been dropping it. This way the limits don't have to stay in sync.
    • The SDK was supposed to be logging something in this case about the dropped span. But it was doing so with logfire, inside a context where instrumentation is suppressed. So the data was being dropped silently. Now, when the backend rejects a large payload that was otherwise not even being sent, OTel logs the following using stdlib logging: Failed to export batch code: 413, reason: Failed to buffer the request body: length limit exceeded. We should try to make this message clearer some other time.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Apr 21, 2025 •

Copy link
Copy Markdown

Deploying logfire-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: e8c2247
Status: ✅  Deploy successful!
Preview URL: https://3d653e54.logfire-docs.pages.dev
Branch Preview URL: https://alex-check-size-in-exporter.logfire-docs.pages.dev

View logs

@alexmojaki alexmojaki changed the title WIP Fix exporting of very large spans and payloads Apr 21, 2025
@alexmojaki
alexmojaki marked this pull request as ready for review April 21, 2025 15:47
@alexmojaki
alexmojaki requested a review from adriangb April 21, 2025 15:48
Comment on lines +35 to +40
def _serialize_spans(self, spans: Sequence[ReadableSpan]) -> bytes:
result = super()._serialize_spans(spans) # type: ignore
if len(spans) > 1 and len(result) > self.max_body_size:
# Tell outer RetryFewerSpansSpanExporter to split in half
raise BodyTooLargeError(len(result), self.max_body_size)
return result

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

My only piece of feedback is that this could be expensive and that instead of re-serializing we could transform to protobuf and then manipulate the in-memory representation of the protobuf since that's cheap to manipulate and cheap to calculate the size of objects and their children.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ideally yes, but not really worth it now.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ok

@alexmojaki
alexmojaki merged commit f9e9310 into main Apr 21, 2025
@alexmojaki
alexmojaki deleted the alex/check-size-in-exporter branch April 21, 2025 17:54
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.

2 participants