导出器
In order to visualize and analyze your telemetry, you will need to export your data to an OpenTelemetry Collector or a backend such as Jaeger, Zipkin, Prometheus or a vendor-specific one.
As part of OpenTelemetry Erlang/Elixir you will find many exporters being available. Among them, the OpenTelemetry Protocol (OTLP) exporters provide the best experience for you as an end-user, since it is a general-purpose telemetry data delivery protocol designed in the scope of the OpenTelemetry project.
To learn more about the OTLP protocol, you can read the OTLP Specification.
Below you will find some introductions on how to set up exporters for OTLP and other common protocols in your code.
导出到OpenTelemetry收集器
收集器 提供了一种供应商无关的接收、处理和导出遥测数据的方式。软件包opentelemetry_exporter支持通过HTTP(默认)和gRPC导出到收集器的方式。收集器可以将Span导出到类似Zipkin或Jaeger的自托管服务以及商业服务。有关可用导出器的完整列表,请参阅注册表。
为了测试目的,opentelemetry-erlang
存储库中有一个收集器配置,config/otel-collector-config.yaml,可以用作起点。此配置用于docker-compose.yml中,以启动具有HTTP和gRPC接收器的收集器,然后导出到由docker-compose运行的Zipkin。
要导出到运行中的收集器,必须将opentelemetry_exporter
软件包添加到项目的依赖项中:
{deps, [{opentelemetry_api, "~> 1.2"},
{opentelemetry, "~> 1.3"},
{opentelemetry_exporter, "~> 1.6"}]}.
def deps do
[
{:opentelemetry_api, "~> 1.2"},
{:opentelemetry, "~> 1.3"},
{:opentelemetry_exporter, "~> 1.6"}
]
end
然后,应将其添加到Release的配置中,在SDK应用程序之前,以确保在SDK尝试初始化和使用导出器之前启动导出器的依赖项。
rebar.config
和mix的Release任务中的Release配置示例:
%% rebar.config
{relx, [{release, {my_instrumented_release, "0.1.0"},
[opentelemetry_exporter,
{opentelemetry, temporary},
my_instrumented_app]},
...]}.
# mix.exs
def project do
[
releases: [
my_instrumented_release: [
applications: [opentelemetry_exporter: :permanent, opentelemetry: :temporary]
],
...
]
]
end
最后,将opentelemetry
和opentelemetry_exporter
应用程序的运行时配置设置为导出到收集器。下面的配置显示了默认值,如果未设置,默认使用HTTP协议,端口为4318,并将其导出到localhost
。如果otlp_protocol
使用grpc
,则端点应更改为http://localhost:4317
。
%% config/sys.config.src
[
{opentelemetry,
[{span_processor, batch},
{traces_exporter, otlp}]},
{opentelemetry_exporter,
[{otlp_protocol, http_protobuf},
{otlp_endpoint, "http://localhost:4318"}]}]}
].
# config/runtime.exs
config :opentelemetry,
span_processor: :batch,
traces_exporter: :otlp
config :opentelemetry_exporter,
otlp_protocol: :http_protobuf,
otlp_endpoint: "http://localhost:4318"