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:
- Check out
main at 524fc3c25.
- 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.
Description:
Setting
OTEL_EXPORTER_OTLP_METRICS_ENDPOINTto 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,withEndpointForGRPCinexporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/envconfig.gosets:So an endpoint like
http://127.0.0.1:1/v1/metricsbecomes the gRPC dial target127.0.0.1:1/v1/metrics.This looks like the metrics-side sibling of #7831.
Environment:
mainat524fc3c25.Steps To Reproduce:
mainat524fc3c25.Actual behavior:
The exporter tries to dial a target that still contains the path:
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/metricsshould not produce a target like127.0.0.1:1/v1/metrics. The exporter should either:127.0.0.1:1as the gRPC endpoint target.Notes:
This appears to be the same root problem as #7831, but in
otlpmetricgrpcinstead ofotlptracegrpc.