Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .chloggen/dep-separate-converter.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: deprecation

# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
component: exporterhelper

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Deprecate per signal converter in favor of generic version

# One or more tracking issues or pull requests related to the change
issues: [12631]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [api]
12 changes: 5 additions & 7 deletions exporter/exporterhelper/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,11 @@ func NewLogs(
return NewLogsRequest(ctx, set, requestFromLogs(pusher), append([]Option{internal.WithEncoding(&logsEncoding{pusher: pusher})}, options...)...)
}

// RequestFromLogsFunc converts plog.Logs data into a user-defined request.
// 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.
type RequestFromLogsFunc func(context.Context, plog.Logs) (Request, error)
// Deprecated: [v0.122.0] use RequestConverterFunc[plog.Logs].
type RequestFromLogsFunc = RequestConverterFunc[plog.Logs]

// requestFromLogs returns a RequestFromLogsFunc that converts plog.Logs into a Request.
func requestFromLogs(pusher consumer.ConsumeLogsFunc) RequestFromLogsFunc {
func requestFromLogs(pusher consumer.ConsumeLogsFunc) RequestConverterFunc[plog.Logs] {
return func(_ context.Context, ld plog.Logs) (Request, error) {
return newLogsRequest(ld, pusher), nil
}
Expand All @@ -121,7 +119,7 @@ func requestFromLogs(pusher consumer.ConsumeLogsFunc) RequestFromLogsFunc {
func NewLogsRequest(
_ context.Context,
set exporter.Settings,
converter RequestFromLogsFunc,
converter RequestConverterFunc[plog.Logs],
options ...Option,
) (exporter.Logs, error) {
if set.Logger == nil {
Expand All @@ -145,7 +143,7 @@ func NewLogsRequest(
return &logsExporter{BaseExporter: be, Logs: lc}, nil
}

func newConsumeLogs(converter RequestFromLogsFunc, be *internal.BaseExporter, logger *zap.Logger) consumer.ConsumeLogsFunc {
func newConsumeLogs(converter RequestConverterFunc[plog.Logs], be *internal.BaseExporter, logger *zap.Logger) consumer.ConsumeLogsFunc {
return func(ctx context.Context, ld plog.Logs) error {
req, err := converter(ctx, ld)
if err != nil {
Expand Down
12 changes: 5 additions & 7 deletions exporter/exporterhelper/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,11 @@ func NewMetrics(
return NewMetricsRequest(ctx, set, requestFromMetrics(pusher), append([]Option{internal.WithEncoding(&metricsEncoding{pusher: pusher})}, options...)...)
}

// RequestFromMetricsFunc converts pdata.Metrics into a user-defined request.
// 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.
type RequestFromMetricsFunc func(context.Context, pmetric.Metrics) (Request, error)
// Deprecated: [v0.122.0] use RequestConverterFunc[pmetric.Metrics].
type RequestFromMetricsFunc = RequestConverterFunc[pmetric.Metrics]

// requestFromMetrics returns a RequestFromMetricsFunc that converts pdata.Metrics into a Request.
func requestFromMetrics(pusher consumer.ConsumeMetricsFunc) RequestFromMetricsFunc {
func requestFromMetrics(pusher consumer.ConsumeMetricsFunc) RequestConverterFunc[pmetric.Metrics] {
return func(_ context.Context, md pmetric.Metrics) (Request, error) {
return newMetricsRequest(md, pusher), nil
}
Expand All @@ -121,7 +119,7 @@ func requestFromMetrics(pusher consumer.ConsumeMetricsFunc) RequestFromMetricsFu
func NewMetricsRequest(
_ context.Context,
set exporter.Settings,
converter RequestFromMetricsFunc,
converter RequestConverterFunc[pmetric.Metrics],
options ...Option,
) (exporter.Metrics, error) {
if set.Logger == nil {
Expand All @@ -145,7 +143,7 @@ func NewMetricsRequest(
return &metricsExporter{BaseExporter: be, Metrics: mc}, nil
}

func newConsumeMetrics(converter RequestFromMetricsFunc, be *internal.BaseExporter, logger *zap.Logger) consumer.ConsumeMetricsFunc {
func newConsumeMetrics(converter RequestConverterFunc[pmetric.Metrics], be *internal.BaseExporter, logger *zap.Logger) consumer.ConsumeMetricsFunc {
return func(ctx context.Context, md pmetric.Metrics) error {
req, err := converter(ctx, md)
if err != nil {
Expand Down
7 changes: 7 additions & 0 deletions exporter/exporterhelper/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package exporterhelper // import "go.opentelemetry.io/collector/exporter/exporterhelper"

import (
"context"

"go.opentelemetry.io/collector/exporter/exporterhelper/internal/request"
)

Expand All @@ -19,3 +21,8 @@ type Request = request.Request
// 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.
type RequestErrorHandler = request.ErrorHandler

// RequestConverterFunc converts pdata telemetry into a user-defined Request.
// 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.
type RequestConverterFunc[K any] func(context.Context, K) (Request, error)
14 changes: 6 additions & 8 deletions exporter/exporterhelper/traces.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,11 @@ func NewTraces(
return NewTracesRequest(ctx, set, requestFromTraces(pusher), append([]Option{internal.WithEncoding(&tracesEncoding{pusher: pusher})}, options...)...)
}

// RequestFromTracesFunc converts ptrace.Traces into a user-defined Request.
// 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.
type RequestFromTracesFunc func(context.Context, ptrace.Traces) (Request, error)
// Deprecated: [v0.122.0] use RequestConverterFunc[ptrace.Traces].
type RequestFromTracesFunc = RequestConverterFunc[ptrace.Traces]

// requestFromTraces returns a RequestFromTracesFunc that converts ptrace.Traces into a Request.
func requestFromTraces(pusher consumer.ConsumeTracesFunc) RequestFromTracesFunc {
// requestFromTraces returns a RequestConverterFunc that converts ptrace.Traces into a Request.
func requestFromTraces(pusher consumer.ConsumeTracesFunc) RequestConverterFunc[ptrace.Traces] {
return func(_ context.Context, traces ptrace.Traces) (Request, error) {
return newTracesRequest(traces, pusher), nil
}
Expand All @@ -113,7 +111,7 @@ func requestFromTraces(pusher consumer.ConsumeTracesFunc) RequestFromTracesFunc
func NewTracesRequest(
_ context.Context,
set exporter.Settings,
converter RequestFromTracesFunc,
converter RequestConverterFunc[ptrace.Traces],
options ...Option,
) (exporter.Traces, error) {
if set.Logger == nil {
Expand All @@ -137,7 +135,7 @@ func NewTracesRequest(
return &tracesExporter{BaseExporter: be, Traces: tc}, nil
}

func newConsumeTraces(converter RequestFromTracesFunc, be *internal.BaseExporter, logger *zap.Logger) consumer.ConsumeTracesFunc {
func newConsumeTraces(converter RequestConverterFunc[ptrace.Traces], be *internal.BaseExporter, logger *zap.Logger) consumer.ConsumeTracesFunc {
return func(ctx context.Context, td ptrace.Traces) error {
req, err := converter(ctx, td)
if err != nil {
Expand Down
12 changes: 5 additions & 7 deletions exporter/exporterhelper/xexporterhelper/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,11 @@ func NewProfilesExporter(
return NewProfilesRequestExporter(ctx, set, requestFromProfiles(pusher), append(opts, options...)...)
}

// RequestFromProfilesFunc converts pprofile.Profiles into a user-defined Request.
// 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.
type RequestFromProfilesFunc func(context.Context, pprofile.Profiles) (exporterhelper.Request, error)
// Deprecated: [v0.122.0] use exporterhelper.RequestConverterFunc[pprofile.Profiles].
type RequestFromProfilesFunc = exporterhelper.RequestConverterFunc[pprofile.Profiles]

// requestFromProfiles returns a RequestFromProfilesFunc that converts pprofile.Profiles into a Request.
func requestFromProfiles(pusher xconsumer.ConsumeProfilesFunc) RequestFromProfilesFunc {
func requestFromProfiles(pusher xconsumer.ConsumeProfilesFunc) exporterhelper.RequestConverterFunc[pprofile.Profiles] {
return func(_ context.Context, profiles pprofile.Profiles) (exporterhelper.Request, error) {
return newProfilesRequest(profiles, pusher), nil
}
Expand All @@ -117,7 +115,7 @@ func requestFromProfiles(pusher xconsumer.ConsumeProfilesFunc) RequestFromProfil
func NewProfilesRequestExporter(
_ context.Context,
set exporter.Settings,
converter RequestFromProfilesFunc,
converter exporterhelper.RequestConverterFunc[pprofile.Profiles],
options ...exporterhelper.Option,
) (xexporter.Profiles, error) {
if set.Logger == nil {
Expand All @@ -141,7 +139,7 @@ func NewProfilesRequestExporter(
return &profileExporter{BaseExporter: be, Profiles: tc}, nil
}

func newConsumeProfiles(converter RequestFromProfilesFunc, be *internal.BaseExporter, logger *zap.Logger) xconsumer.ConsumeProfilesFunc {
func newConsumeProfiles(converter exporterhelper.RequestConverterFunc[pprofile.Profiles], be *internal.BaseExporter, logger *zap.Logger) xconsumer.ConsumeProfilesFunc {
return func(ctx context.Context, pd pprofile.Profiles) error {
req, err := converter(ctx, pd)
if err != nil {
Expand Down
Loading