...

Source file src/go.opentelemetry.io/otel/sdk/trace/span_limits.go

Documentation: go.opentelemetry.io/otel/sdk/trace

     1  // Copyright The OpenTelemetry Authors
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package trace // import "go.opentelemetry.io/otel/sdk/trace"
    16  
    17  import "go.opentelemetry.io/otel/sdk/internal/env"
    18  
    19  const (
    20  	// DefaultAttributeValueLengthLimit is the default maximum allowed
    21  	// attribute value length, unlimited.
    22  	DefaultAttributeValueLengthLimit = -1
    23  
    24  	// DefaultAttributeCountLimit is the default maximum number of attributes
    25  	// a span can have.
    26  	DefaultAttributeCountLimit = 128
    27  
    28  	// DefaultEventCountLimit is the default maximum number of events a span
    29  	// can have.
    30  	DefaultEventCountLimit = 128
    31  
    32  	// DefaultLinkCountLimit is the default maximum number of links a span can
    33  	// have.
    34  	DefaultLinkCountLimit = 128
    35  
    36  	// DefaultAttributePerEventCountLimit is the default maximum number of
    37  	// attributes a span event can have.
    38  	DefaultAttributePerEventCountLimit = 128
    39  
    40  	// DefaultAttributePerLinkCountLimit is the default maximum number of
    41  	// attributes a span link can have.
    42  	DefaultAttributePerLinkCountLimit = 128
    43  )
    44  
    45  // SpanLimits represents the limits of a span.
    46  type SpanLimits struct {
    47  	// AttributeValueLengthLimit is the maximum allowed attribute value length.
    48  	//
    49  	// This limit only applies to string and string slice attribute values.
    50  	// Any string longer than this value will be truncated to this length.
    51  	//
    52  	// Setting this to a negative value means no limit is applied.
    53  	AttributeValueLengthLimit int
    54  
    55  	// AttributeCountLimit is the maximum allowed span attribute count. Any
    56  	// attribute added to a span once this limit is reached will be dropped.
    57  	//
    58  	// Setting this to zero means no attributes will be recorded.
    59  	//
    60  	// Setting this to a negative value means no limit is applied.
    61  	AttributeCountLimit int
    62  
    63  	// EventCountLimit is the maximum allowed span event count. Any event
    64  	// added to a span once this limit is reached means it will be added but
    65  	// the oldest event will be dropped.
    66  	//
    67  	// Setting this to zero means no events we be recorded.
    68  	//
    69  	// Setting this to a negative value means no limit is applied.
    70  	EventCountLimit int
    71  
    72  	// LinkCountLimit is the maximum allowed span link count. Any link added
    73  	// to a span once this limit is reached means it will be added but the
    74  	// oldest link will be dropped.
    75  	//
    76  	// Setting this to zero means no links we be recorded.
    77  	//
    78  	// Setting this to a negative value means no limit is applied.
    79  	LinkCountLimit int
    80  
    81  	// AttributePerEventCountLimit is the maximum number of attributes allowed
    82  	// per span event. Any attribute added after this limit reached will be
    83  	// dropped.
    84  	//
    85  	// Setting this to zero means no attributes will be recorded for events.
    86  	//
    87  	// Setting this to a negative value means no limit is applied.
    88  	AttributePerEventCountLimit int
    89  
    90  	// AttributePerLinkCountLimit is the maximum number of attributes allowed
    91  	// per span link. Any attribute added after this limit reached will be
    92  	// dropped.
    93  	//
    94  	// Setting this to zero means no attributes will be recorded for links.
    95  	//
    96  	// Setting this to a negative value means no limit is applied.
    97  	AttributePerLinkCountLimit int
    98  }
    99  
   100  // NewSpanLimits returns a SpanLimits with all limits set to the value their
   101  // corresponding environment variable holds, or the default if unset.
   102  //
   103  // • AttributeValueLengthLimit: OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT
   104  // (default: unlimited)
   105  //
   106  // • AttributeCountLimit: OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT (default: 128)
   107  //
   108  // • EventCountLimit: OTEL_SPAN_EVENT_COUNT_LIMIT (default: 128)
   109  //
   110  // • AttributePerEventCountLimit: OTEL_EVENT_ATTRIBUTE_COUNT_LIMIT (default:
   111  // 128)
   112  //
   113  // • LinkCountLimit: OTEL_SPAN_LINK_COUNT_LIMIT (default: 128)
   114  //
   115  // • AttributePerLinkCountLimit: OTEL_LINK_ATTRIBUTE_COUNT_LIMIT (default: 128)
   116  func NewSpanLimits() SpanLimits {
   117  	return SpanLimits{
   118  		AttributeValueLengthLimit:   env.SpanAttributeValueLength(DefaultAttributeValueLengthLimit),
   119  		AttributeCountLimit:         env.SpanAttributeCount(DefaultAttributeCountLimit),
   120  		EventCountLimit:             env.SpanEventCount(DefaultEventCountLimit),
   121  		LinkCountLimit:              env.SpanLinkCount(DefaultLinkCountLimit),
   122  		AttributePerEventCountLimit: env.SpanEventAttributeCount(DefaultAttributePerEventCountLimit),
   123  		AttributePerLinkCountLimit:  env.SpanLinkAttributeCount(DefaultAttributePerLinkCountLimit),
   124  	}
   125  }
   126  

View as plain text