Skip to content

Document how to use OTLP exporters with self-signed certificates #6661

Open
@xue20xi

Description

@xue20xi

Description

The goal is to use the OTLP Log gRPC Exporter in golang application to send application logs to the opentelemetry collector with TLS enabled on the server side.

Environment

  • OS: WSL(Ubuntu)
  • Architecture: x86_64
  • Go Version: go1.23.8
  • opentelemetry-go version: v1.35.0

Steps To Reproduce

  1. Export the CA certificate of the opentelemetry collector
    export OTEL_EXPORTER_OTLP_CERTIFICATE=xxx
  2. For the opentelemetry collector endpoint, using the default https://localhost:4317
  3. Follow the example in the README, add the last 5 lines to emit the log
package main

import (
	"context"

	"go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc"
	otellog "go.opentelemetry.io/otel/log"
	"go.opentelemetry.io/otel/log/global"
	"go.opentelemetry.io/otel/log/logtest"
	"go.opentelemetry.io/otel/sdk/log"
)

func main() {
	ctx := context.Background()
	exp, err := otlploggrpc.New(ctx)
	if err != nil {
		panic(err)
	}

	processor := log.NewBatchProcessor(exp)
	provider := log.NewLoggerProvider(log.WithProcessor(processor))
	defer func() {
		if err := provider.Shutdown(ctx); err != nil {
			panic(err)
		}
	}()

	global.SetLoggerProvider(provider)

	// From here, the provider can be used by instrumentation to collect
	// telemetry.
	mylogger := provider.Logger("mylogger")
	rf := logtest.RecordFactory{}
	rf.Body = otellog.StringValue("hello")
	r1 := rf.NewRecord()
	mylogger.Emit(ctx, r1)
}
  1. Below error popup
panic: context deadline exceeded: rpc error: code = Unavailable desc = connection error: desc = "transport: authentication handshake failed: tls: failed to verify certificate: x509: certificate signed by unknown authority"

goroutine 1 [running]:
  1. It seems the OTEL_EXPORTER_OTLP_CERTIFICATE variable is not working as described in the README.
OTEL_EXPORTER_OTLP_CERTIFICATE, OTEL_EXPORTER_OTLP_LOGS_CERTIFICATE (default: none) - the filepath to the trusted certificate to use when verifying a server's TLS credentials. 
  1. I have tried export the SSL_CERT_FILE variable to the same value as OTEL_EXPORTER_OTLP_CERTIFICATE and the same code works fine.

Expected behavior

Expect the OTLP Log gRPC Exporter can work when specify the environment variable OTEL_EXPORTER_OTLP_CERTIFICATE with no errors like specifying the SSL_CERT_FILE environment variable

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationProvides helpful informationenhancementNew feature or requestpkg:exporter:otlpRelated to the OTLP exporter package

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions