-
Notifications
You must be signed in to change notification settings - Fork 293
Closed
Description
The Application Insights Ingestion Service has implemented a feature to redirect client SDKs from the global service endpoint to a regional endpoint.
Currently, the ingestion service is responding with Http 307.
The AI SDK needs to cache this endpoint for future POSTs.
Code Path
Endpoints are recommended to be set on the TelemetryConfiguration.ConnectionString.
This value is then set on the TelemetryChannel.
TelemetryConfiguration
Note: TelemetrySink ctor will initialize InMemoryChannel w/ TelemetryConfiguration.
InMemoryChannel.Flush()
- InMemoryTransmitter.Flush() > InMemoryTransmitter.DequeueAndSend() > InMemoryTransmitter.Send()
- Transmission.SendAsync()
ServerTelemetryChannel.Initialize(TelemetryConfiguration)
- ServerTelemetryChannel.Flush()
- TelemetryBuffer.FlushAsync()
- TelemetrySerializer.Serialize()
- Transmitter.Enqueue()
- TransmissionSender.StartSending()
- Transmission.SendAsync()
Transmission.SendAsync
The HttpClient used by both TelemetryChannels is here:
ApplicationInsights-dotnet/BASE/src/Microsoft.ApplicationInsights/Channel/Transmission.cs
Lines 166 to 200 in 99b87a1
| public virtual async Task<HttpWebResponseWrapper> SendAsync() | |
| { | |
| if (Interlocked.CompareExchange(ref this.isSending, 1, 0) != 0) | |
| { | |
| throw new InvalidOperationException("SendAsync is already in progress."); | |
| } | |
| try | |
| { | |
| using (MemoryStream contentStream = new MemoryStream(this.Content)) | |
| { | |
| HttpRequestMessage request = this.CreateRequestMessage(this.EndpointAddress, contentStream); | |
| HttpWebResponseWrapper wrapper = null; | |
| long responseDurationInMs = 0; | |
| try | |
| { | |
| using (var ct = new CancellationTokenSource(this.Timeout)) | |
| { | |
| // HttpClient.SendAsync throws HttpRequestException only on the following scenarios: | |
| // "The request failed due to an underlying issue such as network connectivity, DNS failure, server certificate validation or timeout." | |
| // i.e for Server errors (500 status code), no exception is thrown. Hence this method should read the response and status code, | |
| // and return correct HttpWebResponseWrapper to give any Retry policies a chance to retry as needed. | |
| var stopwatch = new Stopwatch(); | |
| stopwatch.Start(); | |
| using (var response = await client.SendAsync(request, ct.Token).ConfigureAwait(false)) | |
| { | |
| stopwatch.Stop(); | |
| responseDurationInMs = stopwatch.ElapsedMilliseconds; | |
| CoreEventSource.Log.IngestionResponseTime(response != null ? (int)response.StatusCode : -1, responseDurationInMs); | |
| // Log ingestion respose time as event counter metric. | |
| CoreEventSource.Log.IngestionResponseTimeEventCounter(stopwatch.ElapsedMilliseconds); | |
| if (response != null) |