uptracehelper/add Setup; rename InitTracer -> GoStop;

develop
Ge Song 2 years ago
parent f032b6fbb3
commit d12ff23ff9

@ -2,8 +2,9 @@ package exegroup_test
import ( import (
"context" "context"
"git.blauwelle.com/go/crate/exegroup"
"log" "log"
"git.blauwelle.com/go/crate/exegroup"
) )
func Example_defaultGroup() { func Example_defaultGroup() {

@ -2,6 +2,7 @@ package uptracehelper
import ( import (
"context" "context"
"github.com/uptrace/uptrace-go/uptrace" "github.com/uptrace/uptrace-go/uptrace"
) )
@ -11,12 +12,7 @@ type Config struct {
DeploymentEnvironment string DeploymentEnvironment string
} }
// InitTracer 初始化并等待 uptrace func Setup(cfg Config) {
// 配合 [git.blauwelle.com/go/crate/exegroup] 使用
// env
// - UPTRACE_DISABLED 存在就不再初始化
// - UPTRACE_DSN 服务端地址
func InitTracer(cfg Config) (func(ctx context.Context) error, func(ctx context.Context)) {
opts := []uptrace.Option{ opts := []uptrace.Option{
uptrace.WithServiceName(cfg.ServiceName), uptrace.WithServiceName(cfg.ServiceName),
uptrace.WithServiceVersion(cfg.ServiceVersion), uptrace.WithServiceVersion(cfg.ServiceVersion),
@ -25,7 +21,16 @@ func InitTracer(cfg Config) (func(ctx context.Context) error, func(ctx context.C
opts = append(opts, uptrace.WithDeploymentEnvironment(cfg.DeploymentEnvironment)) opts = append(opts, uptrace.WithDeploymentEnvironment(cfg.DeploymentEnvironment))
} }
uptrace.ConfigureOpentelemetry(opts...) uptrace.ConfigureOpentelemetry(opts...)
shutdownErr := make(chan error) }
// 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 { goFunc := func(context.Context) error {
return <-shutdownErr return <-shutdownErr
} }

Loading…
Cancel
Save