| 1 |
// Copyright The OpenTelemetry Authors |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
package trace // import "go.opentelemetry.io/otel/sdk/trace" |
| 5 |
|
| 6 |
import "go.opentelemetry.io/otel/sdk/trace/internal/env" |
| 7 |
|
| 8 |
const ( |
| 9 |
// DefaultAttributeValueLengthLimit is the default maximum allowed |
| 10 |
// attribute value length, unlimited. |
| 11 |
DefaultAttributeValueLengthLimit = -1 |
| 12 |
|
| 13 |
// DefaultAttributeCountLimit is the default maximum number of attributes |
| 14 |
// a span can have. |
| 15 |
DefaultAttributeCountLimit = 128 |
| 16 |
|
| 17 |
// DefaultEventCountLimit is the default maximum number of events a span |
| 18 |
// can have. |
| 19 |
DefaultEventCountLimit = 128 |
| 20 |
|
| 21 |
// DefaultLinkCountLimit is the default maximum number of links a span can |
| 22 |
// have. |
| 23 |
DefaultLinkCountLimit = 128 |
| 24 |
|
| 25 |
// DefaultAttributePerEventCountLimit is the default maximum number of |
| 26 |
// attributes a span event can have. |
| 27 |
DefaultAttributePerEventCountLimit = 128 |
| 28 |
|
| 29 |
// DefaultAttributePerLinkCountLimit is the default maximum number of |
| 30 |
// attributes a span link can have. |
| 31 |
DefaultAttributePerLinkCountLimit = 128 |
| 32 |
) |
| 33 |
|
| 34 |
// SpanLimits represents the limits of a span. |
| 35 |
type SpanLimits struct { |
| 36 |
// AttributeValueLengthLimit is the maximum allowed attribute value length. |
| 37 |
// |
| 38 |
// This limit only applies to string and string slice attribute values. |
| 39 |
// Any string longer than this value will be truncated to this length. |
| 40 |
// |
| 41 |
// Setting this to a negative value means no limit is applied. |
| 42 |
AttributeValueLengthLimit int |
| 43 |
|
| 44 |
// AttributeCountLimit is the maximum allowed span attribute count. Any |
| 45 |
// attribute added to a span once this limit is reached will be dropped. |
| 46 |
// |
| 47 |
// Setting this to zero means no attributes will be recorded. |
| 48 |
// |
| 49 |
// Setting this to a negative value means no limit is applied. |
| 50 |
AttributeCountLimit int |
| 51 |
|
| 52 |
// EventCountLimit is the maximum allowed span event count. Any event |
| 53 |
// added to a span once this limit is reached means it will be added but |
| 54 |
// the oldest event will be dropped. |
| 55 |
// |
| 56 |
// Setting this to zero means no events we be recorded. |
| 57 |
// |
| 58 |
// Setting this to a negative value means no limit is applied. |
| 59 |
EventCountLimit int |
| 60 |
|
| 61 |
// LinkCountLimit is the maximum allowed span link count. Any link added |
| 62 |
// to a span once this limit is reached means it will be added but the |
| 63 |
// oldest link will be dropped. |
| 64 |
// |
| 65 |
// Setting this to zero means no links we be recorded. |
| 66 |
// |
| 67 |
// Setting this to a negative value means no limit is applied. |
| 68 |
LinkCountLimit int |
| 69 |
|
| 70 |
// AttributePerEventCountLimit is the maximum number of attributes allowed |
| 71 |
// per span event. Any attribute added after this limit reached will be |
| 72 |
// dropped. |
| 73 |
// |
| 74 |
// Setting this to zero means no attributes will be recorded for events. |
| 75 |
// |
| 76 |
// Setting this to a negative value means no limit is applied. |
| 77 |
AttributePerEventCountLimit int |
| 78 |
|
| 79 |
// AttributePerLinkCountLimit is the maximum number of attributes allowed |
| 80 |
// per span link. Any attribute added after this limit reached will be |
| 81 |
// dropped. |
| 82 |
// |
| 83 |
// Setting this to zero means no attributes will be recorded for links. |
| 84 |
// |
| 85 |
// Setting this to a negative value means no limit is applied. |
| 86 |
AttributePerLinkCountLimit int |
| 87 |
} |
| 88 |
|
| 89 |
// NewSpanLimits returns a SpanLimits with all limits set to the value their |
| 90 |
// corresponding environment variable holds, or the default if unset. |
| 91 |
// |
| 92 |
// • AttributeValueLengthLimit: OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT |
| 93 |
// (default: unlimited) |
| 94 |
// |
| 95 |
// • AttributeCountLimit: OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT (default: 128) |
| 96 |
// |
| 97 |
// • EventCountLimit: OTEL_SPAN_EVENT_COUNT_LIMIT (default: 128) |
| 98 |
// |
| 99 |
// • AttributePerEventCountLimit: OTEL_EVENT_ATTRIBUTE_COUNT_LIMIT (default: |
| 100 |
// 128) |
| 101 |
// |
| 102 |
// • LinkCountLimit: OTEL_SPAN_LINK_COUNT_LIMIT (default: 128) |
| 103 |
// |
| 104 |
// • AttributePerLinkCountLimit: OTEL_LINK_ATTRIBUTE_COUNT_LIMIT (default: 128) |
| 105 |
func NewSpanLimits() SpanLimits { |
| 106 |
return SpanLimits{ |
| 107 |
AttributeValueLengthLimit: env.SpanAttributeValueLength(DefaultAttributeValueLengthLimit), |
| 108 |
AttributeCountLimit: env.SpanAttributeCount(DefaultAttributeCountLimit), |
| 109 |
EventCountLimit: env.SpanEventCount(DefaultEventCountLimit), |
| 110 |
LinkCountLimit: env.SpanLinkCount(DefaultLinkCountLimit), |
| 111 |
AttributePerEventCountLimit: env.SpanEventAttributeCount(DefaultAttributePerEventCountLimit), |
| 112 |
AttributePerLinkCountLimit: env.SpanLinkAttributeCount(DefaultAttributePerLinkCountLimit), |
| 113 |
} |
| 114 |
} |