Documentation
¶
Overview ¶
Package lookupprocessor contains a processor that enriches telemetry data by performing lookups from various sources and adding the results as attributes.
Built-in Sources ¶
Sources are configured via the processor's configuration using the source.type field.
Third-party Sources ¶
Custom sources can be registered using NewFactoryWithOptions with WithSources. The public API for creating custom sources is in the lookupsource subpackage. See lookupsource.NewSourceFactory and lookupsource.NewSource for details.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Type = metadata.Type
Functions ¶
func NewFactory ¶
func NewFactoryWithOptions ¶
func NewFactoryWithOptions(options ...FactoryOption) processor.Factory
NewFactoryWithOptions creates a lookup processor factory with custom sources.
Example (third-party HTTP source):
import (
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/lookupprocessor"
"github.com/user/otel-lookup-http/httplookup"
)
factories.Processors[lookupprocessor.Type] = lookupprocessor.NewFactoryWithOptions(
lookupprocessor.WithSources(httplookup.NewFactory()),
)
Types ¶
type AttributeMapping ¶ added in v0.146.0
type AttributeMapping struct {
// Source is the field name in the lookup result for map results.
// Leave empty for 1:1 scalar lookups.
// Optional.
Source string `mapstructure:"source"`
// Destination is the attribute key to write the result to.
// Required.
Destination string `mapstructure:"destination"`
// Default is the value to use when the lookup returns no result.
// If not set and the lookup fails, no attribute is written.
// Optional.
Default string `mapstructure:"default"`
// Context overrides the parent LookupConfig context for this mapping.
// Valid values: "record", "resource".
// Default: inherits from parent LookupConfig.
Context ContextID `mapstructure:"context"`
}
AttributeMapping defines where to write a lookup result.
func (*AttributeMapping) GetContext ¶ added in v0.146.0
func (m *AttributeMapping) GetContext(parent ContextID) ContextID
GetContext returns the context for this mapping, falling back to the parent context.
type Config ¶
type Config struct {
Source SourceConfig `mapstructure:"source"`
// Lookups defines the lookup rules.
// Each rule specifies a key expression to extract the lookup value,
// and one or more attribute mappings for where to write the results.
Lookups []LookupConfig `mapstructure:"lookups"`
}
type ContextID ¶ added in v0.146.0
type ContextID string
ContextID specifies where to apply the lookup.
func (*ContextID) UnmarshalText ¶ added in v0.146.0
type FactoryOption ¶
type FactoryOption func(*lookupProcessorFactory)
func WithSources ¶
func WithSources(factories ...lookupsource.SourceFactory) FactoryOption
WithSources adds custom source factories to the processor. This REPLACES the default sources on first call, then MERGES on subsequent calls. (Same pattern as transform processor's WithXxxFunctions)
Example:
lookupprocessor.NewFactoryWithOptions(
lookupprocessor.WithSources(httplookup.NewFactory()),
)
type LookupConfig ¶ added in v0.146.0
type LookupConfig struct {
// Key is an OTTL value expression for extracting the lookup key.
// Examples: attributes["user.id"], Trim(attributes["raw.id"]),
// resource.attributes["service.name"]
// Required.
Key string `mapstructure:"key"`
// Context is the default context for destination attributes.
// Valid values: "record", "resource".
// Default: "record"
Context ContextID `mapstructure:"context"`
// Attributes defines where to write lookup results.
// Required: at least one mapping.
Attributes []AttributeMapping `mapstructure:"attributes"`
}
LookupConfig defines a single lookup rule.
func (*LookupConfig) GetContext ¶ added in v0.146.0
func (l *LookupConfig) GetContext() ContextID
GetContext returns the context for this lookup, defaulting to ContextRecord.
type SourceConfig ¶
type SourceConfig struct {
// Type is the source type identifier (e.g., "noop", "yaml").
Type string `mapstructure:"type"`
// Config holds the source-specific configuration as raw map.
// It is decoded into the source's typed config struct by the factory
// at processor creation time.
Config map[string]any `mapstructure:",remain"`
}
SourceConfig captures the source type and its opaque settings.
Source-specific fields are collected into Config via mapstructure's ",remain" tag and decoded later in the factory's createSource using a mapstructure decoder. An alternative would be to implement confmap.Unmarshaler on Config (like geoipprocessor does) to resolve the source config at unmarshal time. We defer decoding to the factory because the set of available source factories is not known until the factory is constructed (custom sources can be injected via WithSources), so the config layer cannot look up the correct factory. Both paths run during collector startup, so validation timing is equivalent in practice.
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
metadata
Package metadata contains the autogenerated telemetry and build information for the processor/lookup component.
|
Package metadata contains the autogenerated telemetry and build information for the processor/lookup component. |
|
source/dns
Package dns provides a DNS-based lookup source.
|
Package dns provides a DNS-based lookup source. |
|
source/noop
Package noop provides a no-operation lookup source for testing.
|
Package noop provides a no-operation lookup source for testing. |
|
source/yaml
Package yaml provides a YAML file-based lookup source.
|
Package yaml provides a YAML file-based lookup source. |
|
Package lookupsource provides the public API for creating lookup sources.
|
Package lookupsource provides the public API for creating lookup sources. |