-
Notifications
You must be signed in to change notification settings - Fork 3
Add endpointURL for bare IP:port values #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -188,6 +188,13 @@ func SetupOTelSDKWithConfig(ctx context.Context, cfg OTelConfig) (shutdown func( | |||||||||||||||||||||||
| err = errors.Join(inErr, shutdown(ctx)) | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // Normalize endpoint to include a URL scheme so WithEndpointURL can | ||||||||||||||||||||||||
| // parse it. Bare IP:port values like "127.0.0.1:4317" cause url.Parse | ||||||||||||||||||||||||
| // to fail with "first path segment in URL cannot contain colon". | ||||||||||||||||||||||||
| if cfg.Endpoint != "" { | ||||||||||||||||||||||||
| cfg.Endpoint = endpointURL(cfg.Endpoint, cfg.Insecure) | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // Create resource with service information. | ||||||||||||||||||||||||
| res, err := newResource(cfg) | ||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||
|
|
@@ -276,6 +283,21 @@ func newPropagator(cfg OTelConfig) propagation.TextMapPropagator { | |||||||||||||||||||||||
| return propagation.NewCompositeTextMapPropagator(propagators...) | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // endpointURL ensures the endpoint has a URL scheme. The OTel SDK internally | ||||||||||||||||||||||||
| // reads OTEL_EXPORTER_OTLP_ENDPOINT and parses it with url.Parse, which fails | ||||||||||||||||||||||||
| // for bare IP:port values like "127.0.0.1:4317" with "first path segment in | ||||||||||||||||||||||||
| // URL cannot contain colon". Prepending a scheme based on the insecure flag | ||||||||||||||||||||||||
| // produces a valid URL the SDK can parse. | ||||||||||||||||||||||||
|
Comment on lines
+286
to
+290
|
||||||||||||||||||||||||
| // endpointURL ensures the endpoint has a URL scheme. The OTel SDK internally | |
| // reads OTEL_EXPORTER_OTLP_ENDPOINT and parses it with url.Parse, which fails | |
| // for bare IP:port values like "127.0.0.1:4317" with "first path segment in | |
| // URL cannot contain colon". Prepending a scheme based on the insecure flag | |
| // produces a valid URL the SDK can parse. | |
| // endpointURL ensures the endpoint has a URL scheme suitable for use with | |
| // OTLP exporter WithEndpointURL options. These helpers expect an endpoint | |
| // value that url.Parse can handle, so bare IP:port values like "127.0.0.1:4317" | |
| // would otherwise fail with "first path segment in URL cannot contain colon". | |
| // Prepending "http://" or "https://" based on the insecure flag yields a valid | |
| // URL while preserving the original host and port. |
Copilot
AI
Feb 13, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
endpointURL should probably strings.TrimSpace(raw) before checking/adding a scheme; otherwise values like "127.0.0.1:4317\n" or " localhost:4317" will be turned into an invalid URL and WithEndpointURL will fail to parse.
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -5,6 +5,7 @@ package utils | |||
|
|
||||
| import ( | ||||
| "context" | ||||
|
|
||||
|
||||
Copilot
AI
Feb 13, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test sets OTEL_EXPORTER_OTLP_ENDPOINT but then constructs cfg.Endpoint directly, so the env var doesn’t influence the behavior under test. Consider either (1) building cfg via OTelConfigFromEnv() to validate the end-to-end env->cfg->normalization flow, or (2) removing the t.Setenv line to avoid implying env var handling is being tested here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR description says SetupOTelSDKWithConfig sets OTEL_EXPORTER_OTLP_ENDPOINT after normalizing, but this function only rewrites cfg.Endpoint and never updates the environment variable. Either update the PR description (and the nearby comments) or set the env var here if that behavior is required for SDK/env-based configuration.