-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapm.go
More file actions
69 lines (54 loc) · 1.55 KB
/
apm.go
File metadata and controls
69 lines (54 loc) · 1.55 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package apm // import "go.stackify.com/apm"
import (
"context"
"fmt"
"time"
"go.stackify.com/apm/config"
"go.stackify.com/apm/trace"
"go.stackify.com/apm/transport"
"go.opentelemetry.io/otel/api/global"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
)
type StackifyAPM struct {
config *config.Config
transport *transport.Transport
spanExporter *trace.StackifySpanExporter
spanProcessor *trace.StackifySpanProcessor
traceProvider *sdktrace.TracerProvider
Tracer trace.Tracer
Context context.Context
}
func (sapm *StackifyAPM) Shutdown() {
time.Sleep(1 * time.Second)
sapm.spanProcessor.Shutdown()
}
func NewStackifyAPM(opts ...config.ConfigOptions) (*StackifyAPM, error) {
fmt.Println("APM Starting...")
// initialize Config
c := config.NewConfig(opts...)
// initialize Transport
t := transport.NewTransport(c)
// initialize stackify span exporter
sse := trace.NewStackifySpanExporter(c, &t)
// initialize stackify span processor
ssp := trace.NewStackifySpanProcessor(sse)
// initialize OT tracer provider
tp := sdktrace.NewTracerProvider(sdktrace.WithSpanProcessor(ssp))
// set tracer provider as global tracer provider
global.SetTracerProvider(tp)
tracer := global.Tracer("stackifyapm_tracer")
// create context
ctx := context.Background()
// initialize StackifyAPM
stackifyAPM := StackifyAPM{
config: c,
transport: &t,
spanExporter: sse,
spanProcessor: ssp,
traceProvider: tp,
Tracer: tracer,
Context: ctx,
}
fmt.Println("APM Started...")
return &stackifyAPM, nil
}