exporter

package module
v1.59.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 25, 2026 License: Apache-2.0 Imports: 5 Imported by: 462

README

General Information

An exporter defines how the pipeline data leaves the collector.

This repository hosts the following exporters available in traces, metrics and logs pipelines (sorted alphabetically):

The contrib repository has more exporters available in its builds.

Configuring Exporters

Exporters are configured via YAML under the top-level exporters tag.

The following is a sample configuration for the exampleexporter.

exporters:
  # Exporter 1.
  # <exporter type>:
  exampleexporter:
    # <setting one>: <value one>
    endpoint: 1.2.3.4:8080
    # ...
  # Exporter 2.
  # <exporter type>/<name>:
  exampleexporter/settings:
    # <setting two>: <value two>
    endpoint: 0.0.0.0:9211

An exporter instance is referenced by its full name in other parts of the config, such as in pipelines. A full name consists of the exporter type, '/' and the name appended to the exporter type in the configuration. All exporter full names must be unique.

For the example above:

  • Exporter 1 has full name exampleexporter.
  • Exporter 2 has full name exampleexporter/settings.

Exporters are enabled upon being added to a pipeline. For example:

service:
  pipelines:
    # Valid pipelines are: traces, metrics or logs
    # Trace pipeline 1.
    traces:
      receivers: [examplereceiver]
      processors: []
      exporters: [exampleexporter, exampleexporter/settings]
    # Trace pipeline 2.
    traces/another:
      receivers: [examplereceiver]
      processors: []
      exporters: [exampleexporter, exampleexporter/settings]

Data Ownership

When multiple exporters are configured to send the same data (e.g. by configuring multiple exporters for the same pipeline):

  • exporters not configured to mutate the data will have shared access to the data
  • exporters with the Capabilities to mutate the data will receive a copy of the data

Exporters access export data when ConsumeTraces/ConsumeMetrics/ConsumeLogs function is called. Unless exporter's capabilities include mutation, the exporter MUST NOT modify the pdata.Traces/pdata.Metrics/pdata.Logs argument of these functions. Any approach that does not mutate the original pdata.Traces/pdata.Metrics/pdata.Logs is allowed without the mutation capability.

Proxy Support

Beyond standard YAML configuration as outlined in the individual READMEs above, exporters that leverage the net/http package (all do today) also respect the following proxy environment variables:

  • HTTP_PROXY
  • HTTPS_PROXY
  • NO_PROXY

If set at Collector start time then exporters, regardless of protocol, will or will not proxy traffic as defined by these environment variables.

Documentation

Overview

Example

Example demonstrates the usage of the exporter factory.

package main

import (
	"context"
	"fmt"

	"go.uber.org/zap"

	"go.opentelemetry.io/collector/component"
	"go.opentelemetry.io/collector/config/configoptional"
	"go.opentelemetry.io/collector/config/configretry"
	"go.opentelemetry.io/collector/consumer"
	"go.opentelemetry.io/collector/exporter"
	"go.opentelemetry.io/collector/exporter/exporterhelper"
	"go.opentelemetry.io/collector/pdata/pmetric"
)

// typeStr defines the unique type identifier for the exporter.
var typeStr = component.MustNewType("example")

// exampleConfig holds configuration settings for the exporter.
type exampleConfig struct {
	QueueSettings configoptional.Optional[exporterhelper.QueueBatchConfig]
	BackOffConfig configretry.BackOffConfig
}

// exampleExporter implements the OpenTelemetry exporter interface.
type exampleExporter struct {
	cancel context.CancelFunc
	config exampleConfig
	client *loggerClient
}

// loggerClient wraps a Zap logger to provide logging functionality.
type loggerClient struct {
	logger *zap.Logger
}

// Example demonstrates the usage of the exporter factory.
func main() {
	// Instantiate the exporter factory and print its type.
	exampleExporter := NewFactory()
	fmt.Println(exampleExporter.Type())

}

// NewFactory creates a new exporter factory.
func NewFactory() exporter.Factory {
	return exporter.NewFactory(
		typeStr,
		createDefaultConfig,
		exporter.WithMetrics(createExampleExporter, component.StabilityLevelAlpha),
	)
}

// createDefaultConfig returns the default configuration for the exporter.
func createDefaultConfig() component.Config {
	return &exampleConfig{}
}

// createExampleExporter initializes an instance of the example exporter.
func createExampleExporter(ctx context.Context, params exporter.Settings, baseCfg component.Config) (exporter.Metrics, error) {
	// Convert baseCfg to the correct type.
	cfg := baseCfg.(*exampleConfig)

	// Create a new exporter instance.
	xptr := newExampleExporter(ctx, cfg, params)

	// Wrap the exporter with the helper utilities.
	return exporterhelper.NewMetrics(
		ctx,
		params,
		cfg,
		xptr.consumeMetrics,
		exporterhelper.WithQueue(cfg.QueueSettings),
		exporterhelper.WithRetry(cfg.BackOffConfig),
		exporterhelper.WithCapabilities(consumer.Capabilities{MutatesData: false}),
		exporterhelper.WithShutdown(xptr.shutdown),
	)
}

