Skip to content

Commit

Permalink
[chore] update statsd receiver to use mdatagen
Browse files Browse the repository at this point in the history
This updates the receiver to use mdatagen for internal telemetry.

Signed-off-by: Alex Boten <223565+codeboten@users.noreply.github.com>
  • Loading branch information
codeboten committed Jun 12, 2024
1 parent af5997f commit da72ec2
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 16 deletions.
15 changes: 15 additions & 0 deletions receiver/statsdreceiver/documentation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[comment]: <> (Code generated by mdatagen. DO NOT EDIT.)

# statsd

## Internal Telemetry

The following telemetry is emitted by this component.

### receiver_received_statsd_metrics

Number of statsd metrics received.

| Unit | Metric Type | Value Type | Monotonic |
| ---- | ----------- | ---------- | --------- |
| 1 | Sum | Int | true |
76 changes: 76 additions & 0 deletions receiver/statsdreceiver/generated_component_telemetry_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 46 additions & 1 deletion receiver/statsdreceiver/internal/metadata/generated_telemetry.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions receiver/statsdreceiver/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,13 @@ status:
distributions: [contrib]
codeowners:
active: [jmacd, dmitryax]

telemetry:
metrics:
receiver_received_statsd_metrics:
enabled: true
description: Number of statsd metrics received.
unit: "1"
sum:
value_type: int
monotonic: true
26 changes: 11 additions & 15 deletions receiver/statsdreceiver/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import (
// reporter struct implements the transport.Reporter interface to give consistent
// observability per Collector metric observability package.
type reporter struct {
logger *zap.Logger
sugaredLogger *zap.SugaredLogger // Used for generic debug logging
receiverAttr attribute.KeyValue
receivedCount metric.Int64Counter
logger *zap.Logger
sugaredLogger *zap.SugaredLogger // Used for generic debug logging
receiverAttr attribute.KeyValue
telemetryBuilder *metadata.TelemetryBuilder
}

var (
Expand All @@ -29,19 +29,15 @@ var (
)

func newReporter(set receiver.Settings) (*reporter, error) {
receivedCount, err := metadata.Meter(set.TelemetrySettings).Int64Counter(
"receiver/received_statsd_metrics",
metric.WithDescription("Number of statsd metrics received."),
metric.WithUnit("1"),
)
telemetryBuilder, err := metadata.NewTelemetryBuilder(set.TelemetrySettings)
if err != nil {
return nil, err
}
return &reporter{
logger: set.Logger,
sugaredLogger: set.Logger.Sugar(),
receiverAttr: attribute.String("receiver", set.ID.String()),
receivedCount: receivedCount,
logger: set.Logger,
sugaredLogger: set.Logger.Sugar(),
receiverAttr: attribute.String("receiver", set.ID.String()),
telemetryBuilder: telemetryBuilder,
}, nil
}

Expand All @@ -52,7 +48,7 @@ func (r *reporter) OnDebugf(template string, args ...any) {
}

func (r *reporter) RecordParseFailure() {
r.receivedCount.Add(
r.telemetryBuilder.ReceiverReceivedStatsdMetrics.Add(
context.Background(),
1,
metric.WithAttributes(
Expand All @@ -62,7 +58,7 @@ func (r *reporter) RecordParseFailure() {
}

func (r *reporter) RecordParseSuccess(count int64) {
r.receivedCount.Add(
r.telemetryBuilder.ReceiverReceivedStatsdMetrics.Add(
context.Background(),
count,
metric.WithAttributes(
Expand Down

0 comments on commit da72ec2

Please sign in to comment.