diff --git a/exporter/exporterhelper/logs.go b/exporter/exporterhelper/logs.go index c9512108252..0e822cf11c5 100644 --- a/exporter/exporterhelper/logs.go +++ b/exporter/exporterhelper/logs.go @@ -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 } diff --git a/exporter/exporterhelper/metrics.go b/exporter/exporterhelper/metrics.go index 8ad834b0731..7f462e6706e 100644 --- a/exporter/exporterhelper/metrics.go +++ b/exporter/exporterhelper/metrics.go @@ -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 } diff --git a/exporter/exporterhelper/traces.go b/exporter/exporterhelper/traces.go index eae4b16c5da..48d243cc9d6 100644 --- a/exporter/exporterhelper/traces.go +++ b/exporter/exporterhelper/traces.go @@ -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 } diff --git a/exporter/prometheusexporter/prometheus.go b/exporter/prometheusexporter/prometheus.go index 4a054bc35db..aa8bee2ede0 100644 --- a/exporter/prometheusexporter/prometheus.go +++ b/exporter/prometheusexporter/prometheus.go @@ -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 } diff --git a/obsreport/doc.go b/obsreport/doc.go index 3004c13150f..920c948aa74 100644 --- a/obsreport/doc.go +++ b/obsreport/doc.go @@ -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 diff --git a/obsreport/obsreport_exporter.go b/obsreport/obsreport_exporter.go index 9671dce146e..784e3a4f8c6 100644 --- a/obsreport/obsreport_exporter.go +++ b/obsreport/obsreport_exporter.go @@ -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. @@ -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) @@ -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 } diff --git a/obsreport/obsreport_test.go b/obsreport/obsreport_test.go index 1b4f6e230e5..67d1949a61b 100644 --- a/obsreport/obsreport_test.go +++ b/obsreport/obsreport_test.go @@ -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() @@ -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() @@ -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() diff --git a/obsreport/obsreporttest/obsreporttest_test.go b/obsreport/obsreporttest/obsreporttest_test.go index a9a7c349e63..f55bd82c3bd 100644 --- a/obsreport/obsreporttest/obsreporttest_test.go +++ b/obsreport/obsreporttest/obsreporttest_test.go @@ -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) } @@ -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) } @@ -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) }