Skip to content

Commit 08a6922

Browse files
authored
[component] Deprecate ErrNilNextConsumer (#9526)
**Description:** Deprecate ErrNilNextConsumer and implement nil checks in the builder structs.
1 parent 063f5dd commit 08a6922

20 files changed

+275
-216
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: deprecation
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
7+
component: component
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: deprecate component.ErrNilNextConsumer
11+
12+
# One or more tracking issues or pull requests related to the change
13+
issues: [9526]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# Optional: The change log or logs in which this entry should be included.
21+
# e.g. '[user]' or '[user, api]'
22+
# Include 'user' if the change is relevant to end users.
23+
# Include 'api' if there is a change to a library API.
24+
# Default: '[user]'
25+
change_logs: [api]

component/component.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111
var (
1212
// ErrNilNextConsumer can be returned by receiver, or processor Start factory funcs that create the Component if the
1313
// expected next Consumer is nil.
14+
// Deprecated: [v0.96.0] The next consumer is now checked as part of the creation of the pipelines.
15+
// This error will be removed in a future release.
1416
ErrNilNextConsumer = errors.New("nil next Consumer")
1517

1618
// ErrDataTypeIsNotSupported can be returned by receiver, exporter or processor factory funcs that create the

connector/connector.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package connector // import "go.opentelemetry.io/collector/connector"
55

66
import (
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.
458463
func (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.
474482
func (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.
490501
func (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.
506520
func (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.
522539
func (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.
538558
func (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.
554577
func (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.
570596
func (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.
586615
func (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

Comments
 (0)