# Protocol compatibility

Reference: [OTLP specification](https://opentelemetry.io/docs/specs/otlp/).
Generated models are reused from `moonbit-community/opentelemetry` 0.1.8.

## Capability states and evidence

| State | Capability | Evidence / boundary |
| --- | --- | --- |
| Supported | Three signals, five metrics, HTTP JSON/protobuf | tests/external matrix with Go Collector 0.165.0; codec tests |
| Supported | Nested AnyValue, exact integers, special floats, modeled trace context | core/data/model_boundary_test.mbt, integer_test.mbt, float_boundary_test.mbt |
| Supported | Packed/unpacked normalization, modeled future enums | unpacked_wbtest.mbt, enum_test.mbt, wire_compat_test.mbt |
| Supported | Recognized response encodings, bounded partial responses | receiver_security_test.mbt, response_boundary_test.mbt, exporter_safety_test.mbt |
| Supported | Per-record routing and opt-in OTLP/HTTP self metrics | routing_test.mbt and self_metrics_test.mbt; fixed process-level metrics with JSON and protobuf |
| Limited | Unknown fields | Ordinary re-encoding can discard them; unknown_fields_wbtest.mbt |
| Limited | Metric/trace semantics | Structural checks, not bucket consistency, cross-request series/order or parent-graph verification; semantic_boundary_test.mbt |
| Limited | General ProtoJSON | Declared numeric-enum OTLP profile, not an arbitrary protobuf JSON converter |
| Unsupported | gRPC, receiver TLS, YAML, durable queues, profiles | No implementation/conformance promise; trusted proxy may terminate TLS |
| Non-goal | Instrumentation SDK, backend storage/query/dashboard | Reuse SDKs; Collector handles ingestion/processing/export |

Core data tests above are in core/data; receiver/exporter runtime cases are in
tests/integration. Supported means focused evidence for that profile, not
universal interoperability. Current and historical evidence are distinguished
in docs/VALIDATION.md.

| Area | Supported behavior |
| --- | --- |
| Transport | OTLP/HTTP JSON and protobuf on /v1/logs, /v1/metrics, /v1/traces; persistent connections |
| Compression | gzip input, including up to 16 concatenated members; compressed and cumulative expanded sizes bounded |
| Signals | Logs, traces, Gauge, Sum, Histogram, ExponentialHistogram and Summary |
| Structure | Resource/scope attributes, events, links, exemplars, correlation IDs and typed AnyValue |
| Integers | Decimal strings and exact integral JSON numeric/exponent forms for 64-bit fields; fractional or out-of-range values rejected |
| Enums | Integer JSON enums; unknown positive and negative numbers retained through supported transforms and batching |
| IDs | Hex JSON / binary protobuf; nonempty IDs require valid length and nonzero contents; spans and links require trace/span IDs |
| Repeated primitives | Packed and unpacked protobuf input normalized before generated-model decoding |
| JSON boundaries | Duplicate keys rejected; unknown fields ignored; known null fields treated as absent; oneof identity checked |
| Responses | Matching JSON/protobuf success and google.rpc.Status errors; successful partial responses counted and never retried |

Symbolic JSON enum names are rejected. The pinned SDK can emit these names, so
the SDK demo uses protobuf; numeric-enum JSON fixtures exercise JSON ingestion.
Unknown protobuf fields are skipped by the generated models. Ordinary relay
without any processors also does **not** guarantee their preservation. This is
not a transparent raw-protobuf proxy. Root and nested unknown-field injection
are covered in core/data/unknown_fields_wbtest.mbt; known fields are preserved
while the injected unknown fields disappear on normal decode/re-encode.
Some fallback paths may retain wire bytes, but this is not a preservation
contract. Transforms and JSON conversion reconstruct only recognized fields.
The future-enum fallback preserves enum numbers, not arbitrary future schemas.
Protobuf oneofs use the last member on the wire; JSON with multiple members of
the same oneof is rejected.

Ingress acknowledgement means admission to volatile input queues. Filtering and
export occur afterwards. Invalid input returns 400, unsupported media/encoding
415, oversized input 413, unavailable/full admission 503, and missing configured
signal routes 404. Authentication and source restrictions precede body reads.
Slow headers, body stalls and total request duration are bounded.

Successful outbound responses must match the selected media type and decode as
the signal response. Empty protobuf is valid; empty JSON is invalid. Response
reads default to 4 MiB and can be configured up to 64 MiB per exporter.
429/502/503/504 and transport failures can retry. Retry-After supports seconds
and IMF-fixdate, capped at one hour; retries include bounded random jitter.
Each exporter also has an overall deadline (including lock wait and backoff),
an attempt deadline and a maximum retry delay. A server-requested delay that
cannot fit is abandoned rather than retried early. See the configuration
defaults and delivery limits in [operations](docs/OPERATIONS.md).

`core/data` contains field-dispatch metadata to adapt upstream JSON oneof
inference and enum representation. It defines no duplicate telemetry structs.
Metric protobuf writing also uses the adapter to correct upstream sint32
length calculation for exponential-histogram offsets; focused boundary tests
and the external fixture matrix cover this workaround.
Floating-point fields accept finite JSON numbers, quoted finite JSON numbers
and the exact strings `NaN`, `Infinity`, `-Infinity`, including repeated bounds.
Numeric overflow is rejected; nonfinite values require explicit special strings.
See [ProtoJSON representations](https://protobuf.dev/programming-guides/json/#representation-of-each-type).
`tools/check_protocol_metadata.mbtx` checks 40 descriptors against the pinned
generated source; review the adapter when upgrading dependencies.

Real Go Collector 0.165.0 received all three signals in both HTTP encodings and
forwarded them back to a second MoonTelemetry with fixture-equivalent contents;
see [validation](docs/VALIDATION.md). This covers the committed fixtures and
does not establish full OTLP conformance certification.

Metric validation is structural: it does
not enforce every histogram bucket/count relationship, timestamp ordering,
monotonicity or cross-request time-series business rule. Structurally accepted
data is forwarded without silently repairing these semantics. A focused test
documents this boundary in core/data/semantic_boundary_test.mbt.

Not implemented: gRPC, receiver TLS termination, YAML configuration, profiles,
persistent/durable queues, durable delivery guarantees, Prometheus ingestion,
Kafka, tail sampling, remote configuration or
cluster coordination. Bearer authentication and source-IP restrictions are
available; use trusted TLS termination for remote deployment. HTTPS export
uses the async library's trust roots.
