mirror of
https://github.com/hanzoui/registry-backend.git
synced 2026-10-30 20:30:45 +00:00
25 lines
545 B
Go
25 lines
545 B
Go
package tracing
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/newrelic/go-agent/v3/newrelic"
|
|
)
|
|
|
|
func TraceDefaultSegment(ctx context.Context, segmentName string) func() {
|
|
_, f := TraceSegment(ctx, segmentName)
|
|
return f
|
|
}
|
|
|
|
func TraceSegment(ctx context.Context, segmentName string, opts ...func(*newrelic.Transaction)) (*newrelic.Transaction, func()) {
|
|
txn := newrelic.FromContext(ctx)
|
|
if txn == nil {
|
|
return nil, func() {}
|
|
}
|
|
for _, opt := range opts {
|
|
opt(txn)
|
|
}
|
|
segment := txn.StartSegment(segmentName)
|
|
return txn, func() { segment.End() }
|
|
}
|