// newExampleExporter constructs a new instance of the example exporter.
func newExampleExporter(ctx context.Context, cfg *exampleConfig, params exporter.Settings) *exampleExporter {
	xptr := &exampleExporter{
		config: *cfg,
		client: &loggerClient{logger: params.Logger},
	}

	// Create a cancelable context.
	_, xptr.cancel = context.WithCancel(ctx)

	return xptr
}

// consumeMetrics processes incoming metric data and logs it.
func (xptr *exampleExporter) consumeMetrics(_ context.Context, md pmetric.Metrics) error {
	xptr.client.Push(md)
	return nil
}

// Shutdown properly stops the exporter and releases resources.
func (xptr *exampleExporter) shutdown(_ context.Context) error {
	xptr.cancel()
	return nil
}

// Push logs the received metric data.
func (client *loggerClient) Push(md pmetric.Metrics) {
	client.logger.Info("Exporting metrics", zap.Any("metrics", md))
}
Output:
example

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CreateLogsFunc

type CreateLogsFunc func(context.Context, Settings, component.Config) (Logs, error)

CreateLogsFunc is the equivalent of Factory.CreateLogs.

type CreateMetricsFunc

type CreateMetricsFunc func(context.Context, Settings, component.Config) (Metrics, error)

CreateMetricsFunc is the equivalent of Factory.CreateMetrics.

type CreateTracesFunc

type CreateTracesFunc func(context.Context, Settings, component.Config) (Traces, error)

CreateTracesFunc is the equivalent of Factory.CreateTraces.

type Factory

type Factory interface {
	component.Factory

	// CreateTraces creates a Traces exporter based on this config.
	// If the exporter type does not support tracing,
	// this function returns the error [pipeline.ErrSignalNotSupported].
	CreateTraces(ctx context.Context, set Settings, cfg component.Config) (Traces, error)

	// TracesStability gets the stability level of the Traces exporter.
	TracesStability() component.StabilityLevel

	// CreateMetrics creates a Metrics exporter based on this config.
	// If the exporter type does not support metrics,
	// this function returns the error [pipeline.ErrSignalNotSupported].
	CreateMetrics(ctx context.Context, set Settings, cfg component.Config) (Metrics, error)

	// MetricsStability gets the stability level of the Metrics exporter.
	MetricsStability() component.StabilityLevel

	// CreateLogs creates a Logs exporter based on the config.
	// If the exporter type does not support logs,
	// this function returns the error [pipeline.ErrSignalNotSupported].
	CreateLogs(ctx context.Context, set Settings, cfg component.Config) (Logs, error)

	// LogsStability gets the stability level of the Logs exporter.
	LogsStability() component.StabilityLevel
	// contains filtered or unexported methods
}

Factory is factory interface for exporters.

This interface cannot be directly implemented. Implementations must use the NewFactory to implement it.

func NewFactory

func NewFactory(cfgType component.Type, createDefaultConfig component.CreateDefaultConfigFunc, options ...FactoryOption) Factory

NewFactory returns a Factory.

type FactoryOption

type FactoryOption interface {
	// contains filtered or unexported methods
}

FactoryOption apply changes to Factory.

func WithLogs

func WithLogs(createLogs CreateLogsFunc, sl component.StabilityLevel) FactoryOption

WithLogs overrides the default "error not supported" implementation for Factory.CreateLogs and the default "undefined" stability level.

func WithMetrics

func WithMetrics(createMetrics CreateMetricsFunc, sl component.StabilityLevel) FactoryOption

WithMetrics overrides the default "error not supported" implementation for Factory.CreateMetrics and the default "undefined" stability level.

func WithTraces

func WithTraces(createTraces CreateTracesFunc, sl component.StabilityLevel) FactoryOption

WithTraces overrides the default "error not supported" implementation for Factory.CreateTraces and the default "undefined" stability level.

type Logs

type Logs interface {
	component.Component
	consumer.Logs
}

Logs is an exporter that can consume logs.

type Metrics

type Metrics interface {
	component.Component
	consumer.Metrics
}

Metrics is an exporter that can consume metrics.

type Settings added in v0.103.0

type Settings struct {
	// ID returns the ID of the component that will be created.
	ID component.ID

	component.TelemetrySettings

	// BuildInfo can be used by components for informational purposes
	BuildInfo component.BuildInfo
	// contains filtered or unexported fields
}

Settings configures exporter creators.

type Traces

type Traces interface {
	component.Component
	consumer.Traces
}

Traces is an exporter that can consume traces.

Directories

Path Synopsis
exportertest module
internal
nopexporter module
otlpexporter module
xexporter module

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL