-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Description
Component(s)
connector/otlpjson
Is your feature request related to a problem? Please describe.
Version: v0.111.0
Steps to reproduce:
- Prepare a JSON file (or multiple different files) with OTLP JSON logs, metrics and traces. (For example start a collector with OTLP receiver and File exporter and run
telemetrygento send logs, metrics, spans to it.) Seeotlp-all.jsonfile below for a working example. - Start the OTel Collector v0.111.0 with the below configuration that uses Filelog receiver to read the file(s) and passes the log lines to the OTLP/JSON connector and then to the Debug exporter for all signal types (logs, metrics, traces).
config.yaml:
connectors:
otlpjson:
exporters:
debug:
verbosity: basic
receivers:
filelog:
include:
- otlp-all.json
start_at: beginning
service:
pipelines:
logs/input:
exporters: [otlpjson]
receivers: [filelog]
logs:
exporters: [debug]
receivers: [otlpjson]
metrics:
exporters: [debug]
receivers: [otlpjson]
traces:
exporters: [debug]
receivers: [otlpjson]otlp-all.json:
{"resourceLogs":[{"resource":{},"scopeLogs":[{"scope":{},"logRecords":[{"timeUnixNano":"1728633131034642343","severityNumber":9,"severityText":"Info","body":{"stringValue":"the message"},"attributes":[{"key":"app","value":{"stringValue":"server"}}],"droppedAttributesCount":1,"traceId":"","spanId":""}]}]}]}
{"resourceMetrics":[{"resource":{},"scopeMetrics":[{"scope":{},"metrics":[{"name":"gen","gauge":{"dataPoints":[{"timeUnixNano":"1728633123818516058","asInt":"0"}]}}]}],"schemaUrl":"https://opentelemetry.io/schemas/1.13.0"}]}
{"resourceSpans":[{"resource":{"attributes":[{"key":"service.name","value":{"stringValue":"telemetrygen"}}]},"scopeSpans":[{"scope":{"name":"telemetrygen"},"spans":[{"traceId":"554fe3d717447686b5427188a768eb16","spanId":"ef398864cd536fa8","parentSpanId":"d252c1d6ce0f4452","flags":256,"name":"okey-dokey-0","kind":2,"startTimeUnixNano":"1728633116345405444","endTimeUnixNano":"1728633116345528444","attributes":[{"key":"net.peer.ip","value":{"stringValue":"1.2.3.4"}},{"key":"peer.service","value":{"stringValue":"telemetrygen-client"}}],"status":{}},{"traceId":"554fe3d717447686b5427188a768eb16","spanId":"d252c1d6ce0f4452","parentSpanId":"","flags":256,"name":"lets-go","kind":3,"startTimeUnixNano":"1728633116345405444","endTimeUnixNano":"1728633116345528444","attributes":[{"key":"net.peer.ip","value":{"stringValue":"1.2.3.4"}},{"key":"peer.service","value":{"stringValue":"telemetrygen-server"}}],"status":{}}]}],"schemaUrl":"https://opentelemetry.io/schemas/1.4.0"}]}Actual behavior:
The OTLP/JSON connector emits empty logs, metrics, traces resources. Here is the output from the Debug exporter:
2024-10-11T12:25:01.074+0200 info LogsExporter {"kind": "exporter", "data_type": "logs", "name": "debug", "resource logs": 1, "log records": 1}
2024-10-11T12:25:01.074+0200 info LogsExporter {"kind": "exporter", "data_type": "logs", "name": "debug", "resource logs": 0, "log records": 0}
2024-10-11T12:25:01.075+0200 info LogsExporter {"kind": "exporter", "data_type": "logs", "name": "debug", "resource logs": 0, "log records": 0}
2024-10-11T12:25:01.075+0200 info MetricsExporter {"kind": "exporter", "data_type": "metrics", "name": "debug", "resource metrics": 0, "metrics": 0, "data points": 0}
2024-10-11T12:25:01.075+0200 info MetricsExporter {"kind": "exporter", "data_type": "metrics", "name": "debug", "resource metrics": 1, "metrics": 1, "data points": 1}
2024-10-11T12:25:01.075+0200 info MetricsExporter {"kind": "exporter", "data_type": "metrics", "name": "debug", "resource metrics": 0, "metrics": 0, "data points": 0}
2024-10-11T12:25:01.075+0200 info TracesExporter {"kind": "exporter", "data_type": "traces", "name": "debug", "resource spans": 0, "spans": 0}
2024-10-11T12:25:01.075+0200 info TracesExporter {"kind": "exporter", "data_type": "traces", "name": "debug", "resource spans": 0, "spans": 0}
2024-10-11T12:25:01.075+0200 info TracesExporter {"kind": "exporter", "data_type": "traces", "name": "debug", "resource spans": 1, "spans": 2}Describe the solution you'd like
Expected behavior:
I would expect the OTLP/JSON connector to not emit empty resources. Here's the output from Debug exporter I would expect:
2024-10-11T12:25:01.074+0200 info LogsExporter {"kind": "exporter", "data_type": "logs", "name": "debug", "resource logs": 1, "log records": 1}
2024-10-11T12:25:01.075+0200 info MetricsExporter {"kind": "exporter", "data_type": "metrics", "name": "debug", "resource metrics": 1, "metrics": 1, "data points": 1}
2024-10-11T12:25:01.075+0200 info TracesExporter {"kind": "exporter", "data_type": "traces", "name": "debug", "resource spans": 1, "spans": 2}Describe alternatives you've considered
No response
Additional context
The Unmarshal(Logs|Metrics|Traces) methods do not return an error for valid JSON that is not a valid OTLP payload. They just return an empty object of logs/metrics/traces data. See https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/v0.111.0/connector/otlpjsonconnector/traces.go#L55 for example. The code should be updated to not only check for error, but also check if the payload has any data in it.