|
7 | 7 |
|
8 | 8 | namespace Spryker\Service\Opentelemetry\Instrumentation\Span;
|
9 | 9 |
|
10 |
| -use OpenTelemetry\SDK\Common\Attribute\FilteredAttributesFactory; |
11 | 10 | use OpenTelemetry\SDK\Common\Configuration\Configuration;
|
12 | 11 | use OpenTelemetry\SDK\Common\Configuration\Variables as Env;
|
13 | 12 | use OpenTelemetry\SDK\Trace\SpanLimits;
|
14 |
| -use OpenTelemetry\SemConv\TraceAttributes; |
15 | 13 |
|
16 | 14 | class SpanLimitBuilder
|
17 | 15 | {
|
18 |
| - /** |
19 |
| - * @var int|null |
20 |
| - */ |
21 |
| - protected ?int $attributeCountLimit = null; |
22 |
| - |
23 |
| - /** |
24 |
| - * @var int|null |
25 |
| - */ |
26 |
| - protected ?int $attributeValueLengthLimit = null; |
27 |
| - |
28 |
| - /** |
29 |
| - * @var int|null |
30 |
| - */ |
31 |
| - protected ?int $eventCountLimit = null; |
32 |
| - |
33 |
| - /** |
34 |
| - * @var int|null |
35 |
| - */ |
36 |
| - protected ?int $linkCountLimit = null; |
37 |
| - |
38 |
| - /** |
39 |
| - * @var int|null |
40 |
| - */ |
41 |
| - protected ?int $attributePerEventCountLimit = null; |
42 |
| - |
43 |
| - /** |
44 |
| - * @var int|null |
45 |
| - */ |
46 |
| - protected ?int $attributePerLinkCountLimit = null; |
47 |
| - |
48 |
| - /** |
49 |
| - * @param int $attributeCountLimit |
50 |
| - * |
51 |
| - * @return $this |
52 |
| - */ |
53 |
| - public function setAttributeCountLimit(int $attributeCountLimit) |
54 |
| - { |
55 |
| - $this->attributeCountLimit = $attributeCountLimit; |
56 |
| - |
57 |
| - return $this; |
58 |
| - } |
59 |
| - |
60 |
| - /** |
61 |
| - * @param int $attributeValueLengthLimit |
62 |
| - * |
63 |
| - * @return $this |
64 |
| - */ |
65 |
| - public function setAttributeValueLengthLimit(int $attributeValueLengthLimit) |
66 |
| - { |
67 |
| - $this->attributeValueLengthLimit = $attributeValueLengthLimit; |
68 |
| - |
69 |
| - return $this; |
70 |
| - } |
71 |
| - |
72 |
| - /** |
73 |
| - * @param int $eventCountLimit |
74 |
| - * |
75 |
| - * @return $this |
76 |
| - */ |
77 |
| - public function setEventCountLimit(int $eventCountLimit) |
78 |
| - { |
79 |
| - $this->eventCountLimit = $eventCountLimit; |
80 |
| - |
81 |
| - return $this; |
82 |
| - } |
83 |
| - |
84 |
| - /** |
85 |
| - * @param int $linkCountLimit |
86 |
| - * |
87 |
| - * @return $this |
88 |
| - */ |
89 |
| - public function setLinkCountLimit(int $linkCountLimit) |
90 |
| - { |
91 |
| - $this->linkCountLimit = $linkCountLimit; |
92 |
| - |
93 |
| - return $this; |
94 |
| - } |
95 |
| - |
96 |
| - /** |
97 |
| - * @param int $attributePerEventCountLimit |
98 |
| - * @return $this |
99 |
| - */ |
100 |
| - public function setAttributePerEventCountLimit(int $attributePerEventCountLimit) |
101 |
| - { |
102 |
| - $this->attributePerEventCountLimit = $attributePerEventCountLimit; |
103 |
| - |
104 |
| - return $this; |
105 |
| - } |
106 |
| - |
107 |
| - /** |
108 |
| - * @param int $attributePerLinkCountLimit |
109 |
| - * |
110 |
| - * @return $this |
111 |
| - */ |
112 |
| - public function setAttributePerLinkCountLimit(int $attributePerLinkCountLimit) |
113 |
| - { |
114 |
| - $this->attributePerLinkCountLimit = $attributePerLinkCountLimit; |
115 |
| - |
116 |
| - return $this; |
117 |
| - } |
118 |
| - |
119 |
| - /** |
120 |
| - * @param bool $retain |
121 |
| - * |
122 |
| - * @return $this |
123 |
| - */ |
124 |
| - public function retainGeneralIdentityAttributes(bool $retain = true) |
125 |
| - { |
126 |
| - $this->retainGeneralIdentityAttributes = $retain; |
127 |
| - |
128 |
| - return $this; |
129 |
| - } |
130 |
| - |
131 | 16 | /**
|
132 | 17 | * @return \OpenTelemetry\SDK\Trace\SpanLimits
|
133 | 18 | */
|
134 | 19 | public function build(): SpanLimits
|
135 | 20 | {
|
136 |
| - $attributeCountLimit = $this->attributeCountLimit |
137 |
| - ?: Configuration::getInt(Env::OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT, SpanLimits::DEFAULT_SPAN_ATTRIBUTE_COUNT_LIMIT); |
138 |
| - $attributeValueLengthLimit = $this->attributeValueLengthLimit |
139 |
| - ?: Configuration::getInt(Env::OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT, SpanLimits::DEFAULT_SPAN_ATTRIBUTE_LENGTH_LIMIT); |
140 |
| - $eventCountLimit = $this->eventCountLimit |
141 |
| - ?: Configuration::getInt(Env::OTEL_SPAN_EVENT_COUNT_LIMIT, SpanLimits::DEFAULT_SPAN_EVENT_COUNT_LIMIT); |
142 |
| - $linkCountLimit = $this->linkCountLimit |
143 |
| - ?: Configuration::getInt(Env::OTEL_SPAN_LINK_COUNT_LIMIT, SpanLimits::DEFAULT_SPAN_LINK_COUNT_LIMIT); |
144 |
| - $attributePerEventCountLimit = $this->attributePerEventCountLimit |
145 |
| - ?: Configuration::getInt(Env::OTEL_EVENT_ATTRIBUTE_COUNT_LIMIT, SpanLimits::DEFAULT_EVENT_ATTRIBUTE_COUNT_LIMIT); |
146 |
| - $attributePerLinkCountLimit = $this->attributePerLinkCountLimit |
147 |
| - ?: Configuration::getInt(Env::OTEL_LINK_ATTRIBUTE_COUNT_LIMIT, SpanLimits::DEFAULT_LINK_ATTRIBUTE_COUNT_LIMIT); |
| 21 | + $attributeCountLimit = Configuration::getInt(Env::OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT, SpanLimits::DEFAULT_SPAN_ATTRIBUTE_COUNT_LIMIT); |
| 22 | + $attributeValueLengthLimit = Configuration::getInt(Env::OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT, SpanLimits::DEFAULT_SPAN_ATTRIBUTE_LENGTH_LIMIT); |
| 23 | + $eventCountLimit = Configuration::getInt(Env::OTEL_SPAN_EVENT_COUNT_LIMIT, SpanLimits::DEFAULT_SPAN_EVENT_COUNT_LIMIT); |
| 24 | + $linkCountLimit = Configuration::getInt(Env::OTEL_SPAN_LINK_COUNT_LIMIT, SpanLimits::DEFAULT_SPAN_LINK_COUNT_LIMIT); |
| 25 | + $attributePerEventCountLimit = Configuration::getInt(Env::OTEL_EVENT_ATTRIBUTE_COUNT_LIMIT, SpanLimits::DEFAULT_EVENT_ATTRIBUTE_COUNT_LIMIT); |
| 26 | + $attributePerLinkCountLimit = Configuration::getInt(Env::OTEL_LINK_ATTRIBUTE_COUNT_LIMIT, SpanLimits::DEFAULT_LINK_ATTRIBUTE_COUNT_LIMIT); |
148 | 27 |
|
149 | 28 | if ($attributeValueLengthLimit === PHP_INT_MAX) {
|
150 | 29 | $attributeValueLengthLimit = null;
|
151 | 30 | }
|
152 | 31 |
|
153 |
| - $spanAttributesFactory = new FilteredAttributesFactory(Attributes::factory($attributeCountLimit, $attributeValueLengthLimit), [ |
154 |
| - TraceAttributes::USER_ID, |
155 |
| - TraceAttributes::USER_ROLES, |
156 |
| - ]); |
157 |
| - |
158 | 32 | return new SpanLimits(
|
159 |
| - $spanAttributesFactory, |
| 33 | + Attributes::factory($attributeCountLimit, $attributeValueLengthLimit), |
160 | 34 | Attributes::factory($attributePerEventCountLimit, $attributeValueLengthLimit),
|
161 | 35 | Attributes::factory($attributePerLinkCountLimit, $attributeValueLengthLimit),
|
162 | 36 | $eventCountLimit,
|
|
0 commit comments