Skip to content

otlpmetricgrpc: error setting OTEL_EXPORTER_OTLP_METRICS_ENDPOINT with a path #8861

Description

@RedZapdos123

Description:

Setting OTEL_EXPORTER_OTLP_METRICS_ENDPOINT to a URL with a path causes the OTLP metrics gRPC exporter to build an invalid gRPC target by joining the host and path.

On current main, withEndpointForGRPC in exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/envconfig.go sets:

cfg.Metrics.Endpoint = path.Join(u.Host, u.Path)

So an endpoint like http://127.0.0.1:1/v1/metrics becomes the gRPC dial target 127.0.0.1:1/v1/metrics.

This looks like the metrics-side sibling of #7831.

Environment:

  • OS: Linux 6.6.87.2-microsoft-standard-WSL2.
  • Architecture: x86_64.
  • Go Version: go1.26.4 linux/amd64.
  • opentelemetry-go version: main at 524fc3c25.

Steps To Reproduce:

  1. Check out main at 524fc3c25.
  2. From the repository root, run.
cd exporters/otlp/otlpmetric/otlpmetricgrpc
mkdir -p tmprepro
cat > tmprepro/main.go <<'EOF'
package main

import (
	"context"
	"errors"
	"fmt"
	"net"
	"time"

	otlpmetricgrpc "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc"
	sdkmetric "go.opentelemetry.io/otel/sdk/metric"
	"google.golang.org/grpc"
)

func main() {
	ctx := context.Background()
	exp, err := otlpmetricgrpc.New(
		ctx,
		otlpmetricgrpc.WithRetry(otlpmetricgrpc.RetryConfig{Enabled: false}),
		otlpmetricgrpc.WithDialOption(grpc.WithContextDialer(func(ctx context.Context, target string) (net.Conn, error) {
			return nil, errors.New(target)
		})),
	)
	if err != nil {
		panic(err)
	}

	mp := sdkmetric.NewMeterProvider(
		sdkmetric.WithReader(sdkmetric.NewPeriodicReader(exp, sdkmetric.WithInterval(time.Hour))),
	)

	c, err := mp.Meter("repro").Int64Counter("c")
	if err != nil {
		panic(err)
	}
	c.Add(ctx, 1)

	err = mp.ForceFlush(context.Background())
	fmt.Println(err)
}
EOF

OTEL_EXPORTER_OTLP_METRICS_ENDPOINT=http://127.0.0.1:1/v1/metrics go run ./tmprepro
rm -rf tmprepro

Actual behavior:

The exporter tries to dial a target that still contains the path:

failed to upload metrics: rpc error: code = Unavailable desc = connection error: desc = "transport: Error while dialing: 127.0.0.1:1/v1/metrics"

Expected behavior:

The gRPC dial target should not include the URL path.

At minimum, OTEL_EXPORTER_OTLP_METRICS_ENDPOINT=http://127.0.0.1:1/v1/metrics should not produce a target like 127.0.0.1:1/v1/metrics. The exporter should either:

  • use only 127.0.0.1:1 as the gRPC endpoint target.
  • reject endpoint URLs with a path clearly during configuration.

Notes:

This appears to be the same root problem as #7831, but in otlpmetricgrpc instead of otlptracegrpc.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions