Skip to content

Commit

Permalink
Remake NewSpanLimits to be newEnvSpanLimits
Browse files Browse the repository at this point in the history
Update and unify documentation accordingly.
  • Loading branch information
MrAlias committed Feb 25, 2022
1 parent a780936 commit 3bd05d9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 87 deletions.
92 changes: 20 additions & 72 deletions sdk/trace/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ var _ trace.TracerProvider = &TracerProvider{}
// returned TracerProvider appropriately.
func NewTracerProvider(opts ...TracerProviderOption) *TracerProvider {
o := tracerProviderConfig{
spanLimits: newEnvSpanLimits(),
spanLimits: NewSpanLimits(),
}

for _, opt := range opts {
Expand Down Expand Up @@ -346,47 +346,21 @@ func WithSampler(s Sampler) TracerProviderOption {
})
}

// WithSpanLimits returns a TracerProviderOption that will configure the
// SpanLimits sl as a TracerProvider's SpanLimits. The configured SpanLimits
// are used used by the Tracers the TracerProvider and the Spans they create
// to limit tracing resources used.
// WithSpanLimits returns a TracerProviderOption that configures a
// TracerProvider to use the SpanLimits sl. These SpanLimits bound any Span
// created by a Tracer from the TracerProvider.
//
// If this or WithRawSpanLimits are not provided, the TracerProvider will use
// the value set for the corresponding environment variable:
//
// • AttributeValueLengthLimit: OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT
//
// • AttributeCountLimit: OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT
//
// • EventCountLimit: OTEL_SPAN_EVENT_COUNT_LIMIT
//
// • AttributePerEventCountLimit: OTEL_EVENT_ATTRIBUTE_COUNT_LIMIT
//
// • LinkCountLimit: OTEL_SPAN_LINK_COUNT_LIMIT
//
// • AttributePerLinkCountLimit: OTEL_LINK_ATTRIBUTE_COUNT_LIMIT
//
// If both options are not provided and no environment variable is set, the
// TracerProvider will use the default limit value:
//
// • AttributeValueLengthLimit: unlimited
//
// • AttributeCountLimit: 128
//
// • EventCountLimit: 128
//
// • AttributePerEventCountLimit: 128
//
// • LinkCountLimit: 128
//
// • AttributePerLinkCountLimit: 128
//
// If any filed of sl is zero or negative it will be replaced with the default
// If any field of sl is zero or negative it will be replaced with the default
// value for that field.
//
// Deprecated: Use WithRawSpanLimits instead. That option allows setting
// unlimited and zero limits, this option does not. This option will be kept
// until the next major version incremented release.
// If this or WithRawSpanLimits are not provided, the TracerProvider will use
// the limits defined by environment variables, or the defaults if unset.
// Refer to the NewSpanLimits documentation for information about this
// relationship.
//
// Deprecated: Use WithRawSpanLimits instead which allows setting unlimited
// and zero limits. This option will be kept until the next major version
// incremented release.
func WithSpanLimits(sl SpanLimits) TracerProviderOption {
if sl.AttributeValueLengthLimit <= 0 {
sl.AttributeValueLengthLimit = DefaultAttributeValueLengthLimit
Expand All @@ -412,39 +386,9 @@ func WithSpanLimits(sl SpanLimits) TracerProviderOption {
})
}

// WithRawSpanLimits returns a TracerProviderOption that will configure limits
// as a TracerProvider's SpanLimits. These limits bound any Span created by a
// Tracer from the TracerProvider.
//
// If this or WithSpanLimits are not provided, the TracerProvider will use the
// value set for the corresponding environment variable:
//
// • AttributeValueLengthLimit: OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT
//
// • AttributeCountLimit: OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT
//
// • EventCountLimit: OTEL_SPAN_EVENT_COUNT_LIMIT
//
// • AttributePerEventCountLimit: OTEL_EVENT_ATTRIBUTE_COUNT_LIMIT
//
// • LinkCountLimit: OTEL_SPAN_LINK_COUNT_LIMIT
//
// • AttributePerLinkCountLimit: OTEL_LINK_ATTRIBUTE_COUNT_LIMIT
//
// If both options are not provided and no environment variable is set, the
// TracerProvider will use the default limit value:
//
// • AttributeValueLengthLimit: unlimited
//
// • AttributeCountLimit: 128
//
// • EventCountLimit: 128
//
// • AttributePerEventCountLimit: 128
//
// • LinkCountLimit: 128
//
// • AttributePerLinkCountLimit: 128
// WithRawSpanLimits returns a TracerProviderOption that configures a
// TracerProvider to use these limits. These limits bound any Span created by
// a Tracer from the TracerProvider.
//
// The limits will be used as-is. Zero or negative values will not be changed
// to the default value like WithSpanLimits does. Setting a limit to zero will
Expand All @@ -453,6 +397,10 @@ func WithSpanLimits(sl SpanLimits) TracerProviderOption {
// means that the zero-value SpanLimits will disable all span resources.
// Because of this, limits should be constructed using NewSpanLimits and
// updated accordingly.
//
// If this or WithSpanLimits are not provided, the TracerProvider will use the
// limits defined by environment variables, or the defaults if unset. Refer to
// the NewSpanLimits documentation for information about this relationship.
func WithRawSpanLimits(limits SpanLimits) TracerProviderOption {
return traceProviderOptionFunc(func(cfg tracerProviderConfig) tracerProviderConfig {
cfg.spanLimits = limits
Expand Down
32 changes: 17 additions & 15 deletions sdk/trace/span_limits.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,22 +97,24 @@ type SpanLimits struct {
AttributePerLinkCountLimit int
}

// NewSpanLimits returns a SpanLimits with all limits set to defaults.
// NewSpanLimits returns a SpanLimits with all limits set to the value their
// corresponding environment variable holds, or the default if unset.
//
// • AttributeValueLengthLimit: OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT
// (default: unlimited)
//
// • AttributeCountLimit: OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT (default: 128)
//
// • EventCountLimit: OTEL_SPAN_EVENT_COUNT_LIMIT (default: 128)
//
// • AttributePerEventCountLimit: OTEL_EVENT_ATTRIBUTE_COUNT_LIMIT (default:
// 128)
//
// • LinkCountLimit: OTEL_SPAN_LINK_COUNT_LIMIT (default: 128)
//
// • AttributePerLinkCountLimit: OTEL_LINK_ATTRIBUTE_COUNT_LIMIT (default:
// 128)
func NewSpanLimits() SpanLimits {
return SpanLimits{
AttributeValueLengthLimit: DefaultAttributeValueLengthLimit,
AttributeCountLimit: DefaultAttributeCountLimit,
EventCountLimit: DefaultEventCountLimit,
LinkCountLimit: DefaultLinkCountLimit,
AttributePerEventCountLimit: DefaultAttributePerEventCountLimit,
AttributePerLinkCountLimit: DefaultAttributePerLinkCountLimit,
}
}

// newEnvSpanLimits returns a SpanLimits with all limits set to the value
// defined by their related environment variable, or default if the
// environment variable is not set.
func newEnvSpanLimits() SpanLimits {
return SpanLimits{
AttributeValueLengthLimit: env.SpanAttributeValueLength(DefaultAttributeValueLengthLimit),
AttributeCountLimit: env.SpanAttributeCount(DefaultAttributeCountLimit),
Expand Down

0 comments on commit 3bd05d9

Please sign in to comment.