Skip to content

Using Uptrace with OpenTelemetry Collector

Introduction

Installing OpenTelemetry Collector

Configuring OTLP exporter

Now you need to configure your service to export data to the Otel Collector. By default Otel Collector is running on ports 4317 (gRPC) and 55681 (HTTP). So you need to configure OTLP exporter using the correct IP address and port:

import (
    "go.opentelemetry.io/otel"
    sdktrace "go.opentelemetry.io/otel/sdk/trace"
    "go.opentelemetry.io/otel/exporters/otlp"
    "go.opentelemetry.io/otel/exporters/otlp/otlpgrpc"
)

func installOTLP(ctx context.Context) error {
    driver := otlpgrpc.NewDriver(
        otlpgrpc.WithInsecure(),
        // otlpgrpc.WithAddress("localhost:4317"),
    )
    exporter, err := otlp.NewExporter(ctx,
        otlp.NewSplitDriver(otlp.SplitConfig{
            ForMetrics: driver,
            ForTraces:  driver,
        }),
    )
    if err != nil {
        return err
    }

    tracerProvider := sdktrace.NewTracerProvider(sdktrace.WithBatcher(exporter))
    otel.SetTracerProvider(tracerProvider)

    return nil
}

When everything is configured properly you should see the following logs in Otel Collector:

otel-collector_1  | 2021-01-15T08:33:22.571Z    INFO    loggingexporter/logging_exporter.go:313 TracesExporter  {"#spans": 1}
otel-collector_1  | 2021-01-15T08:33:24.791Z    INFO    loggingexporter/logging_exporter.go:313 TracesExporter  {"#spans": 232}