@@ -32,8 +32,8 @@ func BuildCustomMetricName(configType, metric string) string {
3232
3333// ObsReport is a helper to add observability to a processor.
3434type 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
5050func 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.
6490func (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.
6995func (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.
74100func (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.
79105func (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.
84110func (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.
89115func (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.
94120func (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.
99125func (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.
104130func (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.
109135func (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.
114140func (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.
119145func (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