Skip to content

Commit

Permalink
Deprecate unused and empty struct processorhelper.ObsReport (open-tel…
Browse files Browse the repository at this point in the history
…emetry#11293)

Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
  • Loading branch information
bogdandrutu authored and jackgopack4 committed Oct 8, 2024
1 parent ea629cc commit 7c4b720
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 32 deletions.
25 changes: 25 additions & 0 deletions .chloggen/dep-processorhelper.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: processorhelper

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Deprecate unused and empty struct processorhelper.ObsReport

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

# (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]
8 changes: 2 additions & 6 deletions processor/processorhelper/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import (
"context"
"errors"

"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/pdata/plog"
"go.opentelemetry.io/collector/pipeline"
"go.opentelemetry.io/collector/processor"
)

Expand Down Expand Up @@ -40,14 +40,10 @@ func NewLogsProcessor(
return nil, errors.New("nil logsFunc")
}

obs, err := newObsReport(ObsReportSettings{
ProcessorID: set.ID,
ProcessorCreateSettings: set,
})
obs, err := newObsReport(set, pipeline.SignalLogs)
if err != nil {
return nil, err
}
obs.otelAttrs = append(obs.otelAttrs, attribute.String("otel.signal", "logs"))

eventOptions := spanAttributes(set.ID)
bs := fromOptions(options)
Expand Down
8 changes: 2 additions & 6 deletions processor/processorhelper/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import (
"context"
"errors"

"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/pdata/pmetric"
"go.opentelemetry.io/collector/pipeline"
"go.opentelemetry.io/collector/processor"
)

Expand Down Expand Up @@ -40,14 +40,10 @@ func NewMetricsProcessor(
return nil, errors.New("nil metricsFunc")
}

obs, err := newObsReport(ObsReportSettings{
ProcessorID: set.ID,
ProcessorCreateSettings: set,
})
obs, err := newObsReport(set, pipeline.SignalMetrics)
if err != nil {
return nil, err
}
obs.otelAttrs = append(obs.otelAttrs, attribute.String("otel.signal", "metrics"))

eventOptions := spanAttributes(set.ID)
bs := fromOptions(options)
Expand Down
32 changes: 18 additions & 14 deletions processor/processorhelper/obsreport.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"go.opentelemetry.io/otel/metric"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/pipeline"
"go.opentelemetry.io/collector/processor"
"go.opentelemetry.io/collector/processor/internal"
"go.opentelemetry.io/collector/processor/processorhelper/internal/metadata"
Expand All @@ -30,37 +31,40 @@ func BuildCustomMetricName(configType, metric string) string {
return componentPrefix + configType + internal.MetricNameSep + metric
}

// ObsReport is a helper to add observability to a processor.
type ObsReport struct {
otelAttrs []attribute.KeyValue
telemetryBuilder *metadata.TelemetryBuilder
}
// Deprecated: [v0.111.0] not used.
type ObsReport struct{}

// ObsReportSettings are settings for creating an ObsReport.
// Deprecated: [v0.111.0] not used.
type ObsReportSettings struct {
ProcessorID component.ID
ProcessorCreateSettings processor.Settings
}

// NewObsReport creates a new Processor.
func NewObsReport(cfg ObsReportSettings) (*ObsReport, error) {
return newObsReport(cfg)
// Deprecated: [v0.111.0] not used.
func NewObsReport(_ ObsReportSettings) (*ObsReport, error) {
return &ObsReport{}, nil
}

type obsReport struct {
otelAttrs []attribute.KeyValue
telemetryBuilder *metadata.TelemetryBuilder
}

func newObsReport(cfg ObsReportSettings) (*ObsReport, error) {
telemetryBuilder, err := metadata.NewTelemetryBuilder(cfg.ProcessorCreateSettings.TelemetrySettings)
func newObsReport(set processor.Settings, signal pipeline.Signal) (*obsReport, error) {
telemetryBuilder, err := metadata.NewTelemetryBuilder(set.TelemetrySettings)
if err != nil {
return nil, err
}
return &ObsReport{
return &obsReport{
otelAttrs: []attribute.KeyValue{
attribute.String(internal.ProcessorKey, cfg.ProcessorID.String()),
attribute.String(internal.ProcessorKey, set.ID.String()),
attribute.String("otel.signal", signal.String()),
},
telemetryBuilder: telemetryBuilder,
}, nil
}

func (or *ObsReport) recordInOut(ctx context.Context, incoming, outgoing int) {
func (or *obsReport) recordInOut(ctx context.Context, incoming, outgoing int) {
or.telemetryBuilder.ProcessorIncomingItems.Add(ctx, int64(incoming), metric.WithAttributes(or.otelAttrs...))
or.telemetryBuilder.ProcessorOutgoingItems.Add(ctx, int64(outgoing), metric.WithAttributes(or.otelAttrs...))
}
8 changes: 2 additions & 6 deletions processor/processorhelper/traces.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import (
"context"
"errors"

"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/pdata/ptrace"
"go.opentelemetry.io/collector/pipeline"
"go.opentelemetry.io/collector/processor"
)

Expand Down Expand Up @@ -40,14 +40,10 @@ func NewTracesProcessor(
return nil, errors.New("nil tracesFunc")
}

obs, err := newObsReport(ObsReportSettings{
ProcessorID: set.ID,
ProcessorCreateSettings: set,
})
obs, err := newObsReport(set, pipeline.SignalTraces)
if err != nil {
return nil, err
}
obs.otelAttrs = append(obs.otelAttrs, attribute.String("otel.signal", "traces"))

eventOptions := spanAttributes(set.ID)
bs := fromOptions(options)
Expand Down

0 comments on commit 7c4b720

Please sign in to comment.