-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.go
54 lines (45 loc) · 1.24 KB
/
main.go
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// The purpose of this example is to show how to instrument the Axiom Go client
// using OpenTelemetry.
package main
import (
"context"
"fmt"
"log"
"os"
"github.com/axiomhq/axiom-go/axiom"
axiotel "github.com/axiomhq/axiom-go/axiom/otel"
)
func main() {
// Export "AXIOM_DATASET" in addition to the required environment variables.
ctx := context.Background()
dataset := os.Getenv("AXIOM_DATASET")
if dataset == "" {
log.Fatal("AXIOM_DATASET is required")
}
// 1. Initialize OpenTelemetry.
// Note: You can setup OpenTelemetry however you like! This example uses the
// helper package axiom/otel to initialize OpenTelemetry with Axiom
// configured as a backend for convenience.
stop, err := axiotel.InitTracing(ctx, dataset, "axiom-otel-example", "v1.0.0")
if err != nil {
log.Fatal(err)
}
defer func() {
if stopErr := stop(); stopErr != nil {
log.Fatal(stopErr)
}
}()
// 2. Initialize the Axiom API client.
client, err := axiom.NewClient()
if err != nil {
log.Fatal(err)
}
// 3. Use the client as usual ⚡
// This will send traces to the configured OpenTelemetry collector (in this
// case Axiom itself).
user, err := client.Users.Current(ctx)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Hello %s!\n", user.Name)
}