通用 SDK 配置

OTEL_SERVICE_NAME

设置service.name资源属性的值。

默认值: unknown_service

如果在 OTEL_RESOURCE_ATTRIBUTES 中也提供了 service.name,则 OTEL_SERVICE_NAME 优先。

示例

export OTEL_SERVICE_NAME="your-service-name"

OTEL_RESOURCE_ATTRIBUTES

用作资源属性的键值对。

默认值:

示例

export OTEL_RESOURCE_ATTRIBUTES="key1=value1,key2=value2"

参考

OTEL_TRACES_SAMPLER

指定 SDK 用于采样跟踪的 Sampler。

默认值: parentbased_always_on

示例

export OTEL_TRACES_SAMPLER="traceidratio"

OTEL_TRACES_SAMPLER 的可接受值为

  • always_on: AlwaysOnSampler
  • always_off: AlwaysOffSampler
  • traceidratio: TraceIdRatioBased
  • parentbased_always_on: ParentBased(root=AlwaysOnSampler)
  • parentbased_always_off: ParentBased(root=AlwaysOffSampler)
  • parentbased_traceidratio: ParentBased(root=TraceIdRatioBased)
  • parentbased_jaeger_remote: ParentBased(root=JaegerRemoteSampler)
  • jaeger_remote: JaegerRemoteSampler
  • xray: AWS X-Ray 集中式采样 (第三方)

OTEL_TRACES_SAMPLER_ARG

指定 OTEL_TRACES_SAMPLER 定义的 Sampler 的参数(如果适用)。仅当设置了 OTEL_TRACES_SAMPLER 时,才会使用指定的值。每个 Sampler 类型定义自己的预期输入(如果有)。无效或无法识别的输入将记录为错误。

默认值:

示例

export OTEL_TRACES_SAMPLER="traceidratio"
export OTEL_TRACES_SAMPLER_ARG="0.5"

根据 OTEL_TRACES_SAMPLER 的值,OTEL_TRACES_SAMPLER_ARG 可以设置为如下:

  • 对于 traceidratioparentbased_traceidratio Sampler:采样概率,一个 [0..1] 范围内的数字,例如“0.25”。如果未设置,则默认为 1.0。
  • 对于 jaeger_remoteparentbased_jaeger_remote:值为逗号分隔的列表
    • 示例:endpoint=https://:14250,pollingIntervalMs=5000,initialSamplingRate=0.25
    • endpoint:表示 gRPC 服务器提供服务采样策略的端点,格式为 scheme://host:port (sampling.proto)。
    • pollingIntervalMs:以毫秒为单位,表示 Sampler 从后端轮询采样策略更新的频率。
    • initialSamplingRate:在 [0..1] 范围内,当无法连接后端以检索采样策略时,用作采样概率的值。一旦成功检索到采样策略,此值将不再起作用,因为在检索到新的更新之前将使用远程策略。

OTEL_PROPAGATORS

指定要用作逗号分隔列表的 Propagators。

默认值: tracecontext,baggage

示例

export OTEL_PROPAGATORS="b3"

OTEL_PROPAGATORS 的可接受值为

OTEL_TRACES_EXPORTER

指定用于跟踪的 exporter。根据实现情况,它可以是逗号分隔的列表。

默认值: otlp

示例

export OTEL_TRACES_EXPORTER="jaeger"

可接受的值为

  • otlp: OTLP
  • jaeger: 以 Jaeger 数据模型导出。
  • zipkin: Zipkin
  • console: 标准输出
  • none: 没有自动配置的跟踪 exporter。

OTEL_METRICS_EXPORTER

指定用于指标的 exporter。根据实现情况,它可以是逗号分隔的列表。

默认值: otlp

示例

export OTEL_METRICS_EXPORTER="prometheus"

OTEL_METRICS_EXPORTER 的可接受值为

OTEL_LOGS_EXPORTER

指定用于日志的 exporter。根据实现情况,它可以是逗号分隔的列表。

默认值: otlp

示例

export OTEL_LOGS_EXPORTER="otlp"

OTEL_LOGS_EXPORTER 的可接受值为