Skip to content

Feature/json file http exporter #4556

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

NN---
Copy link
Contributor

@NN--- NN--- commented Apr 20, 2025

Addition to #4470 to write the id as hex so they can be exported to files.

Add new packages for JSON-based OTLP exporters as alternatives to the existing
Protobuf-based exporters:
- opentelemetry-exporter-otlp-json-common: Common JSON encoding functionality
- opentelemetry-exporter-otlp-json-http: HTTP transport implementation

These exporters enable compatibility with services requiring JSON format
instead of Protobuf. Implementation includes full support for traces, metrics,
and logs with comprehensive test coverage following project guidelines.

Closes open-telemetry#1003
Replace 'too-many-positional-arguments' with the correct pylint message ID 'too-many-arguments'
and fix type ignore comments placement for imports without stubs.
Replace string representation of integers with actual integer values in the OTLP JSON exporters
to comply with the OTLP specification. This ensures integer attributes are properly encoded as
{intValue: 123} instead of {intValue: 123} for better compatibility with OTLP receivers.
@NN--- NN--- requested a review from a team as a code owner April 20, 2025 08:38
Copy link

linux-foundation-easycla bot commented Apr 20, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@NN--- NN--- marked this pull request as draft April 20, 2025 08:40
@NN--- NN--- force-pushed the feature/json-file-http-exporter branch from 2a4eab4 to 50f119d Compare April 20, 2025 08:44
@NN--- NN--- force-pushed the feature/json-file-http-exporter branch from 50f119d to 278afd4 Compare April 20, 2025 08:48
Comment on lines +150 to +153
return [
_encode_value(v, allow_null=allow_null) if v is not None else None
for v in array
]
Copy link
Contributor

Choose a reason for hiding this comment

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

Caveat: the spec mandates that arrays are homogeneous.

I don't have a strong opinion on what the expectation of the client-side library is: to actually raise on that, or skip the top-level key, or pass through.

Here's how I've done this:

Comment on lines +193 to +194
if isinstance(value, int):
return {"value": {"intValue": value}}
Copy link
Contributor

Choose a reason for hiding this comment

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

Sadly that's incorrect.

Recall that JavaScript coerces large integers to floating point.

I believe this is spelled out in the OTLP spec.

@NN---
Copy link
Contributor Author

NN--- commented May 13, 2025

@dimaqq Please pay attention to the original PR so the author can address the comments.
This just has a small addition on top of it to make it correctly work according to opentelemetry file spec.

@dimaqq
Copy link
Contributor

dimaqq commented May 13, 2025

You may consider using https://pypi.org/project/otlp-test-data/ , a small project I made to generate all conceivable "weird" input.

That includes the JSON flavour of OTLP serialisation, to the best of my understanding.

I could be wrong on some details, PRs are welcome :)

@NN---
Copy link
Contributor Author

NN--- commented May 13, 2025

@dimaqq Do you know whether trace and spans ids in http/json are base64 encoded?
In files they are hex encoded , hence the addition.

@dimaqq
Copy link
Contributor

dimaqq commented May 13, 2025

@dimaqq Do you know whether trace and spans ids in http/json are base64 encoded? In files they are hex encoded , hence the addition.

Do read https://opentelemetry.io/docs/specs/otlp/#json-protobuf-encoding

I mean I can answer your question off the top of my head, but then you'd miss the other half a dozen gotchas.

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.

3 participants