| 1 |
// Copyright The OpenTelemetry Authors |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
package forwardconnector // import "go.opentelemetry.io/collector/connector/forwardconnector" |
| 5 |
|
| 6 |
import ( |
| 7 |
"context" |
| 8 |
|
| 9 |
"go.opentelemetry.io/collector/component" |
| 10 |
"go.opentelemetry.io/collector/connector" |
| 11 |
"go.opentelemetry.io/collector/connector/forwardconnector/internal/metadata" |
| 12 |
"go.opentelemetry.io/collector/connector/xconnector" |
| 13 |
"go.opentelemetry.io/collector/consumer" |
| 14 |
"go.opentelemetry.io/collector/consumer/xconsumer" |
| 15 |
) |
| 16 |
|
| 17 |
// NewFactory returns a connector.Factory. |
| 18 |
func NewFactory() xconnector.Factory { |
| 19 |
return xconnector.NewFactory( |
| 20 |
metadata.Type, |
| 21 |
createDefaultConfig, |
| 22 |
xconnector.WithTracesToTraces(createTracesToTraces, metadata.TracesToTracesStability), |
| 23 |
xconnector.WithMetricsToMetrics(createMetricsToMetrics, metadata.MetricsToMetricsStability), |
| 24 |
xconnector.WithLogsToLogs(createLogsToLogs, metadata.LogsToLogsStability), |
| 25 |
xconnector.WithProfilesToProfiles(createProfilesToProfiles, metadata.ProfilesToProfilesStability), |
| 26 |
) |
| 27 |
} |
| 28 |
|
| 29 |
type Config struct{} |
| 30 |
|
| 31 |
// createDefaultConfig creates the default configuration. |
| 32 |
func createDefaultConfig() component.Config { |
| 33 |
return &Config{} |
| 34 |
} |
| 35 |
|
| 36 |
// createTracesToTraces creates a trace receiver based on provided config. |
| 37 |
func createTracesToTraces( |
| 38 |
_ context.Context, |
| 39 |
_ connector.Settings, |
| 40 |
_ component.Config, |
| 41 |
nextConsumer consumer.Traces, |
| 42 |
) (connector.Traces, error) { |
| 43 |
return &forward{Traces: nextConsumer}, nil |
| 44 |
} |
| 45 |
|
| 46 |
// createMetricsToMetrics creates a metrics receiver based on provided config. |
| 47 |
func createMetricsToMetrics( |
| 48 |
_ context.Context, |
| 49 |
_ connector.Settings, |
| 50 |
_ component.Config, |
| 51 |
nextConsumer consumer.Metrics, |
| 52 |
) (connector.Metrics, error) { |
| 53 |
return &forward{Metrics: nextConsumer}, nil |
| 54 |
} |
| 55 |
|
| 56 |
// createLogsToLogs creates a log receiver based on provided config. |
| 57 |
func createLogsToLogs( |
| 58 |
_ context.Context, |
| 59 |
_ connector.Settings, |
| 60 |
_ component.Config, |
| 61 |
nextConsumer consumer.Logs, |
| 62 |
) (connector.Logs, error) { |
| 63 |
return &forward{Logs: nextConsumer}, nil |
| 64 |
} |
| 65 |
|
| 66 |
// createProfilesToProfiles creates a profile receiver based on provided config. |
| 67 |
func createProfilesToProfiles( |
| 68 |
_ context.Context, |
| 69 |
_ connector.Settings, |
| 70 |
_ component.Config, |
| 71 |
nextConsumer xconsumer.Profiles, |
| 72 |
) (xconnector.Profiles, error) { |
| 73 |
return &forward{Profiles: nextConsumer}, nil |
| 74 |
} |
| 75 |
|
| 76 |
// forward is used to pass signals directly from one pipeline to another. |
| 77 |
// This is useful when there is a need to replicate data and process it in more |
| 78 |
// than one way. It can also be used to join pipelines together. |
| 79 |
type forward struct { |
| 80 |
consumer.Traces |
| 81 |
consumer.Metrics |
| 82 |
consumer.Logs |
| 83 |
xconsumer.Profiles |
| 84 |
component.StartFunc |
| 85 |
component.ShutdownFunc |
| 86 |
} |
| 87 |
|
| 88 |
func (c *forward) Capabilities() consumer.Capabilities { |
| 89 |
return consumer.Capabilities{MutatesData: false} |
| 90 |
} |