-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
obsreport.go
42 lines (34 loc) · 1.29 KB
/
obsreport.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package processorhelper // import "go.opentelemetry.io/collector/processor/processorhelper"
import (
"context"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/collector/pipeline"
"go.opentelemetry.io/collector/processor"
"go.opentelemetry.io/collector/processor/internal"
"go.opentelemetry.io/collector/processor/processorhelper/internal/metadata"
)
const signalKey = "otel.signal"
type obsReport struct {
otelAttrs metric.MeasurementOption
telemetryBuilder *metadata.TelemetryBuilder
}
func newObsReport(set processor.Settings, signal pipeline.Signal) (*obsReport, error) {
telemetryBuilder, err := metadata.NewTelemetryBuilder(set.TelemetrySettings)
if err != nil {
return nil, err
}
return &obsReport{
otelAttrs: metric.WithAttributeSet(attribute.NewSet(
attribute.String(internal.ProcessorKey, set.ID.String()),
attribute.String(signalKey, signal.String()),
)),
telemetryBuilder: telemetryBuilder,
}, nil
}
func (or *obsReport) recordInOut(ctx context.Context, incoming, outgoing int) {
or.telemetryBuilder.ProcessorIncomingItems.Add(ctx, int64(incoming), or.otelAttrs)
or.telemetryBuilder.ProcessorOutgoingItems.Add(ctx, int64(outgoing), or.otelAttrs)
}