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

Remove Export from obsreport.Exporter funcs #3333

Merged
merged 1 commit into from
May 28, 2021
Merged
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
4 changes: 2 additions & 2 deletions exporter/exporterhelper/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ type logsExporterWithObservability struct {
}

func (lewo *logsExporterWithObservability) send(req request) error {
req.setContext(lewo.obsrep.StartLogsExportOp(req.context()))
req.setContext(lewo.obsrep.StartLogsOp(req.context()))
err := lewo.nextSender.send(req)
lewo.obsrep.EndLogsExportOp(req.context(), req.count(), err)
lewo.obsrep.EndLogsOp(req.context(), req.count(), err)
return err
}
4 changes: 2 additions & 2 deletions exporter/exporterhelper/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ type metricsSenderWithObservability struct {
}

func (mewo *metricsSenderWithObservability) send(req request) error {
req.setContext(mewo.obsrep.StartMetricsExportOp(req.context()))
req.setContext(mewo.obsrep.StartMetricsOp(req.context()))
err := mewo.nextSender.send(req)
mewo.obsrep.EndMetricsExportOp(req.context(), req.count(), err)
mewo.obsrep.EndMetricsOp(req.context(), req.count(), err)
return err
}
4 changes: 2 additions & 2 deletions exporter/exporterhelper/traces.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ type tracesExporterWithObservability struct {
}

func (tewo *tracesExporterWithObservability) send(req request) error {
req.setContext(tewo.obsrep.StartTracesExportOp(req.context()))
req.setContext(tewo.obsrep.StartTracesOp(req.context()))
// Forward the data to the next consumer (this pusher is the next).
err := tewo.nextSender.send(req)
tewo.obsrep.EndTracesExportOp(req.context(), req.count(), err)
tewo.obsrep.EndTracesOp(req.context(), req.count(), err)
return err
}
4 changes: 2 additions & 2 deletions exporter/prometheusexporter/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ func (pe *prometheusExporter) Start(_ context.Context, _ component.Host) error {
}

