mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-23 14:57:46 +00:00
blub
This commit is contained in:
@@ -5,3 +5,7 @@ import "log/slog"
|
||||
type Logger struct {
|
||||
*slog.Logger
|
||||
}
|
||||
|
||||
func (l *Logger) With(args ...any) *Logger {
|
||||
return &Logger{l.Logger.With(args...)}
|
||||
}
|
||||
|
@@ -14,51 +14,65 @@ func NewTracer(name string) Tracer {
|
||||
return Tracer{otel.Tracer(name)}
|
||||
}
|
||||
|
||||
type DecorateOption func(*decorateOptions)
|
||||
type DecorateOption func(*DecorateOptions)
|
||||
|
||||
type decorateOptions struct {
|
||||
type DecorateOptions struct {
|
||||
startOpts []trace.SpanStartOption
|
||||
endOpts []trace.SpanEndOption
|
||||
|
||||
spanName string
|
||||
|
||||
span trace.Span
|
||||
}
|
||||
|
||||
func WithSpanName(name string) DecorateOption {
|
||||
return func(o *decorateOptions) {
|
||||
return func(o *DecorateOptions) {
|
||||
o.spanName = name
|
||||
}
|
||||
}
|
||||
|
||||
func WithSpanStartOptions(opts ...trace.SpanStartOption) DecorateOption {
|
||||
return func(o *decorateOptions) {
|
||||
return func(o *DecorateOptions) {
|
||||
o.startOpts = append(o.startOpts, opts...)
|
||||
}
|
||||
}
|
||||
|
||||
func WithSpanEndOptions(opts ...trace.SpanEndOption) DecorateOption {
|
||||
return func(o *decorateOptions) {
|
||||
return func(o *DecorateOptions) {
|
||||
o.endOpts = append(o.endOpts, opts...)
|
||||
}
|
||||
}
|
||||
|
||||
func (t Tracer) Decorate(ctx context.Context, fn func(ctx context.Context) error, opts ...DecorateOption) {
|
||||
o := new(decorateOptions)
|
||||
for _, opt := range opts {
|
||||
opt(o)
|
||||
}
|
||||
|
||||
func (o *DecorateOptions) Start(ctx context.Context, tracer *Tracer) context.Context {
|
||||
if o.spanName == "" {
|
||||
o.spanName = functionName()
|
||||
}
|
||||
|
||||
_, span := t.Tracer.Start(ctx, o.spanName, o.startOpts...)
|
||||
defer span.End(o.endOpts...)
|
||||
|
||||
if err := fn(ctx); err != nil {
|
||||
span.RecordError(err)
|
||||
}
|
||||
ctx, o.span = tracer.Tracer.Start(ctx, o.spanName, o.startOpts...)
|
||||
return ctx
|
||||
}
|
||||
|
||||
func (o *DecorateOptions) End(err error) {
|
||||
o.span.RecordError(err)
|
||||
o.span.End(o.endOpts...)
|
||||
}
|
||||
|
||||
// func (t Tracer) Decorate(ctx context.Context, fn func(ctx context.Context) error, opts ...DecorateOption) {
|
||||
// o := new(DecorateOptions)
|
||||
// for _, opt := range opts {
|
||||
// opt(o)
|
||||
// }
|
||||
|
||||
// if o.spanName == "" {
|
||||
// o.spanName = functionName()
|
||||
// }
|
||||
|
||||
// ctx, span := t.Tracer.Start(ctx, o.spanName, o.startOpts...)
|
||||
// defer span.End(o.endOpts...)
|
||||
|
||||
// err := fn(ctx)
|
||||
// span.RecordError(err)
|
||||
// }
|
||||
|
||||
func functionName() string {
|
||||
counter, _, _, success := runtime.Caller(2)
|
||||
|
||||
|
Reference in New Issue
Block a user