open-telemetry / opentelemetry-collector-contrib

Contrib repository for the OpenTelemetry Collector
https://opentelemetry.io
Apache License 2.0
3.02k stars 2.34k forks source link

[connector/otlpjson] Invalid OTLP payload is silently ignored #35739

Open andrzej-stencel opened 1 week ago

andrzej-stencel commented 1 week ago

Component(s)

connector/otlpjson

What happened?

Description

The OTLP/JSON connector reports errors on invalid JSON, but silently ignores valid JSON that is not valid OTLP. I would expect it to also error out on valid JSON that is not valid OTLP. As another enhancement, an error_mode option could be added for users to configure the behavior.

Steps to Reproduce

  1. Prepare a newline-delimited JSON file like the below non-otlp.json file:

    {"one":"two"}
    {"this":{"is": {"not": "otlp"}}}
  2. Run the collector with the below configuration, reading the file with Filelog receiver and passing it to OTLP/JSON connector and to Debug exporter.

Expected Result

The OTLP/JSON connector rejects the input lines, outputting an error message saying that the input is not valid OTLP.

Actual Result

The connector does not report any errors. It emits an empty batch for each invalid OTLP line (see related issue https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/35738).

Collector version

v0.111.0

Environment information

Environment

OS: Ubuntu 24.04

OpenTelemetry Collector configuration

connectors:
  otlpjson:
exporters:
  debug:
    verbosity: basic
receivers:
  filelog:
    include:
      - non-otlp.json
    start_at: beginning
service:
  pipelines:
    logs/input:
      exporters: [otlpjson]
      receivers: [filelog]
    logs/otlp:
      exporters: [debug]
      receivers: [otlpjson]

Log output

2024-10-11T12:40:27.217+0200    info    service@v0.111.0/service.go:136 Setting up own telemetry...
2024-10-11T12:40:27.217+0200    info    telemetry/metrics.go:70 Serving metrics {"address": "localhost:8888", "metrics level": "Normal"}
2024-10-11T12:40:27.217+0200    info    builders/builders.go:26 Development component. May change in the future.        {"kind": "exporter", "data_type": "logs", "name": "debug"}
2024-10-11T12:40:27.218+0200    info    otlpjsonconnector@v0.111.0/logs.go:27   Building otlpjson connector for logs    {"kind": "connector", "name": "otlpjson", "exporter_in_pipeline": "logs", "receiver_in_pipeline": "logs"}
2024-10-11T12:40:27.219+0200    info    service@v0.111.0/service.go:208 Starting otelcol-contrib...     {"Version": "0.111.0", "NumCPU": 20}
2024-10-11T12:40:27.219+0200    info    extensions/extensions.go:39     Starting extensions...
2024-10-11T12:40:27.219+0200    info    adapter/receiver.go:47  Starting stanza receiver        {"kind": "receiver", "name": "filelog", "data_type": "logs"}
2024-10-11T12:40:27.219+0200    info    service@v0.111.0/service.go:234 Everything is ready. Begin running and processing data.
2024-10-11T12:40:27.420+0200    info    fileconsumer/file.go:256        Started watching file   {"kind": "receiver", "name": "filelog", "data_type": "logs", "component": "fileconsumer", "path": "non-otlp.json"}
2024-10-11T12:40:27.521+0200    info    LogsExporter    {"kind": "exporter", "data_type": "logs", "name": "debug", "resource logs": 0, "log records": 0}
2024-10-11T12:40:27.521+0200    info    LogsExporter    {"kind": "exporter", "data_type": "logs", "name": "debug", "resource logs": 0, "log records": 0}

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.

github-actions[bot] commented 1 week ago

Pinging code owners:

ChrsMark commented 1 week ago

Doesn't this fall into the same category with what the https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/35738 describes?

A ptrace given as an input to metrics' unmarshaller is an "invalid" otlp similar to what a very random JSON would be 🤔 .