1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-06-23 00:07:52 +02:00
Files
opentelemetry-go/sdk/internal/env/env.go

169 lines
6.1 KiB
Go
Raw Normal View History

// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
fix(deps): update module github.com/golangci/golangci-lint to v2 (#6499) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [github.com/golangci/golangci-lint](https://redirect.github.com/golangci/golangci-lint) | `v1.64.8` -> `v2.0.2` | [![age](https://developer.mend.io/api/mc/badges/age/go/github.com%2fgolangci%2fgolangci-lint/v2.0.2?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/go/github.com%2fgolangci%2fgolangci-lint/v2.0.2?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/go/github.com%2fgolangci%2fgolangci-lint/v1.64.8/v2.0.2?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/go/github.com%2fgolangci%2fgolangci-lint/v1.64.8/v2.0.2?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>golangci/golangci-lint (github.com/golangci/golangci-lint)</summary> ### [`v2.0.2`](https://redirect.github.com/golangci/golangci-lint/blob/HEAD/CHANGELOG.md#v202) [Compare Source](https://redirect.github.com/golangci/golangci-lint/compare/v2.0.1...v2.0.2) 1. Misc. - Fixes flags parsing for formatters - Fixes the filepath used by the exclusion `source` option 2. Documentation - Adds a section about flags migration - Cleaning pages with v1 options ### [`v2.0.1`](https://redirect.github.com/golangci/golangci-lint/blob/HEAD/CHANGELOG.md#v201) [Compare Source](https://redirect.github.com/golangci/golangci-lint/compare/v2.0.0...v2.0.1) 1. Linters/formatters bug fixes - `golines`: fix settings during linter load 2. Misc. - Validates the `version` field before the configuration - `forbidigo`: fix migration ### [`v2.0.0`](https://redirect.github.com/golangci/golangci-lint/blob/HEAD/CHANGELOG.md#v200) [Compare Source](https://redirect.github.com/golangci/golangci-lint/compare/v1.64.8...v2.0.0) 1. Enhancements - 🌟 New `golangci-lint fmt` command with dedicated formatter configuration (https://golangci-lint.run/welcome/quick-start/#formatting) - ♻️ New `golangci-lint migrate` command to help migration from v1 to v2 (cf. [Migration guide](https://golangci-lint.run/product/migration-guide/#command-migrate)) - ⚠️ New default values (cf. [Migration guide](https://golangci-lint.run/product/migration-guide/)) - ⚠️ No exclusions by default (cf. [Migration guide](https://golangci-lint.run/product/migration-guide/#issuesexclude-use-default)) - ⚠️ New default sort order (cf. [Migration guide](https://golangci-lint.run/product/migration-guide/#outputsort-order)) - 🌟 New option `run.relative-path-mode` (cf. [Migration guide](https://golangci-lint.run/product/migration-guide/#runrelative-path-mode)) - 🌟 New linters configuration (cf. [Migration guide](https://golangci-lint.run/product/migration-guide/#linters)) - 🌟 New output format configuration (cf. [Migration guide](https://golangci-lint.run/product/migration-guide/#output)) - 🌟 New `--fast-only` flag (cf. [Migration guide](https://golangci-lint.run/product/migration-guide/#lintersfast)) - 🌟 New option `linters.exclusions.warn-unused` to log a warning if an exclusion rule is unused. 2. New linters/formatters - Add `golines` formatter https://github.com/segmentio/golines 3. Linters new features - ⚠️ Merge `staticcheck`, `stylecheck`, `gosimple` into one linter (`staticcheck`) (cf. [Migration guide](https://golangci-lint.run/product/migration-guide/#lintersenablestylecheckgosimplestaticcheck)) - `go-critic`: from 0.12.0 to 0.13.0 - `gomodguard`: from 1.3.5 to 1.4.1 (block explicit indirect dependencies) - `nilnil`: from 1.0.1 to 1.1.0 (new option: `only-two`) - `perfsprint`: from 0.8.2 to 0.9.1 (checker name in the diagnostic message) - `staticcheck`: new `quickfix` set of rules - `testifylint`: from 1.5.2 to 1.6.0 (new options: `equal-values`, `suite-method-signature`, `require-string-msg`) - `wsl`: from 4.5.0 to 4.6.0 (new option: `allow-cuddle-used-in-block`) 4. Linters bug fixes - `bidichk`: from 0.3.2 to 0.3.3 - `errchkjson`: from 0.4.0 to 0.4.1 - `errname`: from 1.0.0 to 1.1.0 - `funlen`: fix `ignore-comments` option - `gci`: from 0.13.5 to 0.13.6 - `gosmopolitan`: from 1.2.2 to 1.3.0 - `inamedparam`: from 0.1.3 to 0.2.0 - `intrange`: from 0.3.0 to 0.3.1 - `protogetter`: from 0.3.9 to 0.3.12 - `unparam`: from [`8a5130c`](https://redirect.github.com/golangci/golangci-lint/commit/8a5130ca722f) to [`0df0534`](https://redirect.github.com/golangci/golangci-lint/commit/0df0534333a4) 5. Misc. - 🧹 Configuration options renaming (cf. [Migration guide](https://golangci-lint.run/product/migration-guide/)) - 🧹 Remove options (cf. [Migration guide](https://golangci-lint.run/product/migration-guide/)) - 🧹 Remove flags (cf. [Migration guide](https://golangci-lint.run/product/migration-guide/)) - 🧹 Remove alternative names (cf. [Migration guide](https://golangci-lint.run/product/migration-guide/#alternative-linter-names)) - 🧹 Remove or replace deprecated elements (cf. [Migration guide](https://golangci-lint.run/product/migration-guide/)) - Adds an option to display some commands as JSON: - `golangci-lint config path --json` - `golangci-lint help linters --json` - `golangci-lint help formatters --json` - `golangci-lint linters --json` - `golangci-lint formatters --json` - `golangci-lint version --json` 6. Documentation - [Migration guide](https://golangci-lint.run/product/migration-guide/) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/open-telemetry/opentelemetry-go). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS4yMDcuMSIsInVwZGF0ZWRJblZlciI6IjM5LjIwNy4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJTa2lwIENoYW5nZWxvZyIsImRlcGVuZGVuY2llcyJdfQ==--> --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Tyler Yahn <codingalias@gmail.com>
2025-03-26 10:46:44 -07:00
// 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 (
"os"
"strconv"
"go.opentelemetry.io/otel/internal/global"
)
// 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(defaultValue int, keys ...string) int {
for _, key := range keys {
value := os.Getenv(key)
if value == "" {
continue
}
intValue, err := strconv.Atoi(value)
if err != nil {
global.Info("Got invalid value, number value expected.", key, value)
return defaultValue
}
return intValue
}
return defaultValue
}
// 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 IntEnvOr(key string, defaultValue int) int {
value := os.Getenv(key)
if value == "" {
return defaultValue
}
intValue, err := strconv.Atoi(value)
if err != nil {
global.Info("Got invalid value, number value expected.", key, value)
return defaultValue
}
return intValue
}
// BatchSpanProcessorScheduleDelay returns the environment variable value for
// the OTEL_BSP_SCHEDULE_DELAY key if it exists, otherwise defaultValue is
// returned.
func BatchSpanProcessorScheduleDelay(defaultValue int) int {
return IntEnvOr(BatchSpanProcessorScheduleDelayKey, defaultValue)
}
// BatchSpanProcessorExportTimeout returns the environment variable value for
// the OTEL_BSP_EXPORT_TIMEOUT key if it exists, otherwise defaultValue is
// returned.
func BatchSpanProcessorExportTimeout(defaultValue int) int {
return IntEnvOr(BatchSpanProcessorExportTimeoutKey, defaultValue)
}
// BatchSpanProcessorMaxQueueSize returns the environment variable value for
// the OTEL_BSP_MAX_QUEUE_SIZE key if it exists, otherwise defaultValue is
// returned.
func BatchSpanProcessorMaxQueueSize(defaultValue int) int {
return IntEnvOr(BatchSpanProcessorMaxQueueSizeKey, defaultValue)
}
// BatchSpanProcessorMaxExportBatchSize returns the environment variable value for
// the OTEL_BSP_MAX_EXPORT_BATCH_SIZE key if it exists, otherwise defaultValue
// is returned.
func BatchSpanProcessorMaxExportBatchSize(defaultValue int) int {
return IntEnvOr(BatchSpanProcessorMaxExportBatchSizeKey, defaultValue)
}
// 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 SpanAttributeValueLength(defaultValue int) int {
return firstInt(defaultValue, 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 SpanAttributeCount(defaultValue int) int {
return firstInt(defaultValue, SpanAttributeCountKey, AttributeCountKey)
}
// SpanEventCount returns the environment variable value for the
// OTEL_SPAN_EVENT_COUNT_LIMIT key if it exists, otherwise defaultValue is
// returned.
func SpanEventCount(defaultValue int) int {
return IntEnvOr(SpanEventCountKey, defaultValue)
}
// SpanEventAttributeCount returns the environment variable value for the
// OTEL_EVENT_ATTRIBUTE_COUNT_LIMIT key if it exists, otherwise defaultValue
// is returned.
func SpanEventAttributeCount(defaultValue int) int {
return IntEnvOr(SpanEventAttributeCountKey, defaultValue)
}
// SpanLinkCount returns the environment variable value for the
// OTEL_SPAN_LINK_COUNT_LIMIT key if it exists, otherwise defaultValue is
// returned.
func SpanLinkCount(defaultValue int) int {
return IntEnvOr(SpanLinkCountKey, defaultValue)
}
// SpanLinkAttributeCount returns the environment variable value for the
// OTEL_LINK_ATTRIBUTE_COUNT_LIMIT key if it exists, otherwise defaultValue is
// returned.
func SpanLinkAttributeCount(defaultValue int) int {
return IntEnvOr(SpanLinkAttributeCountKey, defaultValue)
}