// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

// Package env provides types and functionality for environment variable support // in the OpenTelemetry SDK.
package env // import "go.opentelemetry.io/otel/sdk/internal/env" import ( ) // Environment variable names. const ( // BatchSpanProcessorScheduleDelayKey is the delay interval between two // consecutive exports (i.e. 5000). BatchSpanProcessorScheduleDelayKey = "OTEL_BSP_SCHEDULE_DELAY" // BatchSpanProcessorExportTimeoutKey is the maximum allowed time to // export data (i.e. 3000). BatchSpanProcessorExportTimeoutKey = "OTEL_BSP_EXPORT_TIMEOUT" // BatchSpanProcessorMaxQueueSizeKey is the maximum queue size (i.e. 2048). BatchSpanProcessorMaxQueueSizeKey = "OTEL_BSP_MAX_QUEUE_SIZE" // BatchSpanProcessorMaxExportBatchSizeKey is the maximum batch size (i.e. // 512). Note: it must be less than or equal to // BatchSpanProcessorMaxQueueSize. BatchSpanProcessorMaxExportBatchSizeKey = "OTEL_BSP_MAX_EXPORT_BATCH_SIZE" // AttributeValueLengthKey is the maximum allowed attribute value size. AttributeValueLengthKey = "OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT" // AttributeCountKey is the maximum allowed span attribute count. AttributeCountKey = "OTEL_ATTRIBUTE_COUNT_LIMIT" // SpanAttributeValueLengthKey is the maximum allowed attribute value size // for a span. SpanAttributeValueLengthKey = "OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT" // SpanAttributeCountKey is the maximum allowed span attribute count for a // span. SpanAttributeCountKey = "OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT" // SpanEventCountKey is the maximum allowed span event count. SpanEventCountKey = "OTEL_SPAN_EVENT_COUNT_LIMIT" // SpanEventAttributeCountKey is the maximum allowed attribute per span // event count. SpanEventAttributeCountKey = "OTEL_EVENT_ATTRIBUTE_COUNT_LIMIT" // SpanLinkCountKey is the maximum allowed span link count. SpanLinkCountKey = "OTEL_SPAN_LINK_COUNT_LIMIT" // SpanLinkAttributeCountKey is the maximum allowed attribute per span // link count. SpanLinkAttributeCountKey = "OTEL_LINK_ATTRIBUTE_COUNT_LIMIT" ) // firstInt returns the value of the first matching environment variable from // keys. If the value is not an integer or no match is found, defaultValue is // returned. func firstInt( int, ...string) int { for , := range { := os.Getenv() if == "" { continue } , := strconv.Atoi() if != nil { global.Info("Got invalid value, number value expected.", , ) return } return } return } // IntEnvOr returns the int value of the environment variable with name key if // it exists, it is not empty, and the value is an int. Otherwise, defaultValue is returned. func ( string, int) int { := os.Getenv() if == "" { return } , := strconv.Atoi() if != nil { global.Info("Got invalid value, number value expected.", , ) return } return } // BatchSpanProcessorScheduleDelay returns the environment variable value for // the OTEL_BSP_SCHEDULE_DELAY key if it exists, otherwise defaultValue is // returned. func ( int) int { return IntEnvOr(BatchSpanProcessorScheduleDelayKey, ) } // BatchSpanProcessorExportTimeout returns the environment variable value for // the OTEL_BSP_EXPORT_TIMEOUT key if it exists, otherwise defaultValue is // returned. func ( int) int { return IntEnvOr(BatchSpanProcessorExportTimeoutKey, ) } // BatchSpanProcessorMaxQueueSize returns the environment variable value for // the OTEL_BSP_MAX_QUEUE_SIZE key if it exists, otherwise defaultValue is // returned. func ( int) int { return IntEnvOr(BatchSpanProcessorMaxQueueSizeKey, ) } // BatchSpanProcessorMaxExportBatchSize returns the environment variable value for // the OTEL_BSP_MAX_EXPORT_BATCH_SIZE key if it exists, otherwise defaultValue // is returned. func ( int) int { return IntEnvOr(BatchSpanProcessorMaxExportBatchSizeKey, ) } // SpanAttributeValueLength returns the environment variable value for the // OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT key if it exists. Otherwise, the // environment variable value for OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT is // returned or defaultValue if that is not set. func ( int) int { return firstInt(, SpanAttributeValueLengthKey, AttributeValueLengthKey) } // SpanAttributeCount returns the environment variable value for the // OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT key if it exists. Otherwise, the // environment variable value for OTEL_ATTRIBUTE_COUNT_LIMIT is returned or // defaultValue if that is not set. func ( int) int { return firstInt(, SpanAttributeCountKey, AttributeCountKey) } // SpanEventCount returns the environment variable value for the // OTEL_SPAN_EVENT_COUNT_LIMIT key if it exists, otherwise defaultValue is // returned. func ( int) int { return IntEnvOr(SpanEventCountKey, ) } // SpanEventAttributeCount returns the environment variable value for the // OTEL_EVENT_ATTRIBUTE_COUNT_LIMIT key if it exists, otherwise defaultValue // is returned. func ( int) int { return IntEnvOr(SpanEventAttributeCountKey, ) } // SpanLinkCount returns the environment variable value for the // OTEL_SPAN_LINK_COUNT_LIMIT key if it exists, otherwise defaultValue is // returned. func ( int) int { return IntEnvOr(SpanLinkCountKey, ) } // SpanLinkAttributeCount returns the environment variable value for the // OTEL_LINK_ATTRIBUTE_COUNT_LIMIT key if it exists, otherwise defaultValue is // returned. func ( int) int { return IntEnvOr(SpanLinkAttributeCountKey, ) }