opentelemetry-python icon indicating copy to clipboard operation
opentelemetry-python copied to clipboard

feat(exporter): Implement OTLP JSON exporters for HTTP transport

Open andrewlwn77 opened this issue 9 months ago • 7 comments

Description

This PR adds JSON-based OTLP exporters to complement the existing Protobuf-based exporters. Many services and backends support the JSON format for OTLP data, and this implementation provides a standards-compliant way to export telemetry data in JSON format over HTTP.

The implementation follows the OpenTelemetry Protocol specification for JSON encoding and includes support for all telemetry signals (traces, metrics, and logs). The code structure mirrors the existing Protobuf exporters for consistency and ease of maintenance.

Fixes #1003

Type of change

  • [x] New feature (non-breaking change which adds functionality)
  • [x] This change requires a documentation update

How Has This Been Tested?

  • [x] Unit tests for all exporters (traces, metrics, logs)
  • [x] Integration tests verifying proper encoding and transport
  • [x] Compatibility tests with the OpenTelemetry Protocol specification
  • [x] Tests for environment variable configuration
  • [x] Tests for error handling and retry logic

Does This PR Require a Contrib Repo Change?

  • [ ] Yes. - Link to PR:
  • [x] No.

Checklist:

  • [x] Followed the style guidelines of this project
  • [x] Changelogs have been updated
  • [x] Unit tests have been added
  • [ ] Documentation has been updated

andrewlwn77 avatar Mar 10 '25 23:03 andrewlwn77

CLA Signed

The committers listed above are authorized under a signed CLA.

  • :white_check_mark: login: andrewlwn77 (9abf25caa7ab15edbbc31d31232ce680d50bfae1, 48a87c647b3bb0e4a5246bcc2f582559f31520ef, 1cacc8413cd2096df2e8e00fdc662fffe71427ea)

Can you add encodie without base64 for trace/span ids so this can be written to a file ?

NN--- avatar Apr 18 '25 21:04 NN---

OTLP JSON file needs a regular id with hex encoding, not base64.

NN--- avatar Apr 19 '25 09:04 NN---

According to the specification the ids must be hex string and not base64

The traceId and spanId byte arrays are represented as case-insensitive hex-encoded strings; they are not base64-encoded as is defined in the standard Protobuf JSON Mapping. Hex encoding is used for traceId and spanId fields in all OTLP Protobuf messages, e.g., the Span, Link, LogRecord, etc. messages. For example, the traceId field in a Span can be represented like this: { “traceId”: “5B8EFFF798038103D269B633813FC60C”, … }

https://opentelemetry.io/docs/specs/otlp/

NN--- avatar Apr 19 '25 13:04 NN---

looking forward to this being resolved! it really helps in a proxy scenario where you want to use plain lua or have a python interpreter but you can't add grpc to it.

codefromthecrypt avatar Apr 21 '25 07:04 codefromthecrypt

Hi, sorry I left some comments on #4556 instead of here by accident.

dimaqq avatar May 13 '25 05:05 dimaqq

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

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

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

dimaqq avatar Jun 04 '25 07:06 dimaqq