Skip to content

Commit

Permalink
[chore] Move exporter id attribute to the span
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan Drutu <[email protected]>
  • Loading branch information
bogdandrutu committed Jan 23, 2025
1 parent 4963da7 commit 93b41f7
Show file tree
Hide file tree
Showing 8 changed files with 200 additions and 185 deletions.
25 changes: 25 additions & 0 deletions .chloggen/opbexp.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: Change exporter ID to be a Span level attribute instead on each event.

# One or more tracking issues or pull requests related to the change
issues: [12164]

# (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: This does not have an impact on the level of information emitted, but on the structure of the Span.

# 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: [user]
2 changes: 1 addition & 1 deletion exporter/exporterhelper/internal/base_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ type BaseExporter struct {
}

func NewBaseExporter(set exporter.Settings, signal pipeline.Signal, osf ObsrepSenderFactory, options ...Option) (*BaseExporter, error) {
obsReport, err := NewExporter(ObsReportSettings{ExporterID: set.ID, ExporterCreateSettings: set, Signal: signal})
obsReport, err := NewExporter(ObsReportSettings{ExporterSettings: set, Signal: signal})
if err != nil {
return nil, err
}
Expand Down
33 changes: 18 additions & 15 deletions exporter/exporterhelper/internal/obsexporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/trace"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/exporter"
"go.opentelemetry.io/collector/exporter/exporterhelper/internal/metadata"
"go.opentelemetry.io/collector/pipeline"
Expand All @@ -23,28 +22,32 @@ type ObsReport struct {
tracer trace.Tracer
Signal pipeline.Signal

otelAttrs metric.MeasurementOption
spanAttrs trace.SpanStartEventOption
metricsAttrs metric.MeasurementOption
TelemetryBuilder *metadata.TelemetryBuilder
}

// ObsReportSettings are settings for creating an ObsReport.
type ObsReportSettings struct {
ExporterID component.ID
ExporterCreateSettings exporter.Settings
Signal pipeline.Signal
ExporterSettings exporter.Settings
Signal pipeline.Signal
}

func NewExporter(cfg ObsReportSettings) (*ObsReport, error) {
telemetryBuilder, err := metadata.NewTelemetryBuilder(cfg.ExporterCreateSettings.TelemetrySettings)
func NewExporter(set ObsReportSettings) (*ObsReport, error) {
telemetryBuilder, err := metadata.NewTelemetryBuilder(set.ExporterSettings.TelemetrySettings)
if err != nil {
return nil, err
}

idStr := set.ExporterSettings.ID.String()
expAttr := attribute.String(ExporterKey, idStr)

return &ObsReport{
spanNamePrefix: ExporterPrefix + cfg.ExporterID.String(),
tracer: cfg.ExporterCreateSettings.TracerProvider.Tracer(cfg.ExporterID.String()),
Signal: cfg.Signal,
otelAttrs: metric.WithAttributeSet(attribute.NewSet(attribute.String(ExporterKey, cfg.ExporterID.String()))),
spanNamePrefix: ExporterPrefix + idStr,
tracer: metadata.Tracer(set.ExporterSettings.TelemetrySettings),
Signal: set.Signal,
spanAttrs: trace.WithAttributes(expAttr, attribute.String(DataTypeKey, set.Signal.String())),
metricsAttrs: metric.WithAttributeSet(attribute.NewSet(expAttr)),
TelemetryBuilder: telemetryBuilder,
}, nil
}
Expand Down Expand Up @@ -111,7 +114,7 @@ func (or *ObsReport) EndProfilesOp(ctx context.Context, numSpans int, err error)
// the updated context and the created span.
func (or *ObsReport) startOp(ctx context.Context, operationSuffix string) context.Context {
spanName := or.spanNamePrefix + operationSuffix
ctx, _ = or.tracer.Start(ctx, spanName)
ctx, _ = or.tracer.Start(ctx, spanName, or.spanAttrs)
return ctx
}

Expand All @@ -129,8 +132,8 @@ func (or *ObsReport) recordMetrics(ctx context.Context, signal pipeline.Signal,
failedMeasure = or.TelemetryBuilder.ExporterSendFailedLogRecords
}

sentMeasure.Add(ctx, sent, or.otelAttrs)
failedMeasure.Add(ctx, failed, or.otelAttrs)
sentMeasure.Add(ctx, sent, or.metricsAttrs)
failedMeasure.Add(ctx, failed, or.metricsAttrs)
}

func endSpan(ctx context.Context, err error, numSent, numFailedToSend int64, sentItemsKey, failedToSendItemsKey string) {
Expand Down Expand Up @@ -166,5 +169,5 @@ func (or *ObsReport) RecordEnqueueFailure(ctx context.Context, signal pipeline.S
enqueueFailedMeasure = or.TelemetryBuilder.ExporterEnqueueFailedLogRecords
}

enqueueFailedMeasure.Add(ctx, failed, or.otelAttrs)
enqueueFailedMeasure.Add(ctx, failed, or.metricsAttrs)
}
Loading

0 comments on commit 93b41f7

Please sign in to comment.