feat: [#726] Harden OTLP exporter configuration [7] - #1475
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #1475 +/- ##
========================================
Coverage 69.43% 69.43%
========================================
Files 375 376 +1
Lines 29730 30097 +367
========================================
+ Hits 20642 20899 +257
- Misses 8141 8231 +90
- Partials 947 967 +20 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR hardens the OTLP telemetry exporter configuration by aligning protocol/temporality behavior with the OpenTelemetry SDK capabilities and adding missing transport features (URL-path endpoints, TLS, compression, retry), while failing fast on unsupported configuration values.
Changes:
- Make OTLP protocol handling strict (unsupported protocols error at boot) and add endpoint URL-path support for OTLP/HTTP exporters.
- Add OTLP exporter options for TLS (CA/mTLS), compression (gzip), and retry tuning for traces/metrics/logs.
- Delegate metric temporality selection to SDK selectors (including a new
lowmemorypreset) and extend test coverage accordingly.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| telemetry/trace.go | Refactors OTLP trace exporter option building; adds compression/TLS/retry and strict protocol handling. |
| telemetry/trace_test.go | Adds config-level and exporter-level tests for unsupported protocol, URL paths, compression/retry, and TLS conflicts. |
| telemetry/setup/stubs.go | Updates telemetry config stubs: removes http/json, documents temporality presets, adds compression/tls/retry blocks. |
| telemetry/otlp.go | Introduces shared OTLP option builder, endpoint parsing (scheme/path), TLS config loader, compression and retry support. |
| telemetry/otlp_test.go | Adds unit tests for endpoint parsing, compression/retry, and TLS config behavior. |
| telemetry/metric.go | Updates OTLP metric exporter to use shared option builder; adds compression/TLS/retry and SDK temporality selectors. |
| telemetry/metric_test.go | Extends tests for strict protocol errors and temporality selector behavior across instrument kinds. |
| telemetry/log.go | Updates OTLP log exporter to use shared option builder; adds compression/TLS/retry and strict protocol handling. |
| telemetry/log_test.go | Adds tests for unsupported protocol, URL paths, compression/retry, and TLS conflicts for log exporter setup. |
| telemetry/config.go | Extends exporter config schema with compression, TLS, and retry settings. |
| errors/list.go | Adds centralized telemetry errors for unsupported protocol/compression and TLS-related config validation. |
| "tls": map[string]any{ | ||
| "ca": config.Env("OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE", ""), | ||
| "cert": config.Env("OTEL_EXPORTER_OTLP_TRACES_CLIENT_CERTIFICATE", ""), | ||
| "key": config.Env("OTEL_EXPORTER_OTLP_TRACES_CLIENT_KEY", ""), | ||
| }, |
There was a problem hiding this comment.
Is it possible to test the tls feature in goravel/example?
There was a problem hiding this comment.
Yes, I will raise a PR for this in goravel/example
| if usesInsecureTransport(cfg) { | ||
| opts = append(opts, builders.withInsecure()) | ||
| } |
There was a problem hiding this comment.
The relationship between line 51 and line 39 should be if else, right? The current code structure is a bit strange. Could you optimize it?
There was a problem hiding this comment.
Earlier we were parsing the url and setting insecure manually. That was only to work around the otlploghttp bug where WithEndpointURL does not add /v1/logs when the url has no path (trace and metric handle it, logs do not).
Now we let the SDK do it. WithEndpointURL for url endpoints, and WithEndpoint with the insecure flag for bare host. So usesInsecureTransport and the manual parsing are removed.
One known thing, a scheme log endpoint without a path will still miss /v1/logs because of the same SDK bug. So we keep the default endpoint as bare localhost:4318.
Use WithEndpointURL for scheme-bearing endpoints (host, path, and insecure derive from the URL) and WithEndpoint plus the insecure flag for bare hosts, instead of hand-parsing the URL and re-deriving the scheme. Drops the redundant usesInsecureTransport helper, the withURLPath wiring, and the TLS-conflicts-with-insecure error -- TLS-vs-insecure precedence is the SDK's job. Defaults the stub endpoints to bare localhost:4318 so logs are unaffected by otlploghttp's empty-path defect.
|
The example ci should be fixed in the master. |
I will fix it in currently raised PR in example repo |
📑 Description
RelatedTo goravel/goravel#726
The OTLP exporter config advertises a protocol the SDK cannot do, exports wrong data for UpDownCounters under delta temporality, and lacks TLS, compression, retry tuning, and URL-path endpoints. Telemetry is unreleased, so these correctness fixes land before the v1.18 config shape freezes.
What is changing (with examples):
metric_temporalitydelegates to the SDK preset selectors instead of a hand-rolled switch;lowmemoryadded as the third standard value.http/jsonremoved; unknown protocols fail at boot instead of silently exporting protobuf.WithEndpointURL, so paths survive and security derives from the scheme.tlsblock (ca/cert/keyfile paths) for private-CA and mTLS collectors; conflicts withinsecureare rejected at boot.compression("gzip") andretrytuning; retry stays SDK-default (enabled, 5s/30s/1m) when omitted.processorblock for traces and logs: "batch" (default) or "simple" (synchronous export, useful with the console exporter during development), plus batchinterval/timeout; unknown types fail at boot.Side effects / breaking changes:
ProtocolHTTPJSONand the old all-delta selector are removed pre-release.✅ Checks