Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow redaction of other metric fields in stdoutmetric exporter #5233

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions exporters/stdout/stdoutmetric/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"os"

"go.opentelemetry.io/otel/sdk/metric"
"go.opentelemetry.io/otel/sdk/metric/metricdata"
)

// config contains options for the exporter.
Expand All @@ -17,7 +18,7 @@
encoder *encoderHolder
temporalitySelector metric.TemporalitySelector
aggregationSelector metric.AggregationSelector
redactTimestamps bool
redactors []RedactorFunc
}

// newConfig creates a validated config configured with options.
Expand Down Expand Up @@ -126,7 +127,18 @@
// WithoutTimestamps sets all timestamps to zero in the output stream.
func WithoutTimestamps() Option {
return optionFunc(func(c config) config {
c.redactTimestamps = true
c.redactors = append(c.redactors, redactTimestamps)
return c
})
}

// WithRedactor sets a redactor the exporter will use to redact metrics.
func WithRedactor(redactor RedactorFunc) Option {
return optionFunc(func(c config) config {
c.redactors = append(c.redactors, redactor)
return c
})

Check warning on line 140 in exporters/stdout/stdoutmetric/config.go

View check run for this annotation

Codecov / codecov/patch

exporters/stdout/stdoutmetric/config.go#L136-L140

Added lines #L136 - L140 were not covered by tests
}

// RedactorFunc supports redacting certain information from metrics.
type RedactorFunc func(orig *metricdata.ResourceMetrics)
8 changes: 4 additions & 4 deletions exporters/stdout/stdoutmetric/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type exporter struct {
temporalitySelector metric.TemporalitySelector
aggregationSelector metric.AggregationSelector

redactTimestamps bool
redactors []RedactorFunc
}

// New returns a configured metric exporter.
Expand All @@ -36,7 +36,7 @@ func New(options ...Option) (metric.Exporter, error) {
exp := &exporter{
temporalitySelector: cfg.temporalitySelector,
aggregationSelector: cfg.aggregationSelector,
redactTimestamps: cfg.redactTimestamps,
redactors: cfg.redactors,
}
exp.encVal.Store(*cfg.encoder)
return exp, nil
Expand All @@ -58,8 +58,8 @@ func (e *exporter) Export(ctx context.Context, data *metricdata.ResourceMetrics)
default:
// Context is still valid, continue.
}
if e.redactTimestamps {
redactTimestamps(data)
for _, redactor := range e.redactors {
redactor(data)
}

global.Debug("STDOUT exporter export", "Data", data)
Expand Down
Loading