主题
OpenTelemetry
提示
本页是 OpenTelemetry 的配置参考,如果你希望设置和集成 OpenTelemetry,建议你查看 与 OpenTelemetry 集成。
¥This page is a config reference for OpenTelemetry, if you're looking to setup and integrate with OpenTelemetry, we recommended taking a look at Integrate with OpenTelemetry instead.
要开始使用 OpenTelemetry,请安装 @elysiajs/opentelemetry
并将插件应用于任何实例。
¥To start using OpenTelemetry, install @elysiajs/opentelemetry
and apply plugin to any instance.
typescript
import { Elysia } from 'elysia'
import { opentelemetry } from '@elysiajs/opentelemetry'
import { BatchSpanProcessor } from '@opentelemetry/sdk-trace-node'
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto'
new Elysia()
.use(
opentelemetry({
spanProcessors: [
new BatchSpanProcessor(
new OTLPTraceExporter()
)
]
})
)
Elysia OpenTelemetry 将收集任何兼容 OpenTelemetry 标准的库的 span,并自动应用父级和子级 span。
¥Elysia OpenTelemetry is will collect span of any library compatible OpenTelemetry standard, and will apply parent and child span automatically.
用法
¥Usage
有关用法和实用程序,请参阅 opentelemetry
¥See opentelemetry for usage and utilities
配置
¥Config
此插件扩展了 OpenTelemetry SDK 参数选项。
¥This plugin extends OpenTelemetry SDK parameters options.
以下是插件接受的配置。
¥Below is a config which is accepted by the plugin
autoDetectResources - boolean
使用默认资源检测器自动从环境中检测资源。
¥Detect resources automatically from the environment using the default resource detectors.
默认:true
¥default: true
contextManager - ContextManager
使用自定义上下文管理器。
¥Use a custom context manager.
默认:AsyncHooksContextManager
¥default: AsyncHooksContextManager
textMapPropagator - TextMapPropagator
使用自定义传播器。
¥Use a custom propagator.
默认:CompositePropagator
使用 W3C 跟踪上下文和 Baggage
¥default: CompositePropagator
using W3C Trace Context and Baggage
metricReader - MetricReader
添加一个将传递给 MeterProvider 的 MetricReader。
¥Add a MetricReader that will be passed to the MeterProvider.
views - View[]
要传递给 MeterProvider 的视图列表。
¥A list of views to be passed to the MeterProvider.
接受一个 View 实例数组。此参数可用于配置直方图指标的明确存储桶大小。
¥Accepts an array of View-instances. This parameter can be used to configure explicit bucket sizes of histogram metrics.
instrumentations - (Instrumentation | Instrumentation[])[]
配置检测。
¥Configure instrumentations.
默认情况下,getNodeAutoInstrumentations
处于启用状态,如果你想启用它们,可以使用元包或单独配置每个检测工具。
¥By default getNodeAutoInstrumentations
is enabled, if you want to enable them you can use either metapackage or configure each instrumentation individually.
默认:getNodeAutoInstrumentations()
¥default: getNodeAutoInstrumentations()
resource - IResource
配置资源。
¥Configure a resource.
也可以使用 SDK 的 autoDetectResources 方法检测资源。
¥Resources may also be detected by using the autoDetectResources method of the SDK.
resourceDetectors - Array<Detector | DetectorSync>
配置资源检测器。默认情况下,资源检测器为 [envDetector, processDetector, hostDetector]。注意:为了启用检测,参数 autoDetectResources 必须为 true。
¥Configure resource detectors. By default, the resource detectors are [envDetector, processDetector, hostDetector]. NOTE: In order to enable the detection, the parameter autoDetectResources has to be true.
如果未设置 resourceDetectors,你还可以使用环境变量 OTEL_NODE_RESOURCE_DETECTORS 来启用某些检测器,或完全禁用它们:
¥If resourceDetectors was not set, you can also use the environment variable OTEL_NODE_RESOURCE_DETECTORS to enable only certain detectors, or completely disable them:
env
host
os
process
serviceinstance(实验性)
all - 启用上述所有资源检测器
none - 禁用资源检测
例如,要仅启用环境和主机检测器:
¥For example, to enable only the env, host detectors:
bash
export OTEL_NODE_RESOURCE_DETECTORS="env,host"
sampler - 采样器
¥sampler - Sampler
配置自定义采样器。默认情况下,所有跟踪都将被采样。
¥Configure a custom sampler. By default, all traces will be sampled.
serviceName - string
待识别的命名空间。
¥Namespace to be identify as.
spanProcessors - SpanProcessor[]
用于注册到跟踪器提供程序的 span 处理器数组。
¥An array of span processors to register to the tracer provider.
traceExporter - SpanExporter
配置跟踪导出器。如果配置了导出器,它将与 BatchSpanProcessor
一起使用。
¥Configure a trace exporter. If an exporter is configured, it will be used with a BatchSpanProcessor
.
如果未以编程方式配置导出器或 span 处理器,此包将自动设置使用 http/protobuf 协议的默认 otlp 导出器,并使用 BatchSpanProcessor。
¥If an exporter OR span processor is not configured programmatically, this package will auto setup the default otlp exporter with http/protobuf protocol with a BatchSpanProcessor.
spanLimits - SpanLimits
配置跟踪参数。这些参数与配置跟踪器时使用的参数相同。
¥Configure tracing parameters. These are the same trace parameters used to configure a tracer.