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

How to convert a protobuf type span to a JSON dict?

Open zhengfeiwang opened this issue 1 year ago • 0 comments

Before opening a feature request against this repo, consider whether the feature should/could be implemented in the other OpenTelemetry client libraries. If so, please open an issue on opentelemetry-specification first.

Is your feature request related to a problem? I'm working on a Python project, and I need to implement a OTLP collector to collect traces. I use OTLPSpanExporter as exporter, and a Flask serving as the collector. When receive and process the span, what I received is the protobuf type span (which is opentelemetry.proto.trace.v1.trace_pb2.Span), I need to use standard protobuf parse method MessageToJson to convert it from protobuf to a python dict and manually process.

I'm wondering if there is a standard/official way to apply such conversion? I understand there are some code that convert ReadableSpan to protobuf type, so maybe there will be some code doing the reverse?

https://github.com/open-telemetry/opentelemetry-python/blob/2b9dcfc5d853d1c10176937a6bcaade54cda1a31/exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/_internal/trace_encoder/init.py#L107-L125

Describe the solution you'd like A function that convert the protobuf one to ReadableSpan, or just a pure JSON?

Describe alternatives you've considered Customize the parse way, but it will generate lots of duplicate lines doing the same thing in this universe.

Additional context Add any other context about the feature request here.

zhengfeiwang avatar Feb 23 '24 11:02 zhengfeiwang