open-telemetry / opentelemetry-go

OpenTelemetry Go API and SDK
https://opentelemetry.io/
Apache License 2.0
5.13k stars 1.04k forks source link

Marshal log record as JSON #5500

Open corentinmusard opened 3 months ago

corentinmusard commented 3 months ago

Problem Statement

I want to write log record to a file in JSON format, is there any way to do it?

I saw in https://github.com/open-telemetry/opentelemetry-go/pull/5172#discussion_r1555020640 that this feature has been postponed.

Proposed Solution

Export this method: func (e *Exporter) newRecordJSON(r sdklog.Record) recordJSON

pellared commented 1 month ago

This is not a stable JSON representation. See https://pkg.go.dev/go.opentelemetry.io/otel/exporters/stdout/stdoutlog#pkg-overview:

it does not provide an interchange format for OpenTelemetry that is supported with any stability or compatibility guarantees

However, it is possible we could provide such functionality as part of otlplogfile package. Reference: