Skip to content

Commit 7c4f82c

Browse files
committed
fix(azuremonitorexporter): Fixes flushes on each single Span
1 parent 4ebb7af commit 7c4f82c

File tree

3 files changed

+63
-2
lines changed

3 files changed

+63
-2
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. filelogreceiver)
7+
component: azuremonitorexporter
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Fix flushes on each single Span
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [37214]
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+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: [user]
28+

exporter/azuremonitorexporter/traceexporter.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ func (v *traceVisitor) visit(
4646
v.exporter.transportChannel.Send(envelope)
4747
}
4848

49-
// Flush the transport channel to force the telemetry to be sent
50-
v.exporter.transportChannel.Flush()
5149
v.processed++
5250

5351
return true
@@ -61,6 +59,12 @@ func (exporter *traceExporter) onTraceData(_ context.Context, traceData ptrace.T
6159

6260
visitor := &traceVisitor{exporter: exporter}
6361
accept(traceData, visitor)
62+
63+
// Flush the transport channel to force the telemetry to be sent
64+
if visitor.processed > 0 {
65+
exporter.transportChannel.Flush()
66+
}
67+
6468
return visitor.err
6569
}
6670

exporter/azuremonitorexporter/traceexporter_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,33 @@ func TestExporterTraceDataCallbackSingleSpan(t *testing.T) {
5050
assert.NoError(t, exporter.onTraceData(context.Background(), traces))
5151

5252
mockTransportChannel.AssertNumberOfCalls(t, "Send", 1)
53+
mockTransportChannel.AssertNumberOfCalls(t, "Flush", 1)
54+
}
55+
56+
func TestExporterTraceDataCallbackCallFlushOnce(t *testing.T) {
57+
mockTransportChannel := getMockTransportChannel()
58+
exporter := getExporter(defaultConfig, mockTransportChannel)
59+
60+
resource := getResource()
61+
scope := getScope()
62+
span := getDefaultHTTPServerSpan()
63+
64+
traces := ptrace.NewTraces()
65+
rs := traces.ResourceSpans().AppendEmpty()
66+
r := rs.Resource()
67+
resource.CopyTo(r)
68+
ilss := rs.ScopeSpans().AppendEmpty()
69+
scope.CopyTo(ilss.Scope())
70+
71+
span.CopyTo(ilss.Spans().AppendEmpty())
72+
span.CopyTo(ilss.Spans().AppendEmpty())
73+
ilss.CopyTo(rs.ScopeSpans().AppendEmpty())
74+
rs.CopyTo(traces.ResourceSpans().AppendEmpty())
75+
76+
assert.NoError(t, exporter.onTraceData(context.Background(), traces))
77+
78+
mockTransportChannel.AssertNumberOfCalls(t, "Send", 8)
79+
mockTransportChannel.AssertNumberOfCalls(t, "Flush", 1)
5380
}
5481

5582
// Tests the export onTraceData callback with a single Span with SpanEvents
@@ -82,6 +109,7 @@ func TestExporterTraceDataCallbackSingleSpanWithSpanEvents(t *testing.T) {
82109
assert.NoError(t, exporter.onTraceData(context.Background(), traces))
83110

84111
mockTransportChannel.AssertNumberOfCalls(t, "Send", 3)
112+
mockTransportChannel.AssertNumberOfCalls(t, "Flush", 1)
85113
}
86114

87115
// Tests the export onTraceData callback with a single Span that fails to produce an envelope
@@ -111,6 +139,7 @@ func TestExporterTraceDataCallbackSingleSpanNoEnvelope(t *testing.T) {
111139
assert.True(t, consumererror.IsPermanent(err), "error should be permanent")
112140

113141
mockTransportChannel.AssertNumberOfCalls(t, "Send", 0)
142+
mockTransportChannel.AssertNumberOfCalls(t, "Flush", 0)
114143
}
115144

116145
func getMockTransportChannel() *mockTransportChannel {

0 commit comments

Comments
 (0)