You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1015 B
Go
42 lines
1015 B
Go
package uptracehelper
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/uptrace/uptrace-go/uptrace"
|
|
)
|
|
|
|
type Config struct {
|
|
ServiceName string
|
|
ServiceVersion string
|
|
DeploymentEnvironment string
|
|
}
|
|
|
|
func Setup(cfg Config) {
|
|
opts := []uptrace.Option{
|
|
uptrace.WithServiceName(cfg.ServiceName),
|
|
uptrace.WithServiceVersion(cfg.ServiceVersion),
|
|
}
|
|
if cfg.DeploymentEnvironment != "" {
|
|
opts = append(opts, uptrace.WithDeploymentEnvironment(cfg.DeploymentEnvironment))
|
|
}
|
|
uptrace.ConfigureOpentelemetry(opts...)
|
|
}
|
|
|
|
// GoStop 初始化并等待 uptrace
|
|
// 配合 [git.blauwelle.com/go/crate/exegroup] 使用
|
|
// env
|
|
// - UPTRACE_DISABLED 存在就不再初始化
|
|
// - UPTRACE_DSN 服务端地址
|
|
func GoStop(cfg Config) (func(ctx context.Context) error, func(ctx context.Context)) {
|
|
Setup(cfg)
|
|
shutdownErr := make(chan error, 1)
|
|
goFunc := func(context.Context) error {
|
|
return <-shutdownErr
|
|
}
|
|
stopFunc := func(ctx context.Context) {
|
|
shutdownErr <- uptrace.Shutdown(ctx)
|
|
}
|
|
return goFunc, stopFunc
|
|
}
|