func (pe *prometheusExporter) ConsumeMetrics(ctx context.Context, md pdata.Metrics) error {
pe.obsrep.StartMetricsExportOp(ctx)
pe.obsrep.StartMetricsOp(ctx)
n := 0
rmetrics := md.ResourceMetrics()
for i := 0; i < rmetrics.Len(); i++ {
n += pe.collector.processMetrics(rmetrics.At(i))
}
pe.obsrep.EndMetricsExportOp(ctx, n, nil)
pe.obsrep.EndMetricsOp(ctx, n, nil)

return nil
}
Expand Down
6 changes: 3 additions & 3 deletions obsreport/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@
// Similar for exporters:
//
// * Traces export operations should use the pair:
// StartTracesExportOp/EndTracesExportOp
// StartTracesOp/EndTracesOp
//
// * Metrics export operations should use the pair:
// StartMetricsExportOp/EndMetricsExportOp
// StartMetricsOp/EndMetricsOp
//
// * Metrics export operations should use the pair:
// StartLogsExportOp/EndLogsExportOp
// StartLogsOp/EndLogsOp
//
// The package is capable of generating legacy metrics by using the
// observability package allowing a controlled transition from legacy to the
Expand Down
40 changes: 20 additions & 20 deletions obsreport/obsreport_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ import (

// Exporter is a helper to add observability to a component.Exporter.
type Exporter struct {
level configtelemetry.Level
exporterName string
mutators []tag.Mutator
level configtelemetry.Level
spanNamePrefix string
mutators []tag.Mutator
}

// ExporterSettings are settings for creating an Exporter.
Expand All @@ -43,50 +43,50 @@ type ExporterSettings struct {
// NewExporter creates a new Exporter.
func NewExporter(cfg ExporterSettings) *Exporter {
return &Exporter{
level: cfg.Level,
exporterName: cfg.ExporterID.String(),
mutators: []tag.Mutator{tag.Upsert(obsmetrics.TagKeyExporter, cfg.ExporterID.String(), tag.WithTTL(tag.TTLNoPropagation))},
level: cfg.Level,
spanNamePrefix: obsmetrics.ExporterPrefix + cfg.ExporterID.String(),
mutators: []tag.Mutator{tag.Upsert(obsmetrics.TagKeyExporter, cfg.ExporterID.String(), tag.WithTTL(tag.TTLNoPropagation))},
}
}

// StartTracesExportOp is called at the start of an Export operation.
// StartTracesOp is called at the start of an Export operation.
// The returned context should be used in other calls to the Exporter functions
// dealing with the same export operation.
func (eor *Exporter) StartTracesExportOp(ctx context.Context) context.Context {
func (eor *Exporter) StartTracesOp(ctx context.Context) context.Context {
return eor.startSpan(ctx, obsmetrics.ExportTraceDataOperationSuffix)
}

// EndTracesExportOp completes the export operation that was started with StartTracesExportOp.
func (eor *Exporter) EndTracesExportOp(ctx context.Context, numSpans int, err error) {
// EndTracesOp completes the export operation that was started with StartTracesOp.
func (eor *Exporter) EndTracesOp(ctx context.Context, numSpans int, err error) {
numSent, numFailedToSend := toNumItems(numSpans, err)
eor.recordMetrics(ctx, numSent, numFailedToSend, obsmetrics.ExporterSentSpans, obsmetrics.ExporterFailedToSendSpans)
endSpan(ctx, err, numSent, numFailedToSend, obsmetrics.SentSpansKey, obsmetrics.FailedToSendSpansKey)
}

// StartMetricsExportOp is called at the start of an Export operation.
// StartMetricsOp is called at the start of an Export operation.
// The returned context should be used in other calls to the Exporter functions
// dealing with the same export operation.
func (eor *Exporter) StartMetricsExportOp(ctx context.Context) context.Context {
func (eor *Exporter) StartMetricsOp(ctx context.Context) context.Context {
return eor.startSpan(ctx, obsmetrics.ExportMetricsOperationSuffix)
}

// EndMetricsExportOp completes the export operation that was started with
// StartMetricsExportOp.
func (eor *Exporter) EndMetricsExportOp(ctx context.Context, numMetricPoints int, err error) {
// EndMetricsOp completes the export operation that was started with
// StartMetricsOp.
func (eor *Exporter) EndMetricsOp(ctx context.Context, numMetricPoints int, err error) {
numSent, numFailedToSend := toNumItems(numMetricPoints, err)
eor.recordMetrics(ctx, numSent, numFailedToSend, obsmetrics.ExporterSentMetricPoints, obsmetrics.ExporterFailedToSendMetricPoints)
endSpan(ctx, err, numSent, numFailedToSend, obsmetrics.SentMetricPointsKey, obsmetrics.FailedToSendMetricPointsKey)
}

// StartLogsExportOp is called at the start of an Export operation.
// StartLogsOp is called at the start of an Export operation.
// The returned context should be used in other calls to the Exporter functions
// dealing with the same export operation.
func (eor *Exporter) StartLogsExportOp(ctx context.Context) context.Context {
func (eor *Exporter) StartLogsOp(ctx context.Context) context.Context {
return eor.startSpan(ctx, obsmetrics.ExportLogsOperationSuffix)
}

// EndLogsExportOp completes the export operation that was started with StartLogsExportOp.
func (eor *Exporter) EndLogsExportOp(ctx context.Context, numLogRecords int, err error) {
// EndLogsOp completes the export operation that was started with StartLogsOp.
func (eor *Exporter) EndLogsOp(ctx context.Context, numLogRecords int, err error) {
numSent, numFailedToSend := toNumItems(numLogRecords, err)
eor.recordMetrics(ctx, numSent, numFailedToSend, obsmetrics.ExporterSentLogRecords, obsmetrics.ExporterFailedToSendLogRecords)
endSpan(ctx, err, numSent, numFailedToSend, obsmetrics.SentLogRecordsKey, obsmetrics.FailedToSendLogRecordsKey)
Expand All @@ -95,7 +95,7 @@ func (eor *Exporter) EndLogsExportOp(ctx context.Context, numLogRecords int, err
// startSpan creates the span used to trace the operation. Returning
// the updated context and the created span.
func (eor *Exporter) startSpan(ctx context.Context, operationSuffix string) context.Context {
spanName := obsmetrics.ExporterPrefix + eor.exporterName + operationSuffix
spanName := eor.spanNamePrefix + operationSuffix
ctx, _ = trace.StartSpan(ctx, spanName)
return ctx
}
Expand Down
12 changes: 6 additions & 6 deletions obsreport/obsreport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,9 @@ func TestExportTraceDataOp(t *testing.T) {
errs := []error{nil, errFake}
numExportedSpans := []int{22, 14}
for i, err := range errs {
ctx := obsrep.StartTracesExportOp(parentCtx)
ctx := obsrep.StartTracesOp(parentCtx)
assert.NotNil(t, ctx)
obsrep.EndTracesExportOp(ctx, numExportedSpans[i], err)
obsrep.EndTracesOp(ctx, numExportedSpans[i], err)
}

spans := ss.PullAllSpans()
Expand Down Expand Up @@ -357,10 +357,10 @@ func TestExportMetricsOp(t *testing.T) {
errs := []error{nil, errFake}
toSendMetricPoints := []int{17, 23}
for i, err := range errs {
ctx := obsrep.StartMetricsExportOp(parentCtx)
ctx := obsrep.StartMetricsOp(parentCtx)
assert.NotNil(t, ctx)

obsrep.EndMetricsExportOp(ctx, toSendMetricPoints[i], err)
obsrep.EndMetricsOp(ctx, toSendMetricPoints[i], err)
}

spans := ss.PullAllSpans()
Expand Down Expand Up @@ -405,10 +405,10 @@ func TestExportLogsOp(t *testing.T) {
errs := []error{nil, errFake}
toSendLogRecords := []int{17, 23}
for i, err := range errs {
ctx := obsrep.StartLogsExportOp(parentCtx)
ctx := obsrep.StartLogsOp(parentCtx)
assert.NotNil(t, ctx)

obsrep.EndLogsExportOp(ctx, toSendLogRecords[i], err)
obsrep.EndLogsOp(ctx, toSendLogRecords[i], err)
}

spans := ss.PullAllSpans()
Expand Down
12 changes: 6 additions & 6 deletions obsreport/obsreporttest/obsreporttest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ func TestCheckExporterTracesViews(t *testing.T) {
Level: configtelemetry.LevelNormal,
ExporterID: exporter,
})
ctx := obsrep.StartTracesExportOp(context.Background())
ctx := obsrep.StartTracesOp(context.Background())
assert.NotNil(t, ctx)

obsrep.EndTracesExportOp(ctx, 7, nil)
obsrep.EndTracesOp(ctx, 7, nil)

obsreporttest.CheckExporterTraces(t, exporter, 7, 0)
}
Expand All @@ -109,10 +109,10 @@ func TestCheckExporterMetricsViews(t *testing.T) {
Level: configtelemetry.LevelNormal,
ExporterID: exporter,
})
ctx := obsrep.StartMetricsExportOp(context.Background())
ctx := obsrep.StartMetricsOp(context.Background())
assert.NotNil(t, ctx)

obsrep.EndMetricsExportOp(ctx, 7, nil)
obsrep.EndMetricsOp(ctx, 7, nil)

obsreporttest.CheckExporterMetrics(t, exporter, 7, 0)
}
Expand All @@ -126,9 +126,9 @@ func TestCheckExporterLogsViews(t *testing.T) {
Level: configtelemetry.LevelNormal,
ExporterID: exporter,
})
ctx := obsrep.StartLogsExportOp(context.Background())
ctx := obsrep.StartLogsOp(context.Background())
assert.NotNil(t, ctx)
obsrep.EndLogsExportOp(ctx, 7, nil)
obsrep.EndLogsOp(ctx, 7, nil)

obsreporttest.CheckExporterLogs(t, exporter, 7, 0)
}