Files
155fb0264e [Exporterhelper Exporter] Enable metadata population in exporterhelper when sending_queue is enabled (#14139)
#### Description
Feature: The enablement of the sending_queue in the configuration of the
otplhttp exporter does not preserve the metadata information of the
initial context.

This pr introduces a new configuration called `metadata_keys` that will
be used in the exporter config

#### Testing

- Added partionetr_test 

- Built my local otlp exporter

Configuration of otlphttp:

```yaml
otlphttp:
  endpoint: https://endpoint.invalid/_otlp
  timeout: {{ .http_request_timeout | quote }}
  sending_queue:
    enabled: true
    wait_for_result: false
    block_on_overflow: true  # false = data loss on queue full
    sizer: requests
    queue_size: {{ .queuedRequests }}
    batch:
      partition:
        metadata_keys:
          - project-id
          - tenant-id
```

See "ProjectID":"local" that is populated below in my logs
```yaml
{"log.level":"info","@timestamp":"2025-11-06T15:51:49.955Z","message":"ecpRoutingRoundTripper: after URL modification","resource":{"cloud.availability_zone":"local","k8s.namespace.name":"motel-index-collector","k8s.node.name":"hotel-worker2","k8s.pod.name":"motel-index-collector-local-58484b67c8-l4vrt","k8s.pod.uid":"1a8f6fad-91b6-413a-a929-6d004ca489b3","orchestrator.cluster.name":"default","orchestrator.deploymentslice":"","orchestrator.environment":"default","service.instance.id":"ecf43bce-5aac-444c-b244-8871bbf2d69a","service.name":"motel-index-collector","service.version":"git"},"otelcol.component.id":"ecproutingmiddleware","otelcol.component.kind":"extension","final_url_host":"local.es.svc.cluster.local:9200","final_url_scheme":"http","final_url":"[http://local.es.svc.cluster.local:9200/_otlp/v1/metrics","final_host":"","ProjectID":"local","header_count":6,"ecs.version":"1.6.0"}](http://local.es.svc.cluster.local:9200/_otlp/v1/metrics%22,%22final_host%22:%22%22,%22ProjectID%22:%22local%22,%22header_count%22:6,%22ecs.version%22:%221.6.0%22%7D)
```

This PR is a feature for exporterhelper, so is not just
otlphttp-specific.

---------

Signed-off-by: Andreas Gkizas <[email protected]>
Co-authored-by: Andrew Wilkins <[email protected]>
2026-02-26 16:50:58 +00:00

92 lines
4.5 KiB
Go

// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package xexporterhelper // import "go.opentelemetry.io/collector/exporter/exporterhelper/xexporterhelper"
import (
"context"
"go.opentelemetry.io/collector/config/configoptional"
"go.opentelemetry.io/collector/exporter"
"go.opentelemetry.io/collector/exporter/exporterhelper"
"go.opentelemetry.io/collector/exporter/exporterhelper/internal"
"go.opentelemetry.io/collector/exporter/exporterhelper/internal/queuebatch"
"go.opentelemetry.io/collector/pdata/plog"
"go.opentelemetry.io/collector/pdata/pmetric"
"go.opentelemetry.io/collector/pdata/ptrace"
)
// NewLogsRequest creates new logs exporter based on custom LogsConverter and Sender.
// Experimental: This API is at the early stage of development and may change without backward compatibility
// until https://github.com/open-telemetry/opentelemetry-collector/issues/8122 is resolved.
func NewLogsRequest(
ctx context.Context,
set exporter.Settings,
converter RequestConverterFunc[plog.Logs],
pusher RequestConsumeFunc,
options ...exporterhelper.Option,
) (exporter.Logs, error) {
return internal.NewLogsRequest(ctx, set, converter, pusher, options...)
}
// NewMetricsRequest creates new metrics exporter based on custom MetricsConverter and Sender.
// Experimental: This API is at the early stage of development and may change without backward compatibility
// until https://github.com/open-telemetry/opentelemetry-collector/issues/8122 is resolved.
func NewMetricsRequest(
ctx context.Context,
set exporter.Settings,
converter RequestConverterFunc[pmetric.Metrics],
pusher RequestConsumeFunc,
options ...exporterhelper.Option,
) (exporter.Metrics, error) {
return internal.NewMetricsRequest(ctx, set, converter, pusher, options...)
}
// NewTracesRequest creates new traces exporter based on custom TracesConverter and Sender.
// Experimental: This API is at the early stage of development and may change without backward compatibility
// until https://github.com/open-telemetry/opentelemetry-collector/issues/8122 is resolved.
func NewTracesRequest(
ctx context.Context,
set exporter.Settings,
converter RequestConverterFunc[ptrace.Traces],
pusher RequestConsumeFunc,
options ...exporterhelper.Option,
) (exporter.Traces, error) {
return internal.NewTracesRequest(ctx, set, converter, pusher, options...)
}
// QueueBatchSettings are settings for the QueueBatch component.
// They include things line Encoding to be used with persistent queue, or the available Sizers, etc.
type QueueBatchSettings = queuebatch.Settings[Request]
// NewMetricsQueueBatchSettings returns a new QueueBatchSettings to configure to WithQueueBatch when using pmetric.Metrics.
// Experimental: This API is at the early stage of development and may change without backward compatibility
// until https://github.com/open-telemetry/opentelemetry-collector/issues/8122 is resolved.
func NewMetricsQueueBatchSettings() QueueBatchSettings {
return queuebatch.NewMetricsQueueBatchSettings()
}
// NewLogsQueueBatchSettings returns a new QueueBatchSettings to configure to WithQueueBatch when using plog.Logs.
// Experimental: This API is at the early stage of development and may change without backward compatibility
// until https://github.com/open-telemetry/opentelemetry-collector/issues/8122 is resolved.
func NewLogsQueueBatchSettings() QueueBatchSettings {
return queuebatch.NewLogsQueueBatchSettings()
}
// NewTracesQueueBatchSettings returns a new QueueBatchSettings to configure to WithQueueBatch when using ptrace.Traces.
// Experimental: This API is at the early stage of development and may change without backward compatibility
// until https://github.com/open-telemetry/opentelemetry-collector/issues/8122 is resolved.
func NewTracesQueueBatchSettings() QueueBatchSettings {
return queuebatch.NewTracesQueueBatchSettings()
}
// WithQueueBatch enables queueing and batching for an exporter.
// This option should be used with the new exporter helpers New[Traces|Metrics|Logs]RequestExporter.
// If batch.partition.MetadataKeys is set, it will automatically configure the partitioner and merge function
// to partition batches based on the specified metadata keys.
// Experimental: This API is at the early stage of development and may change without backward compatibility
// until https://github.com/open-telemetry/opentelemetry-collector/issues/8122 is resolved.
func WithQueueBatch(cfg configoptional.Optional[exporterhelper.QueueBatchConfig], set QueueBatchSettings) exporterhelper.Option {
return internal.WithQueueBatch(cfg, set)
}