Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ internal async Task<HttpMessage> InternalTrackAsync(IEnumerable<TelemetryItem> b
catch (Exception ex)
{
AzureMonitorExporterEventSource.Log.FailedToTransmit(ex);
if (ex.InnerException?.Source != "System.Net.Http")
if (ex.InnerException?.Source != "System.Net.Http" && ex.InnerException?.Source != "System")
Comment thread
rajkumar-rangaraj marked this conversation as resolved.
{
message?.Dispose();
throw;
Expand Down Expand Up @@ -70,7 +70,7 @@ internal async Task<HttpMessage> InternalTrackAsync(ReadOnlyMemory<byte> body, C
catch (Exception ex)
{
AzureMonitorExporterEventSource.Log.FailedToTransmit(ex);
if (ex.InnerException?.Source != "System.Net.Http")
if (ex.InnerException?.Source != "System.Net.Http" && ex.InnerException?.Source != "System")
{
message?.Dispose();
throw;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ await _applicationInsightsRestClient.InternalTrackAsync(telemetryItems, cancella

if (result == ExportResult.Failure && _fileBlobProvider != null)
{
_transmissionStateManager.EnableBackOff(httpMessage.Response);
_transmissionStateManager.EnableBackOff(httpMessage.HasResponse ? httpMessage.Response : null);
result = HttpPipelineHelper.HandleFailures(httpMessage, _fileBlobProvider, _connectionVars, origin, _isAadEnabled);
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ internal void ResetTransmission(object? source, System.Timers.ElapsedEventArgs e
CloseTransmission();
}

internal void EnableBackOff(Response response)
internal void EnableBackOff(Response? response)
{
if (Interlocked.Exchange(ref _syncBackOffIntervalCalculation, 1) == 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ internal void TransmitFromStorage(object? sender, ElapsedEventArgs? e)
}
else
{
_transmissionStateManager.EnableBackOff(httpMessage.Response);
_transmissionStateManager.EnableBackOff(httpMessage.HasResponse ? httpMessage.Response : null);
HttpPipelineHelper.HandleFailures(httpMessage, blob, _blobProvider, _connectionVars, _isAadEnabled);
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,23 @@ public void FailureResponseCode429()
Assert.Single(transmitter._fileBlobProvider.GetBlobs());
}

[Fact]
public void NetworkFailure()
{
using var activity = CreateActivity("TestActivity");
var telemetryItem = CreateTelemetryItem(activity);
List<TelemetryItem> telemetryItems = new List<TelemetryItem>();
telemetryItems.Add(telemetryItem);

// Transmit
using var transmitter = GetTransmitter(null);
transmitter.TrackAsync(telemetryItems, TelemetryItemOrigin.UnitTest, false, CancellationToken.None).EnsureCompleted();

//Assert
Assert.NotNull(transmitter._fileBlobProvider);
Assert.Single(transmitter._fileBlobProvider.GetBlobs());
}

[Fact]
public void FailureResponseCode206()
{
Expand Down Expand Up @@ -260,17 +277,32 @@ public void TelemetryIsStoredOfflineWhenTransmissionStateIsSetToOpen()
transmitter.Dispose();
}

private static AzureMonitorTransmitter GetTransmitter(params MockResponse[] mockResponse)
private static AzureMonitorTransmitter GetTransmitter(params MockResponse[]? mockResponse)
{
MockTransport mockTransport = new MockTransport(mockResponse);
AzureMonitorExporterOptions options = new AzureMonitorExporterOptions
AzureMonitorTransmitter transmitter;
AzureMonitorExporterOptions options;
if (mockResponse == null)
{
ConnectionString = $"InstrumentationKey={testIkey};IngestionEndpoint={testEndpoint}",
StorageDirectory = "C:\\test",
Transport = mockTransport,
EnableStatsbeat = false, // disabled in tests.
};
AzureMonitorTransmitter transmitter = new AzureMonitorTransmitter(options, new MockPlatform());
options = new AzureMonitorExporterOptions
{
ConnectionString = $"InstrumentationKey={testIkey};IngestionEndpoint={testEndpoint}",
StorageDirectory = "C:\\test",
EnableStatsbeat = false, // disabled in tests.
};
}
else
{
MockTransport mockTransport = new MockTransport(mockResponse);
options = new AzureMonitorExporterOptions
{
ConnectionString = $"InstrumentationKey={testIkey};IngestionEndpoint={testEndpoint}",
StorageDirectory = "C:\\test",
Transport = mockTransport,
EnableStatsbeat = false, // disabled in tests.
};
}

transmitter = new AzureMonitorTransmitter(options, new MockPlatform());

// Overwrite storage with mock
transmitter._fileBlobProvider = new MockFileProvider();
Expand Down