From 4569a6a6eafce209508d2806ac0542f3568de3c9 Mon Sep 17 00:00:00 2001 From: Whitney Griffith Date: Mon, 25 Nov 2024 08:04:14 -0800 Subject: [PATCH] [chore][exporter/azuremonitor] Force the telemetry to be sent to azuremonitor (#36520) #### Description 1. Resolved an issue where traces weren't being sent to App Insights due to not flushing the Telemetry Channel. Added the necessary flush operation to ensure all traces, metrics and logs are properly sent to the queue, leveraging App Insights' batch handling for more efficient processing. #### Link to tracking issue Resolves #35037 --------- Signed-off-by: whitneygriffith Co-authored-by: Andrzej Stencel --- .chloggen/azuremonitor-bug-fix.yaml | 27 +++++++++++++++++++ exporter/azuremonitorexporter/channels.go | 1 + exporter/azuremonitorexporter/logexporter.go | 3 ++- .../azuremonitorexporter/metricexporter.go | 2 ++ .../mock_transportChannel.go | 4 +++ .../azuremonitorexporter/traceexporter.go | 2 ++ .../traceexporter_test.go | 1 + 7 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 .chloggen/azuremonitor-bug-fix.yaml diff --git a/.chloggen/azuremonitor-bug-fix.yaml b/.chloggen/azuremonitor-bug-fix.yaml new file mode 100644 index 000000000000..3c7546682371 --- /dev/null +++ b/.chloggen/azuremonitor-bug-fix.yaml @@ -0,0 +1,27 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: 'bug_fix' + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: azuremonitorexporter + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: "Fixes an issue where the Azure Monitor exporter was not sending data to App Insights due to the Telemetry Channel not being flushed." + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [35037] + +# (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: + +# If your change doesn't affect end users or the exported elements of any package, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. +# 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: [] diff --git a/exporter/azuremonitorexporter/channels.go b/exporter/azuremonitorexporter/channels.go index 9c50d03c48ee..5b30e94fc11c 100644 --- a/exporter/azuremonitorexporter/channels.go +++ b/exporter/azuremonitorexporter/channels.go @@ -7,4 +7,5 @@ import "github.com/microsoft/ApplicationInsights-Go/appinsights/contracts" type transportChannel interface { Send(*contracts.Envelope) + Flush() } diff --git a/exporter/azuremonitorexporter/logexporter.go b/exporter/azuremonitorexporter/logexporter.go index e181a5100826..1eacc80261b0 100644 --- a/exporter/azuremonitorexporter/logexporter.go +++ b/exporter/azuremonitorexporter/logexporter.go @@ -35,7 +35,8 @@ func (exporter *logExporter) onLogData(_ context.Context, logData plog.Logs) err } } } - + // Flush the transport channel to force the telemetry to be sent + exporter.transportChannel.Flush() return nil } diff --git a/exporter/azuremonitorexporter/metricexporter.go b/exporter/azuremonitorexporter/metricexporter.go index 16d6d6ba14b2..b0b3bbd2bd1a 100644 --- a/exporter/azuremonitorexporter/metricexporter.go +++ b/exporter/azuremonitorexporter/metricexporter.go @@ -37,6 +37,8 @@ func (exporter *metricExporter) onMetricData(_ context.Context, metricData pmetr } } + // Flush the transport channel to force the telemetry to be sent + exporter.transportChannel.Flush() return nil } diff --git a/exporter/azuremonitorexporter/mock_transportChannel.go b/exporter/azuremonitorexporter/mock_transportChannel.go index 269eb4ac65f6..1d34e3a03a52 100644 --- a/exporter/azuremonitorexporter/mock_transportChannel.go +++ b/exporter/azuremonitorexporter/mock_transportChannel.go @@ -19,3 +19,7 @@ type mockTransportChannel struct { func (_m *mockTransportChannel) Send(_a0 *contracts.Envelope) { _m.Called(_a0) } + +func (_m *mockTransportChannel) Flush() { + _m.Called() +} diff --git a/exporter/azuremonitorexporter/traceexporter.go b/exporter/azuremonitorexporter/traceexporter.go index f5eb15d4e2f1..66326d2f540b 100644 --- a/exporter/azuremonitorexporter/traceexporter.go +++ b/exporter/azuremonitorexporter/traceexporter.go @@ -46,6 +46,8 @@ func (v *traceVisitor) visit( v.exporter.transportChannel.Send(envelope) } + // Flush the transport channel to force the telemetry to be sent + v.exporter.transportChannel.Flush() v.processed++ return true diff --git a/exporter/azuremonitorexporter/traceexporter_test.go b/exporter/azuremonitorexporter/traceexporter_test.go index c80a78cb8f29..d58a2dc9fd52 100644 --- a/exporter/azuremonitorexporter/traceexporter_test.go +++ b/exporter/azuremonitorexporter/traceexporter_test.go @@ -116,6 +116,7 @@ func TestExporterTraceDataCallbackSingleSpanNoEnvelope(t *testing.T) { func getMockTransportChannel() *mockTransportChannel { transportChannelMock := mockTransportChannel{} transportChannelMock.On("Send", mock.Anything) + transportChannelMock.On("Flush", mock.Anything) return &transportChannelMock }