feat(otlptracegrpc,otlpmetricgrpc): support zstd compression

LI
2mo ago
+1836-181

Fixes #8984.

WithCompressor/WithCompression in otlptracegrpc, otlpmetricgrpc, otlptracehttp, and otlpmetricgrpc only recognized gzip; any other value silently fell back to no compression (gRPC) or, on HTTP, wasn't wired into the request builder at all (WithCompression(ZstdCompression) left bodyReader nil and panicked on first export). This adds zstd as a first-class value across all four exporters, following the zstd OTEP that came out of review on this PR.

  • All four transports: zstd is now handled end-to-end (gRPC already worked; HTTP request builders previously had no case for it at all, and otlptracehttp never even exported a ZstdCompression constant).
  • gzip fallback on rejection: UNIMPLEMENTED (gRPC) / 415/400 (HTTP) for a zstd-compressed export are non-retryable under OTLP's existing retry semantics, so a receiver that doesn't support zstd would otherwise drop the batch outright, even though both sides are spec-compliant. The exporter now retries once with gzip, which every conformant OTLP receiver is required to support, and logs a warning via otel.Handle when it does.
  • nozstd build tag: excludes the klauspost/compress dependency and codec registration entirely. A build with the tag fails fast at exporter construction/Start if zstd is still configured, rather than an opaque runtime error at first export.
  • Wire format: pooled zstd.Encoder/Decoder, mirroring gzip's existing streaming Compress/Decompress shape (not a different shape just for zstd), with the window capped at 8 MB per RFC 9659 §3's HTTP interoperability recommendation.
  • Added a default: case to both HTTP compression switches, fixing the general silent-nil-bodyReader failure mode, not just the zstd instance of it.

Verified beyond go build/go test:

  • Wire-level tests in all four packages: happy-path (asserting the actual negotiated codec / decoded frame, not just that export succeeds), fallback-on-rejection, and nozstd fail-fast.
  • Round-tripped against a real Collector (otel/opentelemetry-collector-contrib, not just this PR's own mocks) for both gRPC and HTTP zstd payloads.

Still open

  • The sibling bug this issue also flagged — an unrecognized WithCompressor value silently falls back to no compression instead of erroring — is intentionally left out of this PR; it's a separate, SDK-specific behavior change from the spec-following work here.
  • Whether opentelemetry-configuration's schema needs a companion PR before the OTEP (and by extension this PR) can merge is still being discussed on the OTEP thread.