exportercreator

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2026 License: Apache-2.0 Imports: 26 Imported by: 0

README

Exporter Creator

Status
Stability development: logs, metrics, traces
Distributions []
Issues Open issues Closed issues
Code coverage codecov
Code Owners @stu

The exporter_creator exporter dynamically creates other exporters at runtime when observer extensions report endpoints (for example Kubernetes pods, CRDs, or JSON-defined targets). It evaluates rules against each endpoint, starts matching exporter templates with configuration expanded from endpoint data, and routes incoming logs, metrics, and traces to the right sub-exporter using resource attributes. Use it when destinations are not fixed at config time—similar to dynamic receiver wiring, but on the export side of the pipeline.

Relationship to OpenTelemetry Collector Contrib

In opentelemetry-collector-contrib, receiver creator (receiver_creator) watches observers and spawns receivers from templates. Exporter creator is the same pattern for exporters: watch observers, match rules, instantiate exporters. This repository tracks the implementation from contrib’s exporter/exportercreator, published as a standalone module (github.com/stuart23/exportercreator) for custom collector builds.

Building a collector with this exporter

exporter_creator is not included in the default core or contrib collector distributions. Build a custom binary with the OpenTelemetry Collector Builder (ocb). See the OCB documentation.

Add the module under exporters in builder-config.yaml (use a real version tag once you publish; v0.0.0 is common with a local replace during development):

exporters:
  - gomod: go.opentelemetry.io/collector/exporter/debugexporter v0.147.0
  - gomod: go.opentelemetry.io/collector/exporter/otlpexporter v0.147.0
  - gomod: github.com/stuart23/exportercreator v0.1.0

You also need at least one observer extension in the same manifest (for example k8s_observer, jsonfile_observer) so watch_observers has something to attach to. This module depends on extension/observer from contrib; your go.mod or builder manifest often needs replace directives for contrib paths (including observer submodules such as jsonfileobserver). Copy and adapt the replaces block from builder-config.example.yaml—paths are relative to the builder output_path directory.

Go module and dependencies

  • Module path: github.com/stuart23/exportercreator
  • Shared state: includes a copy of contrib’s internal/sharedcomponent, which is not importable from outside the contrib module tree as a normal dependency.
  • Observer API: depends on a tagged extension/observer release (see go.mod). Rules accept k8s.crd and jsonfile endpoint kinds via ObserverEndpointTypeK8sCRD / ObserverEndpointTypeJSONFile so behavior stays aligned with real observers even when those kinds are not yet named constants in the observer module.

How it works

  1. Observer Extensions: The exporter watches observer extensions (like k8s_observer) for endpoint discovery events.

  2. Rule Matching: When endpoints are discovered, rules are evaluated to determine which exporter templates should be instantiated.

  3. Dynamic Exporter Creation: Matching exporter templates are used to create sub-exporters with endpoint-specific configuration.

  4. Telemetry Routing: Incoming telemetry is routed to the appropriate sub-exporter based on resource attribute matching against endpoint properties.

Configuration

extensions:
  k8s_observer:
    observe_pods: true

exporters:
  exporter_creator:
    # Observer extensions to watch for endpoint discovery
    watch_observers: [k8s_observer]
    
    # Rules for routing telemetry to exporters based on resource attributes
    routing:
      rules:
        - resource_attribute: k8s.pod.labels.app
          endpoint_property: labels.app
    
    # Fallback exporters for unmatched telemetry
    default_exporters: [otlp/default]
    
    # Exporter templates - created when endpoints match rules
    exporters:
      otlp/per-app:
        rule: type == "pod" && labels["otel-export"] == "true"
        config:
          endpoint: '`labels["collector-endpoint"]`'

service:
  extensions: [k8s_observer]
  pipelines:
    traces:
      receivers: [otlp]
      exporters: [exporter_creator]

Configuration Options

Option Type Description
watch_observers []component.ID Observer extensions to watch for endpoint discovery
routing.rules []RoutingRule Rules for matching resource attributes to endpoint properties
default_exporters []component.ID Static exporters to receive unmatched telemetry
exporters map[string]exporterTemplate Exporter templates to instantiate when rules match
Routing Rules

Each routing rule maps a resource attribute to an endpoint property:

Field Type Description
resource_attribute string Resource attribute key (e.g., k8s.pod.labels.app)
endpoint_property string Endpoint property path using dot notation (e.g., labels.app, spec.region)
Exporter Template
Field Type Description
rule string Expression that must evaluate to true for the exporter to be created
config map[string]any Exporter configuration (supports endpoint value expansion)
resource_attributes map[string]any Resource attributes to associate with this exporter

Endpoint Value Expansion

Configuration values can reference endpoint properties using backtick expressions:

config:
  endpoint: '`labels["collector-endpoint"]`'
  topic: '`annotations["kafka.topic"]`'

Development

go test ./...

go test ./... uses the published observer module from the proxy; no local contrib checkout is required.

Documentation

Overview

Package exportercreator implements exporter_creator that can instantiate other exporters at runtime.

Index

Constants

View Source
const (
	ObserverEndpointTypeK8sCRD   = observer.EndpointType("k8s.crd")
	ObserverEndpointTypeJSONFile = observer.EndpointType("jsonfile")
)

Observer endpoint kinds used by k8s_observer, jsonfile_observer, etc. Older tagged github.com/open-telemetry/opentelemetry-collector-contrib/extension/observer modules may not export named constants for every kind; these values match the strings returned by real observer implementations.

Variables

This section is empty.

Functions

func NewFactory

func NewFactory() exporter.Factory

NewFactory creates a factory for exporter creator.

Types

type Config

type Config struct {

	// WatchObservers are the extensions to listen to endpoints from.
	WatchObservers []component.ID `mapstructure:"watch_observers"`
	// Routing defines how telemetry is routed to dynamically created exporters.
	Routing RoutingConfig `mapstructure:"routing"`
	// DefaultExporters are static exporters to route unmatched telemetry to.
	DefaultExporters []component.ID `mapstructure:"default_exporters"`
	// contains filtered or unexported fields
}

Config defines configuration for exporter_creator.

func (*Config) Unmarshal

func (cfg *Config) Unmarshal(componentParser *confmap.Conf) error

type RoutingConfig

type RoutingConfig struct {
	// Rules is a list of routing rules that map resource attributes to endpoint properties.
	Rules []RoutingRule `mapstructure:"rules"`
}

RoutingConfig defines the routing configuration for directing telemetry to exporters.

type RoutingRule

type RoutingRule struct {
	// ResourceAttribute is the resource attribute key to match (e.g., "k8s.pod.labels.app")
	ResourceAttribute string `mapstructure:"resource_attribute"`
	// EndpointProperty is the endpoint property to match against (e.g., "labels.app", "spec.region")
	// Supports dot notation for nested fields
	EndpointProperty string `mapstructure:"endpoint_property"`
}

RoutingRule defines a mapping between a resource attribute and an endpoint property.

Directories

Path Synopsis
internal
sharedcomponent
Package sharedcomponent exposes util functionality for receivers and exporters that need to share state between different signal types instances such as net.Listener or os.File.
Package sharedcomponent exposes util functionality for receivers and exporters that need to share state between different signal types instances such as net.Listener or os.File.

Jump to

Keyboard shortcuts

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