Install Uptrace client
You need to instrument your app to send data to Uptrace. Use the instructions below to install Uptrace client and send your first trace.
Install uptrace-go:
go get github.com/uptrace/uptrace-go
Run the following example (no additional configuration required):
package main

import (
	"context"
	"errors"
	"fmt"

	"go.opentelemetry.io/otel"
	"go.opentelemetry.io/otel/attribute"

	"github.com/uptrace/uptrace-go/uptrace"
)

func main() {
	ctx := context.Background()

	uptrace.ConfigureOpentelemetry(&uptrace.Config{
		DSN: "https://<token>@api.uptrace.dev/<project_id>",

		ServiceName:    "myservice",
		ServiceVersion: "1.0.0",
	})
	defer uptrace.Shutdown(ctx)

	tracer := otel.Tracer("app_or_package_name")
	ctx, span := tracer.Start(ctx, "main")

	_, child1 := tracer.Start(ctx, "child1")
	child1.SetAttributes(attribute.String("key1", "value1"))
	child1.RecordError(errors.New("error1"))
	child1.End()

	_, child2 := tracer.Start(ctx, "child2")
	child2.SetAttributes(attribute.Int("key2", 42), attribute.Float64("key3", 123.456))
	child2.End()

	span.End()
	fmt.Printf("trace: %s\n", uptrace.TraceURL(span))
}
View documentation
Got a question? Send us an email at support@uptrace.dev. We reply as soon as possible.
Already using OTLP?
Uptrace supports OpenTelemetry protocol (OTLP) in case you are already using OpenTelemetry or don't want to install Uptrace client.
To configure OpenTelemetry Collector, use the following config:
exporters:
  otlp:
    endpoint: otlp.uptrace.dev:4317
    headers: {"uptrace-dsn": "https://<token>@api.uptrace.dev/<project_id>"}
    compression: on
To configure OTLP exporter, use the examples below.
See full example at GitHub.
package main

import (
	"context"
	"errors"
	"fmt"
	"os"

	"go.opentelemetry.io/otel"
	"go.opentelemetry.io/otel/attribute"
	"go.opentelemetry.io/otel/exporters/otlp"
	"go.opentelemetry.io/otel/exporters/otlp/otlpgrpc"
	sdktrace "go.opentelemetry.io/otel/sdk/trace"
	"google.golang.org/grpc/credentials"
	_ "google.golang.org/grpc/encoding/gzip"
)

func main() {
	ctx := context.Background()

	// Create credentials using system certificates.
	creds := credentials.NewClientTLSFromCert(nil, "")
	driver := otlpgrpc.NewDriver(
		otlpgrpc.WithEndpoint("otlp.uptrace.dev:4317"),
		otlpgrpc.WithTLSCredentials(creds),
		otlpgrpc.WithHeaders(map[string]string{
			"uptrace-dsn": "https://<token>@api.uptrace.dev/<project_id>",
		}),
		otlpgrpc.WithCompressor("gzip"),
	)

	exporter, err := otlp.NewExporter(ctx, driver)
	if err != nil {
		panic(err)
	}

	bsp := sdktrace.NewBatchSpanProcessor(exporter,
		sdktrace.WithMaxQueueSize(1000),
		sdktrace.WithMaxExportBatchSize(1000))
	// Call shutdown to flush the buffers when program exits.
	defer bsp.Shutdown(ctx)

	tracerProvider := sdktrace.NewTracerProvider()
	tracerProvider.RegisterSpanProcessor(bsp)

	// Install our tracer provider and we are done.
	otel.SetTracerProvider(tracerProvider)

	tracer := otel.Tracer("app_or_package_name")
	ctx, span := tracer.Start(ctx, "main")
	defer span.End()

	_, child1 := tracer.Start(ctx, "child1")
	child1.SetAttributes(attribute.String("key1", "value1"))
	child1.RecordError(errors.New("error1"))
	child1.End()

	_, child2 := tracer.Start(ctx, "child2")
	child2.SetAttributes(attribute.Int("key2", 42), attribute.Float64("key3", 123.456))
	child2.End()

	fmt.Println("trace id:", span.SpanContext().TraceID())
}
View documentation