Skip to content

Commit

Permalink
configure obsReport.NewExporter with struct (#2668)
Browse files Browse the repository at this point in the history
fixes #2643

Signed-off-by: naseemkullah <[email protected]>
  • Loading branch information
Naseem authored Mar 24, 2021
1 parent 8da7dcc commit 9c14430
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 11 deletions.
5 changes: 4 additions & 1 deletion exporter/exporterhelper/logshelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ func NewLogsExporter(
be := newBaseExporter(cfg, logger, options...)
be.wrapConsumerSender(func(nextSender requestSender) requestSender {
return &logsExporterWithObservability{
obsrep: obsreport.NewExporter(configtelemetry.GetMetricsLevelFlagValue(), cfg.Name()),
obsrep: obsreport.NewExporter(obsreport.ExporterSettings{
Level: configtelemetry.GetMetricsLevelFlagValue(),
ExporterName: cfg.Name(),
}),
nextSender: nextSender,
}
})
Expand Down
5 changes: 4 additions & 1 deletion exporter/exporterhelper/metricshelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ func NewMetricsExporter(
be := newBaseExporter(cfg, logger, options...)
be.wrapConsumerSender(func(nextSender requestSender) requestSender {
return &metricsSenderWithObservability{
obsrep: obsreport.NewExporter(configtelemetry.GetMetricsLevelFlagValue(), cfg.Name()),
obsrep: obsreport.NewExporter(obsreport.ExporterSettings{
Level: configtelemetry.GetMetricsLevelFlagValue(),
ExporterName: cfg.Name(),
}),
nextSender: nextSender,
}
})
Expand Down
6 changes: 5 additions & 1 deletion exporter/exporterhelper/tracehelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ func NewTraceExporter(
be := newBaseExporter(cfg, logger, options...)
be.wrapConsumerSender(func(nextSender requestSender) requestSender {
return &tracesExporterWithObservability{
obsrep: obsreport.NewExporter(configtelemetry.GetMetricsLevelFlagValue(), cfg.Name()),
obsrep: obsreport.NewExporter(
obsreport.ExporterSettings{
Level: configtelemetry.GetMetricsLevelFlagValue(),
ExporterName: cfg.Name(),
}),
nextSender: nextSender,
}
})
Expand Down
5 changes: 4 additions & 1 deletion exporter/prometheusexporter/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ func newPrometheusExporter(config *Config, logger *zap.Logger) (*prometheusExpor
return nil, errBlankPrometheusAddress
}

obsrep := obsreport.NewExporter(configtelemetry.GetMetricsLevelFlagValue(), config.Name())
obsrep := obsreport.NewExporter(obsreport.ExporterSettings{
Level: configtelemetry.GetMetricsLevelFlagValue(),
ExporterName: config.Name(),
})

collector := newCollector(config, logger)
registry := prometheus.NewRegistry()
Expand Down
8 changes: 7 additions & 1 deletion obsreport/obsreport_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,13 @@ type Exporter struct {
mutators []tag.Mutator
}

func NewExporter(level configtelemetry.Level, exporterName string) *Exporter {
type ExporterSettings struct {
Level configtelemetry.Level
ExporterName string
}

func NewExporter(cfg ExporterSettings) *Exporter {
level, exporterName := cfg.Level, cfg.ExporterName
return &Exporter{
level: level,
exporterName: exporterName,
Expand Down
6 changes: 3 additions & 3 deletions obsreport/obsreport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ func TestExportTraceDataOp(t *testing.T) {
t.Name(), trace.WithSampler(trace.AlwaysSample()))
defer parentSpan.End()

obsrep := obsreport.NewExporter(configtelemetry.LevelNormal, exporter)
obsrep := obsreport.NewExporter(obsreport.ExporterSettings{configtelemetry.LevelNormal, exporter})
errs := []error{nil, errFake}
numExportedSpans := []int{22, 14}
for i, err := range errs {
Expand Down Expand Up @@ -385,7 +385,7 @@ func TestExportMetricsOp(t *testing.T) {
t.Name(), trace.WithSampler(trace.AlwaysSample()))
defer parentSpan.End()

obsrep := obsreport.NewExporter(configtelemetry.LevelNormal, exporter)
obsrep := obsreport.NewExporter(obsreport.ExporterSettings{configtelemetry.LevelNormal, exporter})

errs := []error{nil, errFake}
toSendMetricPoints := []int{17, 23}
Expand Down Expand Up @@ -434,7 +434,7 @@ func TestExportLogsOp(t *testing.T) {
t.Name(), trace.WithSampler(trace.AlwaysSample()))
defer parentSpan.End()

obsrep := obsreport.NewExporter(configtelemetry.LevelNormal, exporter)
obsrep := obsreport.NewExporter(obsreport.ExporterSettings{configtelemetry.LevelNormal, exporter})
errs := []error{nil, errFake}
toSendLogRecords := []int{17, 23}
for i, err := range errs {
Expand Down
15 changes: 12 additions & 3 deletions obsreport/obsreporttest/obsreporttest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ func TestCheckExporterTracesViews(t *testing.T) {
require.NoError(t, err)
defer doneFn()

obsrep := obsreport.NewExporter(configtelemetry.LevelNormal, exporter)
obsrep := obsreport.NewExporter(obsreport.ExporterSettings{
Level: configtelemetry.LevelNormal,
ExporterName: exporter,
})
ctx := obsrep.StartTracesExportOp(context.Background())
assert.NotNil(t, ctx)

Expand All @@ -95,7 +98,10 @@ func TestCheckExporterMetricsViews(t *testing.T) {
require.NoError(t, err)
defer doneFn()

obsrep := obsreport.NewExporter(configtelemetry.LevelNormal, exporter)
obsrep := obsreport.NewExporter(obsreport.ExporterSettings{
Level: configtelemetry.LevelNormal,
ExporterName: exporter,
})
ctx := obsrep.StartMetricsExportOp(context.Background())
assert.NotNil(t, ctx)

Expand All @@ -109,7 +115,10 @@ func TestCheckExporterLogsViews(t *testing.T) {
require.NoError(t, err)
defer doneFn()

obsrep := obsreport.NewExporter(configtelemetry.LevelNormal, exporter)
obsrep := obsreport.NewExporter(obsreport.ExporterSettings{
Level: configtelemetry.LevelNormal,
ExporterName: exporter,
})
ctx := obsrep.StartLogsExportOp(context.Background())
assert.NotNil(t, ctx)
obsrep.EndLogsExportOp(ctx, 7, nil)
Expand Down

0 comments on commit 9c14430

Please sign in to comment.