3.2 KiB
Exporter Developer Guide
An exporter sends traces and metrics to any backend that is capable of consuming them. With OpenTelemetry, you can easily add and remove any exporter without requiring changes to your application code.
We provide support for several open source backends and vendors out-of-the-box like Zipkin, Jaeger, and Prometheus, but OpenTelemetry exporters follow a public interface which can be implemented by anyone. This document describes the process for developers to create their own exporter if the provided ones do not meet their needs.
A typical package layout:
opentelemetry-exporter-myexporter
├── src
│ └── index.ts
│ └── transform.ts
│ └── types.ts
│ └── myexporter.ts
└── test
└── transform.test.ts
└── myexporter.test.ts
Tracing
The SpanExporter interface defines which methods the protocol-specific trace/span exporters must implement so that they can be plugged into OpenTelemetry SDK. Span exporters must follow these rules:
- Implement the
SpanExporterinterface. - Expect to only receive spans which have been sampled.
- Expect to only receive spans which are ended.
- Do not throw exceptions.
- Do not modify received spans.
- Do not implement queuing or batching logic because this is handled by Span Processors.
The current SpanExporter interface (0.2.0) contains 2 methods:
-
export: Exports a batch of spans. In this method, you’ll process and translateReadableSpanData into the data that your trace backend accepts, and send them to your tracing backend. -
shutdown: Shuts down the exporter. This is an opportunity for exporter to do any cleanup required.Shutdownshould be called only once for each Exporter instance. After the call toShutdownsubsequent calls to Export are not allowed and should returnFailedNotRetryableerror.
Please refer to the Zipkin Exporter or Jaeger Exporter for more comprehensive examples.
Metrics
The MetricExporter defines the interface that protocol-specific exporters must implement so that they can be plugged into OpenTelemetry SDK and support sending of metrics data.
The current MetricExporter interface (0.2.0) defines 2 methods:
-
export: Exports a batch of telemetry data. In this method you’ll process and translateMetricRecordData into the data that your metric backend accepts. -
shutdown: Shuts down the exporter. This is an opportunity for exporter to do any cleanup required.Shutdownshould be called only once for each Exporter instance. After the call toShutdownsubsequent calls to Export are not allowed and should returnFailedNotRetryableerror.
Please refer to the Prometheus Exporter for more comprehensive examples.