feat: add 'opentelemetry-exporter-otlp-json-common' package#4996
feat: add 'opentelemetry-exporter-otlp-json-common' package#4996herin049 wants to merge 10 commits intoopen-telemetry:mainfrom
Conversation
a06e192 to
6a0c46f
Compare
...son-common/src/opentelemetry/exporter/otlp/json/common/_internal/metrics_encoder/__init__.py
Show resolved
Hide resolved
|
Thanks for this and the benchmarks! I like how it's laid out very similarly to the otlp-proto-common.
I believe they were moved to test_1.yml |
That was my goal, although I made a few alterations/simplifications. |
tammy-baylis-swi
left a comment
There was a problem hiding this comment.
Lgtm, would be great if others from the discussion to have a look too.
|
Hi, excited to see this progressing! We have a use case where OTLP JSON would be really valuable. We're building an observability pipeline where traces need to be both forwarded to a backend (Langfuse) and persisted to disk as OTLP JSON files for audit/replay purposes. The current from google.protobuf.json_format import MessageToJson
from opentelemetry.exporter.otlp.proto.common.trace_encoder import encode_spans
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.trace.export import SpanExportResult
class OTLPJsonSpanExporter(OTLPSpanExporter):
"""OTLPSpanExporter that sends OTLP JSON instead of protobuf."""
def export(self, spans):
try:
encoded = encode_spans(spans)
serialized = MessageToJson(encoded, preserving_proto_field_name=True)
self._session.headers["Content-Type"] = "application/json"
return self._export(serialized.encode("utf-8"))
except Exception:
return SpanExportResult.FAILUREThis works but depends on internal APIs (encode_spans, _export). Having an official Would love to see this merged. Happy to help test! |
pmcollins
left a comment
There was a problem hiding this comment.
Thanks for doing this. LGTM overall, just a concern about raising exceptions.
| elif isinstance(sdk_exemplar.value, int): | ||
| json_exemplar.as_int = sdk_exemplar.value | ||
| else: | ||
| raise ValueError("Exemplar value must be an int or float") |
There was a problem hiding this comment.
Looks like this exception is not handled in this PR, but I suppose it could be handled by the caller in a subsequent one (we don't want the SDK to throw an unhandled exception). In any case, even if it were handled I'm not sure we want to fail the encoding call chain on a bad value. May be a better to log and keep going -- convert as much as possible to JSON and log any weird data that had to be skipped rather than skipping the entire message.
| ] | ||
| ) | ||
| ) | ||
| raise TypeError(f"Invalid type {type(value)} of value {value}") |
There was a problem hiding this comment.
Ditto about raising an exception here.
| { name = "OpenTelemetry Authors", email = "cncf-opentelemetry-contributors@lists.cncf.io" }, | ||
| ] | ||
| classifiers = [ | ||
| "Development Status :: 5 - Production/Stable", |
Description
Follow up to #4910 to progress towards adding support for OTLP JSON.
Fixes #1003
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Does This PR Require a Contrib Repo Change?
Checklist: