Skip to content

fix(otel): normalize OTEL endpoint env vars to prevent SDK parse errors#380

Merged
ClaraTersi merged 1 commit intodevelopfrom
fix/otel-normalize-endpoint-env-vars
Mar 21, 2026
Merged

fix(otel): normalize OTEL endpoint env vars to prevent SDK parse errors#380
ClaraTersi merged 1 commit intodevelopfrom
fix/otel-normalize-endpoint-env-vars

Conversation

@jeffersonrodrigues92
Copy link
Contributor

Summary

  • Adds normalizeEndpointEnvVars() that prepends http:// to OTEL_EXPORTER_OTLP_*_ENDPOINT env vars when they contain bare host:port without a scheme
  • Prevents the OTEL SDK's internal url.Parse() from logging noisy "parse url" errors
  • Complements the existing normalizeEndpoint() which only handled the programmatic CollectorExporterEndpoint config field

Problem

The OTEL Go SDK (v1.42.0) reads endpoint env vars internally via envconfig.WithURL()url.Parse(). When the env var contains host:port without a scheme (e.g. 10.10.0.202:4317), Go's URL parser fails:

"msg"="parse url" "error"="parse \"10.10.0.202:4317\": first path segment in URL cannot contain colon"

This happens independently of the programmatic WithEndpoint() path, which PR #362 already fixed. The SDK reads env vars before applying programmatic options, so bare host:port in env vars still caused the error.

Root Cause

The OTEL SDK's envconfig.go (lines 93-104) uses url.Parse() to read OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_TRACES_ENDPOINT, and OTEL_EXPORTER_OTLP_METRICS_ENDPOINT. The error appears twice per startup (once for trace exporter, once for metric exporter).

Test plan

  • 8 table-driven test cases × 3 env var keys = 24 subtests covering: bare host:port, hostname:port, http preserved, https preserved, whitespace trimming, empty value, whitespace-only, unset env var
  • All existing tests pass
  • go build ./commons/opentelemetry/... passes

🤖 Generated with Claude Code

The OTEL SDK internally reads OTEL_EXPORTER_OTLP_*_ENDPOINT env vars
via url.Parse(), which fails on bare "host:port" without a scheme,
producing noisy "parse url" errors in the SDK's internal logger.

normalizeEndpointEnvVars() runs before exporter creation and prepends
"http://" to any env var missing a scheme, matching the existing
normalizeEndpoint() behavior for the programmatic config path.
@coderabbitai
Copy link

coderabbitai bot commented Mar 21, 2026

Caution

Review failed

Pull request was closed or merged during review

Walkthrough

The changes add environment variable normalization for OpenTelemetry OTLP endpoint configuration. During telemetry initialization, a new helper function processes three environment variables by trimming whitespace and prepending the HTTP scheme when endpoints lack http:// or https:// prefixes. This ensures the OTEL SDK receives properly formatted endpoint URLs. Corresponding test coverage validates the normalization behavior across various input scenarios including bare hostnames, existing schemes, and whitespace handling.

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The pull request title clearly summarizes the main change: normalizing OTEL endpoint environment variables to prevent SDK parse errors.
Description check ✅ Passed The pull request description is comprehensive and well-structured, covering the summary, problem, root cause, and test plan sections thoroughly.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

@ClaraTersi ClaraTersi merged commit dfc8f4d into develop Mar 21, 2026
2 of 3 checks passed
@ClaraTersi ClaraTersi deleted the fix/otel-normalize-endpoint-env-vars branch March 21, 2026 21:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants