LCOV - code coverage report
Current view: top level - lib/src/export - otlp_http_protocol.dart (source / functions) Coverage Total Hit
Test: lcov.info Lines: 75.0 % 4 3
Test Date: 2026-07-11 13:35:19 Functions: - 0 0

            Line data    Source code
       1              : // Copyright The OpenTelemetry Authors
       2              : // SPDX-License-Identifier: Apache-2.0
       3              : 
       4              : /// Wire-format protocol for OTLP/HTTP exporters.
       5              : ///
       6              : /// The OpenTelemetry specification defines two HTTP encodings:
       7              : ///   - `application/x-protobuf` — protobuf-encoded OTLP messages. The
       8              : ///     spec-recommended default; smaller payloads, faster to encode.
       9              : ///   - `application/json` — JSON-encoded OTLP messages using the
      10              : ///     protobuf-to-JSON mapping (proto3 JSON). Optional per spec — SDKs
      11              : ///     `MAY` support it — but supported by Dartastic for parity with the
      12              : ///     JS/Python implementations and for backends that prefer JSON for
      13              : ///     human-readable telemetry (e.g. local dev UIs, Browser DevTools).
      14              : ///
      15              : /// See `specification/protocol/exporter.md` for the full conformance
      16              : /// rules; the env-var `OTEL_EXPORTER_OTLP_PROTOCOL` (and signal-specific
      17              : /// `_TRACES_PROTOCOL` / `_METRICS_PROTOCOL` / `_LOGS_PROTOCOL` variants)
      18              : /// selects this from configuration with values `http/protobuf` or
      19              : /// `http/json`. `OtlpHttpProtocol.httpProtobuf` is the default.
      20              : enum OtlpHttpProtocol {
      21              :   /// `application/x-protobuf` — protobuf-encoded OTLP messages.
      22              :   httpProtobuf,
      23              : 
      24              :   /// `application/json` — proto3-JSON-encoded OTLP messages.
      25              :   httpJson,
      26              : }
      27              : 
      28              : /// Parses the OTel `OTEL_EXPORTER_OTLP_PROTOCOL` env-var value into an
      29              : /// [OtlpHttpProtocol]. Returns `null` for unsupported values (e.g. `grpc`
      30              : /// — caller is expected to handle that out-of-band by selecting an
      31              : /// OTLP/gRPC exporter instead).
      32          121 : OtlpHttpProtocol? otlpHttpProtocolFromString(String value) {
      33          242 :   switch (value.trim().toLowerCase()) {
      34          121 :     case 'http/protobuf':
      35              :       return OtlpHttpProtocol.httpProtobuf;
      36            0 :     case 'http/json':
      37              :       return OtlpHttpProtocol.httpJson;
      38              :     default:
      39              :       return null;
      40              :   }
      41              : }
        

Generated by: LCOV version 2.0-1