Skip to main content

Lookup Processor

Status Maintainers: @jsvd, @dehaansa, @VihasMakwana Source: opentelemetry-collector-contrib

Supported Telemetry

Logs Metrics Traces

Overview

Configuration

Full Configuration

Lookup Configuration

Each entry in lookups defines a lookup rule: The key field supports any OTTL value expression, including paths across contexts and converters. The path prefix depends on the signal type: Resource attributes use resource.attributes["..."] for all signals. A context prefix is always required; bare attributes["..."] paths are rejected at configuration time. Examples:
  • attributes["user.id"] - record attribute (works for all signals)
  • log.attributes["user.id"] - log record attribute (logs only)
  • span.attributes["user.id"] - span attribute (traces only)
  • datapoint.attributes["host.id"] - datapoint attribute (metrics only)
  • resource.attributes["service.name"] - resource attribute (all signals)
  • Trim(attributes["raw.id"]) - apply a converter

Attribute Mapping

Each entry in attributes defines where to write a lookup result:

Examples

Scalar Lookup (1:1)

When the source returns a single value per key, leave the source field empty:

Map Lookup (1:N)

When the source returns a map of fields per key, use the source field to extract individual values:

OTTL Converter on Key

The key field supports OTTL converters for transforming the lookup key before querying the source:

Context

  • record: Write to the signal’s record-level attributes (default). This maps to log record attributes for logs, span attributes for traces, and datapoint attributes for metrics. For metrics, lookups are evaluated for each datapoint across all metric types (Gauge, Sum, Histogram, ExponentialHistogram, Summary).
  • resource: Write to resource attributes.
The context field on a key sets the default for all its destination attributes. Each attribute mapping can override this with its own context field. Lookups are evaluated per record. When writing to resource attributes, later records in the same resource may overwrite values written by earlier records.

Built-in Sources

  • noop - No-operation source for testing
  • yaml - Key-value mappings from YAML files (optional periodic reload)
  • csv - Key-value mappings from CSV files, with or without a header (optional periodic reload)
  • dns - DNS lookups with caching

Caching

Sources that support external lookups (like DNS) can use the built-in LRU caching system to reduce latency and external queries. The cache uses a doubly-linked list with a hash map for O(1) lookups, insertions, and evictions.

Cache Configuration

Cache Performance

Run with go test -bench=BenchmarkCache -run=^$ ./lookupsource/ Single-threaded (Apple M4 Pro): Concurrent (12 goroutines):

Using Cache in Custom Sources

Custom sources can use the cache by wrapping their lookup function:

Custom Sources

Custom lookup sources can be added using WithSources:

Source contract

  • Concurrency: Lookup is called concurrently from multiple goroutines. Implementations must be safe for concurrent use.
  • Keys are strings: The OTTL expression result is converted to a string before calling Lookup.
  • Return values: For scalar (1:1) lookups, return any single value. For map (1:N) lookups, return map[string]any. Values are written to attributes via pcommon.Value.FromRaw. Unsupported types are stringified via fmt.Sprintf.
  • Errors are non-fatal: When Lookup returns an error the processor logs it at Debug level and skips the lookup. It does not fail the batch.
  • Lifecycle: Start is called once before any Lookup; Shutdown is called once after all processing stops. Both are optional (pass nil to NewSource).
  • Config tags: Source config structs must use mapstructure struct tags. The processor decodes source configuration from a raw map using mapstructure.

Implementing a Source

Benchmarks

Run benchmarks with:

Processor Performance

Measures the full processing pipeline including OTTL key evaluation, source lookup, value conversion, and attribute writes. Uses noop source to isolate processor overhead from source implementation (Apple M4 Pro):

YAML Source Performance

Measures only the source lookup operation (map access), isolated from processor overhead:
Last generated: 2026-08-24