feat: add option for exporting traces to a provided Honeycomb team (#4816)

This commit is contained in:
Colin Adler
2022-11-01 09:15:41 -05:00
committed by GitHub
parent 21e64943ac
commit 4c5bf42355
7 changed files with 67 additions and 9 deletions

View File

@ -13,6 +13,7 @@ import (
sdktrace "go.opentelemetry.io/otel/sdk/trace"
semconv "go.opentelemetry.io/otel/semconv/v1.11.0"
"golang.org/x/xerrors"
"google.golang.org/grpc/credentials"
)
// TracerOpts specifies which telemetry exporters should be configured.
@ -23,6 +24,8 @@ type TracerOpts struct {
// Coder exports traces to Coder's public tracing ingest service and is used
// to improve the product. It is disabled when opting out of telemetry.
Coder bool
// Exports traces to Honeycomb.io with the provided API key.
Honeycomb string
}
// TracerProvider creates a grpc otlp exporter and configures a trace provider.
@ -57,6 +60,14 @@ func TracerProvider(ctx context.Context, service string, opts TracerOpts) (*sdkt
closers = append(closers, exporter.Shutdown)
tracerOpts = append(tracerOpts, sdktrace.WithBatcher(exporter))
}
if opts.Honeycomb != "" {
exporter, err := HoneycombExporter(ctx, opts.Honeycomb)
if err != nil {
return nil, nil, xerrors.Errorf("honeycomb exporter: %w", err)
}
closers = append(closers, exporter.Shutdown)
tracerOpts = append(tracerOpts, sdktrace.WithBatcher(exporter))
}
tracerProvider := sdktrace.NewTracerProvider(tracerOpts...)
otel.SetTracerProvider(tracerProvider)
@ -101,3 +112,20 @@ func CoderExporter(ctx context.Context) (*otlptrace.Exporter, error) {
return exporter, nil
}
func HoneycombExporter(ctx context.Context, apiKey string) (*otlptrace.Exporter, error) {
opts := []otlptracegrpc.Option{
otlptracegrpc.WithEndpoint("api.honeycomb.io:443"),
otlptracegrpc.WithHeaders(map[string]string{
"x-honeycomb-team": apiKey,
}),
otlptracegrpc.WithTLSCredentials(credentials.NewClientTLSFromCert(nil, "")),
}
exporter, err := otlptrace.New(ctx, otlptracegrpc.NewClient(opts...))
if err != nil {
return nil, xerrors.Errorf("create otlp exporter: %w", err)
}
return exporter, nil
}