get.porter.sh/porter@v1.3.0/pkg/tracing/tracer.go (about) 1 package tracing 2 3 import ( 4 "context" 5 6 "go.opentelemetry.io/otel/trace" 7 ) 8 9 type TracerCleanup func(ctx context.Context) error 10 11 // Tracer wraps an open telemetry tracer connection in Porter 12 // so that its cleanup function can be moved around with it. 13 type Tracer struct { 14 trace.Tracer 15 16 // IsNoOp indicates that this tracer is a no-op, it doesn't do anything 17 IsNoOp bool 18 cleanup TracerCleanup 19 } 20 21 // NewTracer wraps an open telemetry tracer and its cleanup function. 22 func NewTracer(t trace.Tracer, cleanup TracerCleanup) Tracer { 23 return Tracer{ 24 Tracer: t, 25 cleanup: cleanup, 26 } 27 } 28 29 // Close the tracer, releasing resources and sending the data to the collector. 30 func (t Tracer) Close(ctx context.Context) error { 31 if t.cleanup != nil { 32 return t.cleanup(ctx) 33 } 34 return nil 35 }