summaryrefslogtreecommitdiff
path: root/vendor/open-telemetry/sdk/Logs/LogRecordLimitsBuilder.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/open-telemetry/sdk/Logs/LogRecordLimitsBuilder.php')
-rw-r--r--vendor/open-telemetry/sdk/Logs/LogRecordLimitsBuilder.php58
1 files changed, 58 insertions, 0 deletions
diff --git a/vendor/open-telemetry/sdk/Logs/LogRecordLimitsBuilder.php b/vendor/open-telemetry/sdk/Logs/LogRecordLimitsBuilder.php
new file mode 100644
index 000000000..3aa5217ef
--- /dev/null
+++ b/vendor/open-telemetry/sdk/Logs/LogRecordLimitsBuilder.php
@@ -0,0 +1,58 @@
+<?php
+
+declare(strict_types=1);
+
+namespace OpenTelemetry\SDK\Logs;
+
+use OpenTelemetry\SDK\Common\Attribute\Attributes;
+use OpenTelemetry\SDK\Common\Configuration\Configuration;
+use OpenTelemetry\SDK\Common\Configuration\Variables;
+use const PHP_INT_MAX;
+
+class LogRecordLimitsBuilder
+{
+ /** @var ?int Maximum allowed attribute count per record */
+ private ?int $attributeCountLimit = null;
+
+ /** @var ?int Maximum allowed attribute value length */
+ private ?int $attributeValueLengthLimit = null;
+
+ /**
+ * @param int $attributeCountLimit Maximum allowed attribute count per record
+ */
+ public function setAttributeCountLimit(int $attributeCountLimit): LogRecordLimitsBuilder
+ {
+ $this->attributeCountLimit = $attributeCountLimit;
+
+ return $this;
+ }
+
+ /**
+ * @param int $attributeValueLengthLimit Maximum allowed attribute value length
+ */
+ public function setAttributeValueLengthLimit(int $attributeValueLengthLimit): LogRecordLimitsBuilder
+ {
+ $this->attributeValueLengthLimit = $attributeValueLengthLimit;
+
+ return $this;
+ }
+
+ /**
+ * @see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/configuration/sdk-environment-variables.md#attribute-limits
+ */
+ public function build(): LogRecordLimits
+ {
+ $attributeCountLimit = $this->attributeCountLimit
+ ?: Configuration::getInt(Variables::OTEL_LOGRECORD_ATTRIBUTE_COUNT_LIMIT);
+ $attributeValueLengthLimit = $this->attributeValueLengthLimit
+ ?: Configuration::getInt(Variables::OTEL_LOGRECORD_ATTRIBUTE_VALUE_LENGTH_LIMIT);
+
+ if ($attributeValueLengthLimit === PHP_INT_MAX) {
+ $attributeValueLengthLimit = null;
+ }
+
+ $attributesFactory = Attributes::factory($attributeCountLimit, $attributeValueLengthLimit);
+
+ return new LogRecordLimits($attributesFactory);
+ }
+}