Skip to content

Commit

Permalink
[exporterhelper] delete deprecated exporterhelper.ObsReport (#10779)
Browse files Browse the repository at this point in the history
#### Description
Delete deprecated `exporterhelper.ObsReport` and
`exporterhelper.NewObsReport`

#### Link to tracking issue
Relates to
#10592
  • Loading branch information
atoulme authored Aug 7, 2024
1 parent 3396d0b commit c469394
Show file tree
Hide file tree
Showing 12 changed files with 113 additions and 113 deletions.
25 changes: 25 additions & 0 deletions .chloggen/obsexporter.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: breaking

# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
component: exporterhelper

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Delete deprecated `exporterhelper.ObsReport` and `exporterhelper.NewObsReport`

# One or more tracking issues or pull requests related to the change
issues: [10779, 10592]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [api]
6 changes: 3 additions & 3 deletions exporter/exporterhelper/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (b *baseRequestSender) setNextSender(nextSender requestSender) {
b.nextSender = nextSender
}

type obsrepSenderFactory func(obsrep *ObsReport) requestSender
type obsrepSenderFactory func(obsrep *obsReport) requestSender

// Option apply changes to baseExporter.
type Option func(*baseExporter) error
Expand Down Expand Up @@ -232,7 +232,7 @@ type baseExporter struct {
unmarshaler exporterqueue.Unmarshaler[Request]

set exporter.Settings
obsrep *ObsReport
obsrep *obsReport

// Message for the user to be added with an export failure message.
exportFailureMessage string
Expand All @@ -250,7 +250,7 @@ type baseExporter struct {
}

func newBaseExporter(set exporter.Settings, signal component.DataType, osf obsrepSenderFactory, options ...Option) (*baseExporter, error) {
obsReport, err := NewObsReport(ObsReportSettings{ExporterID: set.ID, ExporterCreateSettings: set, DataType: signal})
obsReport, err := newObsReport(obsReportSettings{exporterID: set.ID, exporterCreateSettings: set, dataType: signal})
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion exporter/exporterhelper/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var (
}()
)

func newNoopObsrepSender(*ObsReport) requestSender {
func newNoopObsrepSender(*obsReport) requestSender {
return &baseRequestSender{}
}

Expand Down
8 changes: 4 additions & 4 deletions exporter/exporterhelper/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,17 @@ func NewLogsRequestExporter(

type logsExporterWithObservability struct {
baseRequestSender
obsrep *ObsReport
obsrep *obsReport
}

func newLogsExporterWithObservability(obsrep *ObsReport) requestSender {
func newLogsExporterWithObservability(obsrep *obsReport) requestSender {
return &logsExporterWithObservability{obsrep: obsrep}
}

func (lewo *logsExporterWithObservability) send(ctx context.Context, req Request) error {
c := lewo.obsrep.StartLogsOp(ctx)
c := lewo.obsrep.startLogsOp(ctx)
numLogRecords := req.ItemsCount()
err := lewo.nextSender.send(c, req)
lewo.obsrep.EndLogsOp(c, numLogRecords, err)
lewo.obsrep.endLogsOp(c, numLogRecords, err)
return err
}
8 changes: 4 additions & 4 deletions exporter/exporterhelper/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,17 @@ func NewMetricsRequestExporter(

type metricsSenderWithObservability struct {
baseRequestSender
obsrep *ObsReport
obsrep *obsReport
}

func newMetricsSenderWithObservability(obsrep *ObsReport) requestSender {
func newMetricsSenderWithObservability(obsrep *obsReport) requestSender {
return &metricsSenderWithObservability{obsrep: obsrep}
}

func (mewo *metricsSenderWithObservability) send(ctx context.Context, req Request) error {
c := mewo.obsrep.StartMetricsOp(ctx)
c := mewo.obsrep.startMetricsOp(ctx)
numMetricDataPoints := req.ItemsCount()
err := mewo.nextSender.send(c, req)
mewo.obsrep.EndMetricsOp(c, numMetricDataPoints, err)
mewo.obsrep.endMetricsOp(c, numMetricDataPoints, err)
return err
}
91 changes: 33 additions & 58 deletions exporter/exporterhelper/obsexporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,8 @@ import (
"go.opentelemetry.io/collector/internal/obsreportconfig/obsmetrics"
)

// ObsReport is a helper to add observability to an exporter.
//
// Deprecated: [v0.105.0] Not expected to be used directly.
// If needed, report your use case in https://github.com/open-telemetry/opentelemetry-collector/issues/10592.
type ObsReport struct {
// obsReport is a helper to add observability to an exporter.
type obsReport struct {
level configtelemetry.Level
spanNamePrefix string
tracer trace.Tracer
Expand All @@ -32,112 +29,90 @@ type ObsReport struct {
telemetryBuilder *metadata.TelemetryBuilder
}

// ObsReportSettings are settings for creating an ObsReport.
//
// Deprecated: [v0.105.0] Not expected to be used directly.
// If needed, report your use case in https://github.com/open-telemetry/opentelemetry-collector/issues/10592.
type ObsReportSettings struct {
ExporterID component.ID
ExporterCreateSettings exporter.Settings
DataType component.DataType
// obsReportSettings are settings for creating an obsReport.
type obsReportSettings struct {
exporterID component.ID
exporterCreateSettings exporter.Settings
dataType component.DataType
}

// NewObsReport creates a new Exporter.
//
// Deprecated: [v0.105.0] Not expected to be used directly.
// If needed, report your use case in https://github.com/open-telemetry/opentelemetry-collector/issues/10592.
func NewObsReport(cfg ObsReportSettings) (*ObsReport, error) {
// newObsReport creates a new Exporter.
func newObsReport(cfg obsReportSettings) (*obsReport, error) {
return newExporter(cfg)
}

func newExporter(cfg ObsReportSettings) (*ObsReport, error) {
telemetryBuilder, err := metadata.NewTelemetryBuilder(cfg.ExporterCreateSettings.TelemetrySettings)
func newExporter(cfg obsReportSettings) (*obsReport, error) {
telemetryBuilder, err := metadata.NewTelemetryBuilder(cfg.exporterCreateSettings.TelemetrySettings)
if err != nil {
return nil, err
}

return &ObsReport{
level: cfg.ExporterCreateSettings.TelemetrySettings.MetricsLevel,
spanNamePrefix: obsmetrics.ExporterPrefix + cfg.ExporterID.String(),
tracer: cfg.ExporterCreateSettings.TracerProvider.Tracer(cfg.ExporterID.String()),
dataType: cfg.DataType,
return &obsReport{
level: cfg.exporterCreateSettings.TelemetrySettings.MetricsLevel,
spanNamePrefix: obsmetrics.ExporterPrefix + cfg.exporterID.String(),
tracer: cfg.exporterCreateSettings.TracerProvider.Tracer(cfg.exporterID.String()),
dataType: cfg.dataType,
otelAttrs: []attribute.KeyValue{
attribute.String(obsmetrics.ExporterKey, cfg.ExporterID.String()),
attribute.String(obsmetrics.ExporterKey, cfg.exporterID.String()),
},
telemetryBuilder: telemetryBuilder,
}, nil
}

// StartTracesOp 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.
//
// Deprecated: [v0.105.0] Not expected to be used directly.
// If needed, report your use case in https://github.com/open-telemetry/opentelemetry-collector/issues/10592.
func (or *ObsReport) StartTracesOp(ctx context.Context) context.Context {
func (or *obsReport) startTracesOp(ctx context.Context) context.Context {
return or.startOp(ctx, obsmetrics.ExportTraceDataOperationSuffix)
}

// EndTracesOp completes the export operation that was started with StartTracesOp.
//
// Deprecated: [v0.105.0] Not expected to be used directly.
// If needed, report your use case in https://github.com/open-telemetry/opentelemetry-collector/issues/10592.
func (or *ObsReport) EndTracesOp(ctx context.Context, numSpans int, err error) {
// endTracesOp completes the export operation that was started with startTracesOp.
func (or *obsReport) endTracesOp(ctx context.Context, numSpans int, err error) {
numSent, numFailedToSend := toNumItems(numSpans, err)
or.recordMetrics(context.WithoutCancel(ctx), component.DataTypeTraces, numSent, numFailedToSend)
endSpan(ctx, err, numSent, numFailedToSend, obsmetrics.SentSpansKey, obsmetrics.FailedToSendSpansKey)
}

// StartMetricsOp 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.
//
// Deprecated: [v0.105.0] Not expected to be used directly.
// If needed, report your use case in https://github.com/open-telemetry/opentelemetry-collector/issues/10592.
func (or *ObsReport) StartMetricsOp(ctx context.Context) context.Context {
func (or *obsReport) startMetricsOp(ctx context.Context) context.Context {
return or.startOp(ctx, obsmetrics.ExportMetricsOperationSuffix)
}

// EndMetricsOp completes the export operation that was started with
// StartMetricsOp.
// endMetricsOp completes the export operation that was started with
// startMetricsOp.
//
// Deprecated: [v0.105.0] Not expected to be used directly.
// If needed, report your use case in https://github.com/open-telemetry/opentelemetry-collector/issues/10592.
func (or *ObsReport) EndMetricsOp(ctx context.Context, numMetricPoints int, err error) {
func (or *obsReport) endMetricsOp(ctx context.Context, numMetricPoints int, err error) {
numSent, numFailedToSend := toNumItems(numMetricPoints, err)
or.recordMetrics(context.WithoutCancel(ctx), component.DataTypeMetrics, numSent, numFailedToSend)
endSpan(ctx, err, numSent, numFailedToSend, obsmetrics.SentMetricPointsKey, obsmetrics.FailedToSendMetricPointsKey)
}

// StartLogsOp 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.
//
// Deprecated: [v0.105.0] Not expected to be used directly.
// If needed, report your use case in https://github.com/open-telemetry/opentelemetry-collector/issues/10592.
func (or *ObsReport) StartLogsOp(ctx context.Context) context.Context {
func (or *obsReport) startLogsOp(ctx context.Context) context.Context {
return or.startOp(ctx, obsmetrics.ExportLogsOperationSuffix)
}

// EndLogsOp completes the export operation that was started with StartLogsOp.
//
// Deprecated: [v0.105.0] Not expected to be used directly.
// If needed, report your use case in https://github.com/open-telemetry/opentelemetry-collector/issues/10592.
func (or *ObsReport) EndLogsOp(ctx context.Context, numLogRecords int, err error) {
// endLogsOp completes the export operation that was started with startLogsOp.
func (or *obsReport) endLogsOp(ctx context.Context, numLogRecords int, err error) {
numSent, numFailedToSend := toNumItems(numLogRecords, err)
or.recordMetrics(context.WithoutCancel(ctx), component.DataTypeLogs, numSent, numFailedToSend)
endSpan(ctx, err, numSent, numFailedToSend, obsmetrics.SentLogRecordsKey, obsmetrics.FailedToSendLogRecordsKey)
}

// startOp creates the span used to trace the operation. Returning
// the updated context and the created span.
func (or *ObsReport) startOp(ctx context.Context, operationSuffix string) context.Context {
func (or *obsReport) startOp(ctx context.Context, operationSuffix string) context.Context {
spanName := or.spanNamePrefix + operationSuffix
ctx, _ = or.tracer.Start(ctx, spanName)
return ctx
}

func (or *ObsReport) recordMetrics(ctx context.Context, dataType component.DataType, sent, failed int64) {
func (or *obsReport) recordMetrics(ctx context.Context, dataType component.DataType, sent, failed int64) {
if or.level == configtelemetry.LevelNone {
return
}
Expand Down Expand Up @@ -180,7 +155,7 @@ func toNumItems(numExportedItems int, err error) (int64, int64) {
return int64(numExportedItems), 0
}

func (or *ObsReport) recordEnqueueFailure(ctx context.Context, dataType component.DataType, failed int64) {
func (or *obsReport) recordEnqueueFailure(ctx context.Context, dataType component.DataType, failed int64) {
var enqueueFailedMeasure metric.Int64Counter
switch dataType {
case component.DataTypeTraces:
Expand Down
Loading

0 comments on commit c469394

Please sign in to comment.