Skip to content

Add endpointURL for bare IP:port values#32

Merged
bramwelt merged 2 commits intomainfrom
bramwelt/otel-endpoint-fix
Feb 16, 2026
Merged

Add endpointURL for bare IP:port values#32
bramwelt merged 2 commits intomainfrom
bramwelt/otel-endpoint-fix

Conversation

@bramwelt
Copy link
Contributor

This pull request improves the handling of OpenTelemetry (OTel) endpoint configuration to ensure compatibility with the OTel SDK, particularly when users provide endpoints as bare IP:port values. The changes introduce normalization of the endpoint to include the appropriate URL scheme, update SDK initialization to use new URL-based options, and add comprehensive tests for these enhancements.

Endpoint normalization and SDK integration:

  • Added logic in SetupOTelSDKWithConfig to normalize the cfg.Endpoint value by prepending an appropriate URL scheme (http:// or https://) if missing, and set the OTEL_EXPORTER_OTLP_ENDPOINT environment variable accordingly. This prevents SDK parse errors when using bare IP:port endpoints.
  • Introduced the endpointURL helper function to perform the normalization, choosing the scheme based on the Insecure flag.
  • Updated all OTel exporter initialization code to use the new WithEndpointURL option instead of WithEndpoint, ensuring the SDK receives a valid URL. This change applies to traces, metrics, and logs for both HTTP and gRPC protocols. [1] [2] [3] [4] [5] [6]

Testing improvements:

  • Added unit tests for the endpointURL function to verify correct scheme prepending and preservation of existing schemes.
  • Added an integration test to ensure SetupOTelSDKWithConfig correctly normalizes a bare IP:port endpoint and prevents SDK parse errors.

Minor cleanup:

  • Minor import formatting update in otel_test.go.

bramwelt and others added 2 commits February 12, 2026 14:56
Prepend a URL scheme to bare IP:port endpoints so
the OTel SDK can parse them. Use WithEndpointURL
consistently for all exporters and update the env
var so the SDK reads a valid URL internally.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Issue: LFXV2-609
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Trevor Bramwell <tbramwell@linuxfoundation.org>
WithEndpointURL receives the normalized endpoint
explicitly, making the env var mutation unnecessary.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Issue: LFXV2-609
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Trevor Bramwell <tbramwell@linuxfoundation.org>
Copilot AI review requested due to automatic review settings February 13, 2026 01:21
@bramwelt bramwelt requested a review from a team as a code owner February 13, 2026 01:21
@coderabbitai
Copy link

coderabbitai bot commented Feb 13, 2026

Walkthrough

The changes introduce endpoint URL normalization for OTLP endpoints in the OpenTelemetry SDK setup. A new unexported function endpointURL() normalizes endpoints by prepending http/https schemes when missing, based on an insecure configuration flag. This normalization is applied early in SetupOTelSDKWithConfig, and all exporter options are updated to use URL-based variants instead of endpoint variants across traces, metrics, and logs exporters.

Changes

Cohort / File(s) Summary
Endpoint Normalization
pkg/utils/otel.go
Added endpointURL() helper function to normalize OTLP endpoints with appropriate schemes. Updated SetupOTelSDKWithConfig to apply normalization early. Replaced all exporter endpoint options with URL-based variants: traces, metrics, and logs exporters (both HTTP and gRPC) now use WithEndpointURL instead of WithEndpoint.
Test Coverage
pkg/utils/otel_test.go
Added TestEndpointURL() to verify protocol inference and scheme preservation. Added TestSetupOTelSDKWithConfig_IPEndpoint() to validate IP:port endpoint normalization in SDK configuration. Both tests ensure endpoint normalization prevents URL parsing errors.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately reflects the main change: introducing endpointURL function to handle bare IP:port endpoint values by normalizing them with appropriate URL schemes.
Description check ✅ Passed The description is comprehensive and directly related to the changeset, explaining endpoint normalization, SDK integration updates, testing improvements, and the rationale for these changes.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into main

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch bramwelt/otel-endpoint-fix

No actionable comments were generated in the recent review. 🎉


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

@bramwelt bramwelt changed the title Bramwelt/otel endpoint fix Add endpointURL for bare IP:port values Feb 13, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the OpenTelemetry (OTel) SDK setup helpers to accept bare host:port endpoints by normalizing them into URL form (adding http:// or https:// as needed), and switches OTLP exporter initialization to URL-based endpoint options. It also adds tests to validate the normalization behavior.

Changes:

  • Normalize cfg.Endpoint via a new endpointURL helper before initializing exporters.
  • Update OTLP trace/metric/log exporter setup to use WithEndpointURL instead of WithEndpoint.
  • Add unit tests for endpoint normalization plus an integration-style test covering a bare IP:port endpoint.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
pkg/utils/otel.go Normalizes endpoints to include a scheme and updates OTLP exporter initialization to use URL-based endpoint options.
pkg/utils/otel_test.go Adds tests for endpointURL and a SetupOTelSDKWithConfig test case for bare IP:port endpoints.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


import (
"context"

Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The extra blank line inside the standard-library import block isn’t gofmt/goimports style and may cause formatting/lint churn. Consider running gofmt (or remove the empty line) so imports remain consistently formatted.

Suggested change

Copilot uses AI. Check for mistakes.
Comment on lines +297 to +304
t.Setenv("OTEL_EXPORTER_OTLP_ENDPOINT", "127.0.0.1:4317")

cfg := OTelConfig{
ServiceName: "test-service",
ServiceVersion: "1.0.0",
Protocol: OTelProtocolGRPC,
Endpoint: "127.0.0.1:4317",
Insecure: true,
Copy link

Copilot AI Feb 13, 2026

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.

Copilot uses AI. Check for mistakes.
Comment on lines +191 to +196
// 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)
}
Copy link

Copilot AI Feb 13, 2026

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.

Copilot uses AI. Check for mistakes.
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.
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The endpointURL doc comment claims the SDK reads OTEL_EXPORTER_OTLP_ENDPOINT and parses it, but in this codepath endpointURL is only used to prepare cfg.Endpoint for WithEndpointURL options. Consider rewording the comment to describe the actual call chain (or implement env var normalization if that’s the intent).

Suggested change
// 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 uses AI. Check for mistakes.
Comment on lines +291 to +298
func endpointURL(raw string, insecure bool) string {
if strings.Contains(raw, "://") {
return raw
}
if insecure {
return "http://" + raw
}
return "https://" + raw
Copy link

Copilot AI Feb 13, 2026

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.

Copilot uses AI. Check for mistakes.
@bramwelt bramwelt merged commit f46383f into main Feb 16, 2026
11 checks passed
@bramwelt bramwelt deleted the bramwelt/otel-endpoint-fix branch February 16, 2026 21:38
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.

3 participants