Skip to content

Commit 06271a6

Browse files
authored
Fix processor metrics not being reported initially with 0 values (#10857)
This change reverts #10693, which had an unintentional behavior change that made the processor helper report metrics only if they got values other than `0`. Fixes #10855
1 parent 643c17e commit 06271a6

File tree

2 files changed

+62
-16
lines changed

2 files changed

+62
-16
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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: bug_fix
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
7+
component: processorhelper
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Fix processor metrics not being reported initially with 0 values.
11+
12+
# One or more tracking issues or pull requests related to the change
13+
issues: [10855]
14+
15+
# Optional: The change log or logs in which this entry should be included.
16+
# e.g. '[user]' or '[user, api]'
17+
# Include 'user' if the change is relevant to end users.
18+
# Include 'api' if there is a change to a library API.
19+
# Default: '[user]'
20+
change_logs: [user]

processor/processorhelper/obsreport.go

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ func BuildCustomMetricName(configType, metric string) string {
3232

3333
// ObsReport is a helper to add observability to a processor.
3434
type ObsReport struct {
35-
otelAttrs []attribute.KeyValue
36-
telBuilder *metadata.TelemetryBuilder
35+
otelAttrs []attribute.KeyValue
36+
telemetryBuilder *metadata.TelemetryBuilder
3737
}
3838

3939
// ObsReportSettings are settings for creating an ObsReport.
@@ -48,74 +48,100 @@ func NewObsReport(cfg ObsReportSettings) (*ObsReport, error) {
4848
}
4949

5050
func newObsReport(cfg ObsReportSettings) (*ObsReport, error) {
51-
telBuilder, err := metadata.NewTelemetryBuilder(cfg.ProcessorCreateSettings.TelemetrySettings, metadata.WithLevel(cfg.ProcessorCreateSettings.MetricsLevel))
51+
telemetryBuilder, err := metadata.NewTelemetryBuilder(cfg.ProcessorCreateSettings.TelemetrySettings, metadata.WithLevel(cfg.ProcessorCreateSettings.MetricsLevel))
5252
if err != nil {
5353
return nil, err
5454
}
5555
return &ObsReport{
5656
otelAttrs: []attribute.KeyValue{
5757
attribute.String(obsmetrics.ProcessorKey, cfg.ProcessorID.String()),
5858
},
59-
telBuilder: telBuilder,
59+
telemetryBuilder: telemetryBuilder,
6060
}, nil
6161
}
6262

63+
func (or *ObsReport) recordData(ctx context.Context, dataType component.DataType, accepted, refused, dropped, inserted int64) {
64+
var acceptedCount, refusedCount, droppedCount, insertedCount metric.Int64Counter
65+
switch dataType {
66+
case component.DataTypeTraces:
67+
acceptedCount = or.telemetryBuilder.ProcessorAcceptedSpans
68+
refusedCount = or.telemetryBuilder.ProcessorRefusedSpans
69+
droppedCount = or.telemetryBuilder.ProcessorDroppedSpans
70+
insertedCount = or.telemetryBuilder.ProcessorInsertedSpans
71+
case component.DataTypeMetrics:
72+
acceptedCount = or.telemetryBuilder.ProcessorAcceptedMetricPoints
73+
refusedCount = or.telemetryBuilder.ProcessorRefusedMetricPoints
74+
droppedCount = or.telemetryBuilder.ProcessorDroppedMetricPoints
75+
insertedCount = or.telemetryBuilder.ProcessorInsertedMetricPoints
76+
case component.DataTypeLogs:
77+
acceptedCount = or.telemetryBuilder.ProcessorAcceptedLogRecords
78+
refusedCount = or.telemetryBuilder.ProcessorRefusedLogRecords
79+
droppedCount = or.telemetryBuilder.ProcessorDroppedLogRecords
80+
insertedCount = or.telemetryBuilder.ProcessorInsertedLogRecords
81+
}
82+
83+
acceptedCount.Add(ctx, accepted, metric.WithAttributes(or.otelAttrs...))
84+
refusedCount.Add(ctx, refused, metric.WithAttributes(or.otelAttrs...))
85+
droppedCount.Add(ctx, dropped, metric.WithAttributes(or.otelAttrs...))
86+
insertedCount.Add(ctx, inserted, metric.WithAttributes(or.otelAttrs...))
87+
}
88+
6389
// TracesAccepted reports that the trace data was accepted.
6490
func (or *ObsReport) TracesAccepted(ctx context.Context, numSpans int) {
65-
or.telBuilder.ProcessorAcceptedSpans.Add(ctx, int64(numSpans), metric.WithAttributes(or.otelAttrs...))
91+
or.recordData(ctx, component.DataTypeTraces, int64(numSpans), int64(0), int64(0), int64(0))
6692
}
6793

6894
// TracesRefused reports that the trace data was refused.
6995
func (or *ObsReport) TracesRefused(ctx context.Context, numSpans int) {
70-
or.telBuilder.ProcessorRefusedSpans.Add(ctx, int64(numSpans), metric.WithAttributes(or.otelAttrs...))
96+
or.recordData(ctx, component.DataTypeTraces, int64(0), int64(numSpans), int64(0), int64(0))
7197
}
7298

7399
// TracesDropped reports that the trace data was dropped.
74100
func (or *ObsReport) TracesDropped(ctx context.Context, numSpans int) {
75-
or.telBuilder.ProcessorDroppedSpans.Add(ctx, int64(numSpans), metric.WithAttributes(or.otelAttrs...))
101+
or.recordData(ctx, component.DataTypeTraces, int64(0), int64(0), int64(numSpans), int64(0))
76102
}
77103

78104
// TracesInserted reports that the trace data was inserted.
79105
func (or *ObsReport) TracesInserted(ctx context.Context, numSpans int) {
80-
or.telBuilder.ProcessorInsertedSpans.Add(ctx, int64(numSpans), metric.WithAttributes(or.otelAttrs...))
106+
or.recordData(ctx, component.DataTypeTraces, int64(0), int64(0), int64(0), int64(numSpans))
81107
}
82108

83109
// MetricsAccepted reports that the metrics were accepted.
84110
func (or *ObsReport) MetricsAccepted(ctx context.Context, numPoints int) {
85-
or.telBuilder.ProcessorAcceptedMetricPoints.Add(ctx, int64(numPoints), metric.WithAttributes(or.otelAttrs...))
111+
or.recordData(ctx, component.DataTypeMetrics, int64(numPoints), int64(0), int64(0), int64(0))
86112
}
87113

88114
// MetricsRefused reports that the metrics were refused.
89115
func (or *ObsReport) MetricsRefused(ctx context.Context, numPoints int) {
90-
or.telBuilder.ProcessorRefusedMetricPoints.Add(ctx, int64(numPoints), metric.WithAttributes(or.otelAttrs...))
116+
or.recordData(ctx, component.DataTypeMetrics, int64(0), int64(numPoints), int64(0), int64(0))
91117
}
92118

93119
// MetricsDropped reports that the metrics were dropped.
94120
func (or *ObsReport) MetricsDropped(ctx context.Context, numPoints int) {
95-
or.telBuilder.ProcessorDroppedMetricPoints.Add(ctx, int64(numPoints), metric.WithAttributes(or.otelAttrs...))
121+
or.recordData(ctx, component.DataTypeMetrics, int64(0), int64(0), int64(numPoints), int64(0))
96122
}
97123

98124
// MetricsInserted reports that the metrics were inserted.
99125
func (or *ObsReport) MetricsInserted(ctx context.Context, numPoints int) {
100-
or.telBuilder.ProcessorInsertedMetricPoints.Add(ctx, int64(numPoints), metric.WithAttributes(or.otelAttrs...))
126+
or.recordData(ctx, component.DataTypeMetrics, int64(0), int64(0), int64(0), int64(numPoints))
101127
}
102128

103129
// LogsAccepted reports that the logs were accepted.
104130
func (or *ObsReport) LogsAccepted(ctx context.Context, numRecords int) {
105-
or.telBuilder.ProcessorAcceptedLogRecords.Add(ctx, int64(numRecords), metric.WithAttributes(or.otelAttrs...))
131+
or.recordData(ctx, component.DataTypeLogs, int64(numRecords), int64(0), int64(0), int64(0))
106132
}
107133

108134
// LogsRefused reports that the logs were refused.
109135
func (or *ObsReport) LogsRefused(ctx context.Context, numRecords int) {
110-
or.telBuilder.ProcessorRefusedLogRecords.Add(ctx, int64(numRecords), metric.WithAttributes(or.otelAttrs...))
136+
or.recordData(ctx, component.DataTypeLogs, int64(0), int64(numRecords), int64(0), int64(0))
111137
}
112138

113139
// LogsDropped reports that the logs were dropped.
114140
func (or *ObsReport) LogsDropped(ctx context.Context, numRecords int) {
115-
or.telBuilder.ProcessorDroppedLogRecords.Add(ctx, int64(numRecords), metric.WithAttributes(or.otelAttrs...))
141+
or.recordData(ctx, component.DataTypeLogs, int64(0), int64(0), int64(numRecords), int64(0))
116142
}
117143

118144
// LogsInserted reports that the logs were inserted.
119145
func (or *ObsReport) LogsInserted(ctx context.Context, numRecords int) {
120-
or.telBuilder.ProcessorInsertedLogRecords.Add(ctx, int64(numRecords), metric.WithAttributes(or.otelAttrs...))
146+
or.recordData(ctx, component.DataTypeLogs, int64(0), int64(0), int64(0), int64(numRecords))
121147
}

0 commit comments

Comments
 (0)