Source File
config.go
Belonging Package
go.opentelemetry.io/otel/trace
// Copyright The OpenTelemetry Authors//// Licensed under the Apache License, Version 2.0 (the "License");// you may not use this file except in compliance with the License.// You may obtain a copy of the License at//// http://www.apache.org/licenses/LICENSE-2.0//// Unless required by applicable law or agreed to in writing, software// distributed under the License is distributed on an "AS IS" BASIS,// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.// See the License for the specific language governing permissions and// limitations under the License.package trace // import "go.opentelemetry.io/otel/trace"import ()// TracerConfig is a group of options for a Tracer.type TracerConfig struct {instrumentationVersion string// Schema URL of the telemetry emitted by the Tracer.schemaURL stringattrs attribute.Set}// InstrumentationVersion returns the version of the library providing instrumentation.func ( *TracerConfig) () string {return .instrumentationVersion}// InstrumentationAttributes returns the attributes associated with the library// providing instrumentation.func ( *TracerConfig) () attribute.Set {return .attrs}// SchemaURL returns the Schema URL of the telemetry emitted by the Tracer.func ( *TracerConfig) () string {return .schemaURL}// NewTracerConfig applies all the options to a returned TracerConfig.func ( ...TracerOption) TracerConfig {var TracerConfigfor , := range {= .apply()}return}// TracerOption applies an option to a TracerConfig.type TracerOption interface {apply(TracerConfig) TracerConfig}type tracerOptionFunc func(TracerConfig) TracerConfigfunc ( tracerOptionFunc) ( TracerConfig) TracerConfig {return ()}// SpanConfig is a group of options for a Span.type SpanConfig struct {attributes []attribute.KeyValuetimestamp time.Timelinks []LinknewRoot boolspanKind SpanKindstackTrace bool}// Attributes describe the associated qualities of a Span.func ( *SpanConfig) () []attribute.KeyValue {return .attributes}// Timestamp is a time in a Span life-cycle.func ( *SpanConfig) () time.Time {return .timestamp}// StackTrace checks whether stack trace capturing is enabled.func ( *SpanConfig) () bool {return .stackTrace}// Links are the associations a Span has with other Spans.func ( *SpanConfig) () []Link {return .links}// NewRoot identifies a Span as the root Span for a new trace. This is// commonly used when an existing trace crosses trust boundaries and the// remote parent span context should be ignored for security.func ( *SpanConfig) () bool {return .newRoot}// SpanKind is the role a Span has in a trace.func ( *SpanConfig) () SpanKind {return .spanKind}// NewSpanStartConfig applies all the options to a returned SpanConfig.// No validation is performed on the returned SpanConfig (e.g. no uniqueness// checking or bounding of data), it is left to the SDK to perform this// action.func ( ...SpanStartOption) SpanConfig {var SpanConfigfor , := range {= .applySpanStart()}return}// NewSpanEndConfig applies all the options to a returned SpanConfig.// No validation is performed on the returned SpanConfig (e.g. no uniqueness// checking or bounding of data), it is left to the SDK to perform this// action.func ( ...SpanEndOption) SpanConfig {var SpanConfigfor , := range {= .applySpanEnd()}return}// SpanStartOption applies an option to a SpanConfig. These options are applicable// only when the span is created.type SpanStartOption interface {applySpanStart(SpanConfig) SpanConfig}type spanOptionFunc func(SpanConfig) SpanConfigfunc ( spanOptionFunc) ( SpanConfig) SpanConfig {return ()}// SpanEndOption applies an option to a SpanConfig. These options are// applicable only when the span is ended.type SpanEndOption interface {applySpanEnd(SpanConfig) SpanConfig}// EventConfig is a group of options for an Event.type EventConfig struct {attributes []attribute.KeyValuetimestamp time.TimestackTrace bool}// Attributes describe the associated qualities of an Event.func ( *EventConfig) () []attribute.KeyValue {return .attributes}// Timestamp is a time in an Event life-cycle.func ( *EventConfig) () time.Time {return .timestamp}// StackTrace checks whether stack trace capturing is enabled.func ( *EventConfig) () bool {return .stackTrace}// NewEventConfig applies all the EventOptions to a returned EventConfig. If no// timestamp option is passed, the returned EventConfig will have a Timestamp// set to the call time, otherwise no validation is performed on the returned// EventConfig.func ( ...EventOption) EventConfig {var EventConfigfor , := range {= .applyEvent()}if .timestamp.IsZero() {.timestamp = time.Now()}return}// EventOption applies span event options to an EventConfig.type EventOption interface {applyEvent(EventConfig) EventConfig}// SpanOption are options that can be used at both the beginning and end of a span.type SpanOption interface {SpanStartOptionSpanEndOption}// SpanStartEventOption are options that can be used at the start of a span, or with an event.type SpanStartEventOption interface {SpanStartOptionEventOption}// SpanEndEventOption are options that can be used at the end of a span, or with an event.type SpanEndEventOption interface {SpanEndOptionEventOption}type attributeOption []attribute.KeyValuefunc ( 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{}// WithAttributes adds the attributes related to a span life-cycle event.// These attributes are used to describe the work a Span represents when this// option is provided to a Span's start or end events. Otherwise, these// attributes provide additional information about the event being recorded// (e.g. error, state change, processing progress, system event).//// If multiple of these options are passed the attributes of each successive// option will extend the attributes instead of overwriting. There is no// guarantee of uniqueness in the resulting attributes.func ( ...attribute.KeyValue) SpanStartEventOption {return attributeOption()}// SpanEventOption are options that can be used with an event or a span.type SpanEventOption interface {SpanOptionEventOption}type timestampOption time.Timefunc ( 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{}// WithTimestamp sets the time of a Span or Event life-cycle moment (e.g.// started, stopped, errored).func ( time.Time) SpanEventOption {return timestampOption()}type stackTraceOption boolfunc ( stackTraceOption) ( EventConfig) EventConfig {.stackTrace = bool()return}func ( stackTraceOption) ( SpanConfig) SpanConfig {.stackTrace = bool()return}func ( stackTraceOption) ( SpanConfig) SpanConfig { return .applySpan() }// WithStackTrace sets the flag to capture the error with stack trace (e.g. true, false).func ( bool) SpanEndEventOption {return stackTraceOption()}// WithLinks adds links to a Span. The links are added to the existing Span// links, i.e. this does not overwrite. Links with invalid span context are ignored.func ( ...Link) SpanStartOption {return spanOptionFunc(func( SpanConfig) SpanConfig {.links = append(.links, ...)return})}// WithNewRoot specifies that the Span should be treated as a root Span. Any// existing parent span context will be ignored when defining the Span's trace// identifiers.func () SpanStartOption {return spanOptionFunc(func( SpanConfig) SpanConfig {.newRoot = truereturn})}// WithSpanKind sets the SpanKind of a Span.func ( SpanKind) SpanStartOption {return spanOptionFunc(func( SpanConfig) SpanConfig {.spanKind =return})}// WithInstrumentationVersion sets the instrumentation version.func ( string) TracerOption {return tracerOptionFunc(func( TracerConfig) TracerConfig {.instrumentationVersion =return})}// WithInstrumentationAttributes sets the instrumentation attributes.//// The passed attributes will be de-duplicated.func ( ...attribute.KeyValue) TracerOption {return tracerOptionFunc(func( TracerConfig) TracerConfig {.attrs = attribute.NewSet(...)return})}// WithSchemaURL sets the schema URL for the Tracer.func ( string) TracerOption {return tracerOptionFunc(func( TracerConfig) TracerConfig {.schemaURL =return})}
![]() |
The pages are generated with Golds v0.6.7. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |