Skip to content

Commit 00a63af

Browse files
committed
Update the cli to manage own handler
1 parent 137bbea commit 00a63af

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

cli/main.go

+26
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ import (
1414
"path/filepath"
1515
"syscall"
1616

17+
semconv "go.opentelemetry.io/otel/semconv/v1.26.0"
18+
1719
"go.opentelemetry.io/auto"
20+
"go.opentelemetry.io/auto/export/otelsdk"
1821
"go.opentelemetry.io/auto/internal/pkg/process"
1922
)
2023

@@ -106,9 +109,22 @@ func main() {
106109
"version", newVersion(),
107110
)
108111

112+
v := semconv.TelemetryDistroVersionKey.String(auto.Version())
113+
h, err := otelsdk.New(
114+
ctx,
115+
otelsdk.WithEnv(),
116+
otelsdk.WithLogger(logger),
117+
otelsdk.WithResourceAttributes(v),
118+
)
119+
if err != nil {
120+
logger.Error("failed to create OTel SDK handler", "error", err)
121+
return
122+
}
123+
109124
instOptions := []auto.InstrumentationOption{
110125
auto.WithEnv(),
111126
auto.WithLogger(logger),
127+
auto.WithHandler(h),
112128
}
113129
if globalImpl {
114130
instOptions = append(instOptions, auto.WithGlobal())
@@ -131,4 +147,14 @@ func main() {
131147
if err = inst.Run(ctx); err != nil && !errors.Is(err, process.ErrInterrupted) {
132148
logger.Error("instrumentation crashed", "error", err)
133149
}
150+
151+
logger.Info("shutting down")
152+
153+
ctx, cancel = signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
154+
defer cancel()
155+
156+
err = h.Shutdown(ctx)
157+
if err != nil {
158+
logger.Error("failed to flush handler", "error", err)
159+
}
134160
}

0 commit comments

Comments
 (0)