Skip to content

Commit 73b2088

Browse files
Alex Botenpantuza
Alex Boten
authored andcommitted
[exporterhelper] fix missed metric aggregations (open-telemetry#9048)
This PR ensures that context cancellation in the exporter doesn't interfere with metric aggregation. The OTel SDK currently returns if there's an error in the context used in `Add` (see https://github.com/open-telemetry/opentelemetry-go/blob/6cee2b4a4c76b581115d0d0ca150ad8b2e683db6/sdk/metric/instrument.go#L241-L243). This means that if there's a cancelled context in an export, the metrics are not recorded. --------- Signed-off-by: Alex Boten <[email protected]>
1 parent 63a07c7 commit 73b2088

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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: bug_fix
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: fix missed metric aggregations
11+
12+
# One or more tracking issues or pull requests related to the change
13+
issues: [9048]
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: |
19+
This ensures that context cancellation in the exporter doesn't interfere with metric aggregation. The OTel
20+
SDK currently returns if there's an error in the context used in `Add`. This means that if there's a
21+
cancelled context in an export, the metrics are now recorded.
22+
23+
# Optional: The change log or logs in which this entry should be included.
24+
# e.g. '[user]' or '[user, api]'
25+
# Include 'user' if the change is relevant to end users.
26+
# Include 'api' if there is a change to a library API.
27+
# Default: '[user]'
28+
change_logs: []

exporter/exporterhelper/obsexporter.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ func (or *ObsReport) StartTracesOp(ctx context.Context) context.Context {
154154
// EndTracesOp completes the export operation that was started with StartTracesOp.
155155
func (or *ObsReport) EndTracesOp(ctx context.Context, numSpans int, err error) {
156156
numSent, numFailedToSend := toNumItems(numSpans, err)
157-
or.recordMetrics(ctx, component.DataTypeTraces, numSent, numFailedToSend)
157+
or.recordMetrics(noCancellationContext{Context: ctx}, component.DataTypeTraces, numSent, numFailedToSend)
158158
endSpan(ctx, err, numSent, numFailedToSend, obsmetrics.SentSpansKey, obsmetrics.FailedToSendSpansKey)
159159
}
160160

@@ -169,7 +169,7 @@ func (or *ObsReport) StartMetricsOp(ctx context.Context) context.Context {
169169
// StartMetricsOp.
170170
func (or *ObsReport) EndMetricsOp(ctx context.Context, numMetricPoints int, err error) {
171171
numSent, numFailedToSend := toNumItems(numMetricPoints, err)
172-
or.recordMetrics(ctx, component.DataTypeMetrics, numSent, numFailedToSend)
172+
or.recordMetrics(noCancellationContext{Context: ctx}, component.DataTypeMetrics, numSent, numFailedToSend)
173173
endSpan(ctx, err, numSent, numFailedToSend, obsmetrics.SentMetricPointsKey, obsmetrics.FailedToSendMetricPointsKey)
174174
}
175175

@@ -183,7 +183,7 @@ func (or *ObsReport) StartLogsOp(ctx context.Context) context.Context {
183183
// EndLogsOp completes the export operation that was started with StartLogsOp.
184184
func (or *ObsReport) EndLogsOp(ctx context.Context, numLogRecords int, err error) {
185185
numSent, numFailedToSend := toNumItems(numLogRecords, err)
186-
or.recordMetrics(ctx, component.DataTypeLogs, numSent, numFailedToSend)
186+
or.recordMetrics(noCancellationContext{Context: ctx}, component.DataTypeLogs, numSent, numFailedToSend)
187187
endSpan(ctx, err, numSent, numFailedToSend, obsmetrics.SentLogRecordsKey, obsmetrics.FailedToSendLogRecordsKey)
188188
}
189189

0 commit comments

Comments
 (0)