Skip to content

Commit 93b41f7

Browse files
committed
[chore] Move exporter id attribute to the span
Signed-off-by: Bogdan Drutu <[email protected]>
1 parent 4963da7 commit 93b41f7

File tree

8 files changed

+200
-185
lines changed

8 files changed

+200
-185
lines changed

.chloggen/opbexp.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: breaking
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
7+
component: exporterhelper
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Change exporter ID to be a Span level attribute instead on each event.
11+
12+
# One or more tracking issues or pull requests related to the change
13+
issues: [12164]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext: This does not have an impact on the level of information emitted, but on the structure of the Span.
19+
20+
# Optional: The change log or logs in which this entry should be included.
21+
# e.g. '[user]' or '[user, api]'
22+
# Include 'user' if the change is relevant to end users.
23+
# Include 'api' if there is a change to a library API.
24+
# Default: '[user]'
25+
change_logs: [user]

exporter/exporterhelper/internal/base_exporter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ type BaseExporter struct {
6767
}
6868

6969
func NewBaseExporter(set exporter.Settings, signal pipeline.Signal, osf ObsrepSenderFactory, options ...Option) (*BaseExporter, error) {
70-
obsReport, err := NewExporter(ObsReportSettings{ExporterID: set.ID, ExporterCreateSettings: set, Signal: signal})
70+
obsReport, err := NewExporter(ObsReportSettings{ExporterSettings: set, Signal: signal})
7171
if err != nil {
7272
return nil, err
7373
}

exporter/exporterhelper/internal/obsexporter.go

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"go.opentelemetry.io/otel/metric"
1212
"go.opentelemetry.io/otel/trace"
1313

14-
"go.opentelemetry.io/collector/component"
1514
"go.opentelemetry.io/collector/exporter"
1615
"go.opentelemetry.io/collector/exporter/exporterhelper/internal/metadata"
1716
"go.opentelemetry.io/collector/pipeline"
@@ -23,28 +22,32 @@ type ObsReport struct {
2322
tracer trace.Tracer
2423
Signal pipeline.Signal
2524

26-
otelAttrs metric.MeasurementOption
25+
spanAttrs trace.SpanStartEventOption
26+
metricsAttrs metric.MeasurementOption
2727
TelemetryBuilder *metadata.TelemetryBuilder
2828
}
2929

3030
// ObsReportSettings are settings for creating an ObsReport.
3131
type ObsReportSettings struct {
32-
ExporterID component.ID
33-
ExporterCreateSettings exporter.Settings
34-
Signal pipeline.Signal
32+
ExporterSettings exporter.Settings
33+
Signal pipeline.Signal
3534
}
3635

37-
func NewExporter(cfg ObsReportSettings) (*ObsReport, error) {
38-
telemetryBuilder, err := metadata.NewTelemetryBuilder(cfg.ExporterCreateSettings.TelemetrySettings)
36+
func NewExporter(set ObsReportSettings) (*ObsReport, error) {
37+
telemetryBuilder, err := metadata.NewTelemetryBuilder(set.ExporterSettings.TelemetrySettings)
3938
if err != nil {
4039
return nil, err
4140
}
4241

42+
idStr := set.ExporterSettings.ID.String()
43+
expAttr := attribute.String(ExporterKey, idStr)
44+
4345
return &ObsReport{
44-
spanNamePrefix: ExporterPrefix + cfg.ExporterID.String(),
45-
tracer: cfg.ExporterCreateSettings.TracerProvider.Tracer(cfg.ExporterID.String()),
46-
Signal: cfg.Signal,
47-
otelAttrs: metric.WithAttributeSet(attribute.NewSet(attribute.String(ExporterKey, cfg.ExporterID.String()))),
46+
spanNamePrefix: ExporterPrefix + idStr,
47+
tracer: metadata.Tracer(set.ExporterSettings.TelemetrySettings),
48+
Signal: set.Signal,
49+
spanAttrs: trace.WithAttributes(expAttr, attribute.String(DataTypeKey, set.Signal.String())),
50+
metricsAttrs: metric.WithAttributeSet(attribute.NewSet(expAttr)),
4851
TelemetryBuilder: telemetryBuilder,
4952
}, nil
5053
}
@@ -111,7 +114,7 @@ func (or *ObsReport) EndProfilesOp(ctx context.Context, numSpans int, err error)
111114
// the updated context and the created span.
112115
func (or *ObsReport) startOp(ctx context.Context, operationSuffix string) context.Context {
113116
spanName := or.spanNamePrefix + operationSuffix
114-
ctx, _ = or.tracer.Start(ctx, spanName)
117+
ctx, _ = or.tracer.Start(ctx, spanName, or.spanAttrs)
115118
return ctx
116119
}
117120

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

132-
sentMeasure.Add(ctx, sent, or.otelAttrs)
133-
failedMeasure.Add(ctx, failed, or.otelAttrs)
135+
sentMeasure.Add(ctx, sent, or.metricsAttrs)
136+
failedMeasure.Add(ctx, failed, or.metricsAttrs)
134137
}
135138

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

169-
enqueueFailedMeasure.Add(ctx, failed, or.otelAttrs)
172+
enqueueFailedMeasure.Add(ctx, failed, or.metricsAttrs)
170173
}

0 commit comments

Comments
 (0)