envoyproxy / envoyproxy/gateway

Unable to configure TLS for OTEL grpc exporter in code

Open
#4,629 2 comments 0 reactions 0 assignees View on GitHub
stale triage
Dominant language
Go
Stars
3k
Forks
864
Avg merge
2d 2h
Merged PRs (30d)
140

Description

*Description*:
I'm trying to set up OTEL grpc exporter for my application to push metrics to a gprc endpoint, which requires mTLS secure connection. I want to use `otlpmetricgrpc.WithTLSCredentials()` in [code](https://github.com/envoyproxy/gateway/blob/main/internal/metrics/register.go#L215-L219) to configure TLS certs instead of passing the ENV variable `OTEL_EXPORTER_OTLP_CERTIFICATE` , because it's easier to inject my server's CA cert in code. (This change is made to a local forked version of the gateway).

However it doesn't work. Keep getting the error
```
2024-11-01T23:30:47.853Z INFO provider channelz/logging.go:55 [core] [Channel #1 SubChannel #4]grpc: addrConn.createTransport failed to connect to {Addr: "xx.xx.xxx.xxxx:24184", ServerName: "xxx-ingestion-gateway.telemetry.g.xxx.com:24184", }.
Err: connection error: desc = "error reading server preface: remote error: tls: certificate required" {"runner": "provider"}
```
seems like the exporter is not picking up the tls credentials. I've verified the cert files using ENV variable route so those aren't the problem

*Repro steps*:
Code change in [this function](https://github.com/envoyproxy/gateway/blob/main/internal/metrics/register.go#L211)
```
func registerOTELgRPCexporter(otelOpts *[]metric.Option, opts registerOptions) error {
...
tlsConfig, err := crypto.TLSConfigWithCustomCA()
if err != nil {
metricsLogger.Error(err, "failed to create tls config")
}
httpexporter, err := otlpmetricgrpc.New(
context.Background(),
otlpmetricgrpc.WithEndpoint(address),
otlpmetricgrpc.WithTLSCredentials(credentials.NewTLS(tlsConfig)),
)
...
}
```

*Environment*:
latest gateway. Running in Kubernetes.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.