span_limits.go 4.7 KB

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