@@ -5,6 +5,7 @@ package connector // import "go.opentelemetry.io/collector/connector"
55
66import (
77 "context"
8+ "errors"
89 "fmt"
910
1011 "go.uber.org/zap"
@@ -13,6 +14,10 @@ import (
1314 "go.opentelemetry.io/collector/consumer"
1415)
1516
17+ var (
18+ errNilNextConsumer = errors .New ("nil next Consumer" )
19+ )
20+
1621// A Traces connector acts as an exporter from a traces pipeline and a receiver
1722// to one or more traces, metrics, or logs pipelines.
1823// Traces feeds a consumer.Traces, consumer.Metrics, or consumer.Logs with data.
@@ -456,6 +461,9 @@ func NewBuilder(cfgs map[component.ID]component.Config, factories map[component.
456461
457462// CreateTracesToTraces creates a Traces connector based on the settings and config.
458463func (b * Builder ) CreateTracesToTraces (ctx context.Context , set CreateSettings , next consumer.Traces ) (Traces , error ) {
464+ if next == nil {
465+ return nil , errNilNextConsumer
466+ }
459467 cfg , existsCfg := b .cfgs [set .ID ]
460468 if ! existsCfg {
461469 return nil , fmt .Errorf ("connector %q is not configured" , set .ID )
@@ -472,6 +480,9 @@ func (b *Builder) CreateTracesToTraces(ctx context.Context, set CreateSettings,
472480
473481// CreateTracesToMetrics creates a Traces connector based on the settings and config.
474482func (b * Builder ) CreateTracesToMetrics (ctx context.Context , set CreateSettings , next consumer.Metrics ) (Traces , error ) {
483+ if next == nil {
484+ return nil , errNilNextConsumer
485+ }
475486 cfg , existsCfg := b .cfgs [set .ID ]
476487 if ! existsCfg {
477488 return nil , fmt .Errorf ("connector %q is not configured" , set .ID )
@@ -488,6 +499,9 @@ func (b *Builder) CreateTracesToMetrics(ctx context.Context, set CreateSettings,
488499
489500// CreateTracesToLogs creates a Traces connector based on the settings and config.
490501func (b * Builder ) CreateTracesToLogs (ctx context.Context , set CreateSettings , next consumer.Logs ) (Traces , error ) {
502+ if next == nil {
503+ return nil , errNilNextConsumer
504+ }
491505 cfg , existsCfg := b .cfgs [set .ID ]
492506 if ! existsCfg {
493507 return nil , fmt .Errorf ("connector %q is not configured" , set .ID )
@@ -504,6 +518,9 @@ func (b *Builder) CreateTracesToLogs(ctx context.Context, set CreateSettings, ne
504518
505519// CreateMetricsToTraces creates a Metrics connector based on the settings and config.
506520func (b * Builder ) CreateMetricsToTraces (ctx context.Context , set CreateSettings , next consumer.Traces ) (Metrics , error ) {
521+ if next == nil {
522+ return nil , errNilNextConsumer
523+ }
507524 cfg , existsCfg := b .cfgs [set .ID ]
508525 if ! existsCfg {
509526 return nil , fmt .Errorf ("connector %q is not configured" , set .ID )
@@ -520,6 +537,9 @@ func (b *Builder) CreateMetricsToTraces(ctx context.Context, set CreateSettings,
520537
521538// CreateMetricsToMetrics creates a Metrics connector based on the settings and config.
522539func (b * Builder ) CreateMetricsToMetrics (ctx context.Context , set CreateSettings , next consumer.Metrics ) (Metrics , error ) {
540+ if next == nil {
541+ return nil , errNilNextConsumer
542+ }
523543 cfg , existsCfg := b .cfgs [set .ID ]
524544 if ! existsCfg {
525545 return nil , fmt .Errorf ("connector %q is not configured" , set .ID )
@@ -536,6 +556,9 @@ func (b *Builder) CreateMetricsToMetrics(ctx context.Context, set CreateSettings
536556
537557// CreateMetricsToLogs creates a Metrics connector based on the settings and config.
538558func (b * Builder ) CreateMetricsToLogs (ctx context.Context , set CreateSettings , next consumer.Logs ) (Metrics , error ) {
559+ if next == nil {
560+ return nil , errNilNextConsumer
561+ }
539562 cfg , existsCfg := b .cfgs [set .ID ]
540563 if ! existsCfg {
541564 return nil , fmt .Errorf ("connector %q is not configured" , set .ID )
@@ -552,6 +575,9 @@ func (b *Builder) CreateMetricsToLogs(ctx context.Context, set CreateSettings, n
552575
553576// CreateLogsToTraces creates a Logs connector based on the settings and config.
554577func (b * Builder ) CreateLogsToTraces (ctx context.Context , set CreateSettings , next consumer.Traces ) (Logs , error ) {
578+ if next == nil {
579+ return nil , errNilNextConsumer
580+ }
555581 cfg , existsCfg := b .cfgs [set .ID ]
556582 if ! existsCfg {
557583 return nil , fmt .Errorf ("connector %q is not configured" , set .ID )
@@ -568,6 +594,9 @@ func (b *Builder) CreateLogsToTraces(ctx context.Context, set CreateSettings, ne
568594
569595// CreateLogsToMetrics creates a Logs connector based on the settings and config.
570596func (b * Builder ) CreateLogsToMetrics (ctx context.Context , set CreateSettings , next consumer.Metrics ) (Logs , error ) {
597+ if next == nil {
598+ return nil , errNilNextConsumer
599+ }
571600 cfg , existsCfg := b .cfgs [set .ID ]
572601 if ! existsCfg {
573602 return nil , fmt .Errorf ("connector %q is not configured" , set .ID )
@@ -584,6 +613,9 @@ func (b *Builder) CreateLogsToMetrics(ctx context.Context, set CreateSettings, n
584613
585614// CreateLogsToLogs creates a Logs connector based on the settings and config.
586615func (b * Builder ) CreateLogsToLogs (ctx context.Context , set CreateSettings , next consumer.Logs ) (Logs , error ) {
616+ if next == nil {
617+ return nil , errNilNextConsumer
618+ }
587619 cfg , existsCfg := b .cfgs [set .ID ]
588620 if ! existsCfg {
589621 return nil , fmt .Errorf ("connector %q is not configured" , set .ID )
0 commit comments