# Getting started with OpenTelemetry

  • Step 1. Createopen in new window an Uptrace project to obtain a DSN, for example, https://<token>@api.uptrace.dev/<project_id>.

DSN

  • Step 2. Install uptrace-go:
go get github.com/uptrace/uptrace-go
1
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: "<dsn>",

		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))
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
  • Step 4. Run the example to get a link for the generated trace:
go run main.go
trace: https://uptrace.dev/search/<project_id>?q=<trace_id>
1
2

By now, you should have a fully configured OpenTelemetry distribution. Next, learn about the basics of OpenTelemetry API or check available instrumentationsopen in new window.