package trace
import (
)
type TracerConfig struct {
instrumentationVersion string
schemaURL string
attrs attribute.Set
}
func ( *TracerConfig) () string {
return .instrumentationVersion
}
func ( *TracerConfig) () attribute.Set {
return .attrs
}
func ( *TracerConfig) () string {
return .schemaURL
}
type experimentalOption interface {
Experimental()
}
func ( ...TracerOption) TracerConfig {
var TracerConfig
for , := range {
if , := .(experimentalOption); {
continue
}
= .apply()
}
return
}
type TracerOption interface {
apply(TracerConfig) TracerConfig
}
type tracerOptionFunc func(TracerConfig) TracerConfig
func ( tracerOptionFunc) ( TracerConfig) TracerConfig {
return ()
}
type SpanConfig struct {
attributes []attribute.KeyValue
timestamp time.Time
links []Link
newRoot bool
spanKind SpanKind
stackTrace bool
}
func ( *SpanConfig) () []attribute.KeyValue {
return .attributes
}
func ( *SpanConfig) () time.Time {
return .timestamp
}
func ( *SpanConfig) () bool {
return .stackTrace
}
func ( *SpanConfig) () []Link {
return .links
}
func ( *SpanConfig) () bool {
return .newRoot
}
func ( *SpanConfig) () SpanKind {
return .spanKind
}
func ( ...SpanStartOption) SpanConfig {
var SpanConfig
for , := range {
if , := .(experimentalOption); {
continue
}
= .applySpanStart()
}
return
}
func ( ...SpanEndOption) SpanConfig {
var SpanConfig
for , := range {
if , := .(experimentalOption); {
continue
}
= .applySpanEnd()
}
return
}
type SpanStartOption interface {
applySpanStart(SpanConfig) SpanConfig
}
type spanOptionFunc func(SpanConfig) SpanConfig
func ( spanOptionFunc) ( SpanConfig) SpanConfig {
return ()
}
type SpanEndOption interface {
applySpanEnd(SpanConfig) SpanConfig
}
type EventConfig struct {
attributes []attribute.KeyValue
timestamp time.Time
stackTrace bool
}
func ( *EventConfig) () []attribute.KeyValue {
return .attributes
}
func ( *EventConfig) () time.Time {
return .timestamp
}
func ( *EventConfig) () bool {
return .stackTrace
}
func ( ...EventOption) EventConfig {
var EventConfig
for , := range {
if , := .(experimentalOption); {
continue
}
= .applyEvent()
}
if .timestamp.IsZero() {
.timestamp = time.Now()
}
return
}
type EventOption interface {
applyEvent(EventConfig) EventConfig
}
type SpanOption interface {
SpanStartOption
SpanEndOption
}
type SpanStartEventOption interface {
SpanStartOption
EventOption
}
type SpanEndEventOption interface {
SpanEndOption
EventOption
}
type attributeOption []attribute.KeyValue
func ( attributeOption) ( SpanConfig) SpanConfig {
.attributes = append(.attributes, []attribute.KeyValue()...)
return
}
func ( attributeOption) ( SpanConfig) SpanConfig { return .applySpan() }
func ( attributeOption) ( EventConfig) EventConfig {
.attributes = append(.attributes, []attribute.KeyValue()...)
return
}
var _ SpanStartEventOption = attributeOption{}
func ( ...attribute.KeyValue) SpanStartEventOption {
return attributeOption()
}
type SpanEventOption interface {
SpanOption
EventOption
}
type timestampOption time.Time
func ( timestampOption) ( SpanConfig) SpanConfig {
.timestamp = time.Time()
return
}
func ( timestampOption) ( SpanConfig) SpanConfig { return .applySpan() }
func ( timestampOption) ( SpanConfig) SpanConfig { return .applySpan() }
func ( timestampOption) ( EventConfig) EventConfig {
.timestamp = time.Time()
return
}
var _ SpanEventOption = timestampOption{}
func ( time.Time) SpanEventOption {
return timestampOption()
}
type stackTraceOption bool
func ( stackTraceOption) ( EventConfig) EventConfig {
.stackTrace = bool()
return
}
func ( stackTraceOption) ( SpanConfig) SpanConfig {
.stackTrace = bool()
return
}
func ( stackTraceOption) ( SpanConfig) SpanConfig { return .applySpan() }
func ( bool) SpanEndEventOption {
return stackTraceOption()
}
func ( ...Link) SpanStartOption {
return spanOptionFunc(func( SpanConfig) SpanConfig {
.links = append(.links, ...)
return
})
}
func () SpanStartOption {
return spanOptionFunc(func( SpanConfig) SpanConfig {
.newRoot = true
return
})
}
func ( SpanKind) SpanStartOption {
return spanOptionFunc(func( SpanConfig) SpanConfig {
.spanKind =
return
})
}
func ( string) TracerOption {
return tracerOptionFunc(func( TracerConfig) TracerConfig {
.instrumentationVersion =
return
})
}
func (, attribute.Set) attribute.Set {
:= attribute.NewMergeIterator(&, &)
:= make([]attribute.KeyValue, 0, .Len()+.Len())
for .Next() {
= append(, .Attribute())
}
return attribute.NewSet(...)
}
func ( ...attribute.KeyValue) TracerOption {
:= attribute.NewSet(slices.Clone()...)
return WithInstrumentationAttributeSet()
}
func ( attribute.Set) TracerOption {
if .Len() == 0 {
return tracerOptionFunc(func( TracerConfig) TracerConfig {
return
})
}
return tracerOptionFunc(func( TracerConfig) TracerConfig {
if .attrs.Len() == 0 {
.attrs =
} else {
.attrs = mergeSets(.attrs, )
}
return
})
}
func ( string) TracerOption {
return tracerOptionFunc(func( TracerConfig) TracerConfig {
.schemaURL =
return
})
}