Skip to content

Commit

Permalink
Merge pull request #2157 from microsoft/rajrang/transDuration
Browse files Browse the repository at this point in the history
Add ingestion response duration to data delivery status (TransmissionStatusEventArgs)
  • Loading branch information
rajkumar-rangaraj authored Jan 26, 2021
2 parents 5c999c8 + 03c9ac5 commit 7223ab5
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Microsoft.ApplicationInsights.Channel.TransmissionStatusEventArgs.ResponseDurationInMs.get -> long
Microsoft.ApplicationInsights.Channel.TransmissionStatusEventArgs.TransmissionStatusEventArgs(Microsoft.ApplicationInsights.Extensibility.Implementation.HttpWebResponseWrapper response, long responseDurationInMs) -> void
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Microsoft.ApplicationInsights.Channel.TransmissionStatusEventArgs.ResponseDurationInMs.get -> long
Microsoft.ApplicationInsights.Channel.TransmissionStatusEventArgs.TransmissionStatusEventArgs(Microsoft.ApplicationInsights.Extensibility.Implementation.HttpWebResponseWrapper response, long responseDurationInMs) -> void
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Microsoft.ApplicationInsights.Channel.TransmissionStatusEventArgs.ResponseDurationInMs.get -> long
Microsoft.ApplicationInsights.Channel.TransmissionStatusEventArgs.TransmissionStatusEventArgs(Microsoft.ApplicationInsights.Extensibility.Implementation.HttpWebResponseWrapper response, long responseDurationInMs) -> void
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,7 @@ public async Task TestTransmissionStatusEventHandlerWithSuccessTransmission()
{
Assert.IsTrue(sender is Transmission);
Assert.AreEqual((int)HttpStatusCode.OK, args.Response.StatusCode);
Assert.AreNotEqual(0, args.ResponseDurationInMs);
};

// ACT
Expand Down Expand Up @@ -559,6 +560,7 @@ public async Task TestTransmissionStatusEventHandlerWithKnownFailureTransmission
transmission.TransmissionStatusEvent += delegate (object sender, TransmissionStatusEventArgs args)
{
Assert.AreEqual((int)HttpStatusCode.RequestTimeout, args.Response.StatusCode);
Assert.AreEqual(0, args.ResponseDurationInMs);
};

// ACT
Expand Down Expand Up @@ -589,6 +591,7 @@ public async Task TestTransmissionStatusEventHandlerWithUnKnownFailureTransmissi
transmission.TransmissionStatusEvent += delegate (object sender, TransmissionStatusEventArgs args)
{
Assert.AreEqual(999, args.Response.StatusCode);
Assert.AreEqual(0, args.ResponseDurationInMs);
};

// ACT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ public virtual async Task<HttpWebResponseWrapper> SendAsync()
{
HttpRequestMessage request = this.CreateRequestMessage(this.EndpointAddress, contentStream);
HttpWebResponseWrapper wrapper = null;
long responseDurationInMs = 0;

try
{
Expand All @@ -171,7 +172,8 @@ public virtual async Task<HttpWebResponseWrapper> SendAsync()
using (var response = await client.SendAsync(request, ct.Token).ConfigureAwait(false))
{
stopwatch.Stop();
CoreEventSource.Log.IngestionResponseTime(response != null ? (int)response.StatusCode : -1, stopwatch.ElapsedMilliseconds);
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);

Expand Down Expand Up @@ -225,7 +227,7 @@ public virtual async Task<HttpWebResponseWrapper> SendAsync()
try
{
// Initiates event notification to subscriber with Transmission and TransmissionStatusEventArgs.
this.TransmissionStatusEvent?.Invoke(this, new TransmissionStatusEventArgs(wrapper ?? new HttpWebResponseWrapper() { StatusCode = 999 }));
this.TransmissionStatusEvent?.Invoke(this, new TransmissionStatusEventArgs(wrapper ?? new HttpWebResponseWrapper() { StatusCode = 999 }, responseDurationInMs));
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,30 @@ public class TransmissionStatusEventArgs : EventArgs
/// Initializes a new instance of the <see cref="TransmissionStatusEventArgs"/> class.
/// </summary>
/// <param name="response">Response from ingestion endpoint.</param>
public TransmissionStatusEventArgs(HttpWebResponseWrapper response)
[ObsoleteAttribute("This constructor is deprecated. Please use a constructor that accepts response and responseDurationInMs instead.", false)]
public TransmissionStatusEventArgs(HttpWebResponseWrapper response) : this(response, default)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="TransmissionStatusEventArgs"/> class.
/// </summary>
/// <param name="response">Response from ingestion endpoint.</param>
/// <param name="responseDurationInMs">Response duration in milliseconds.</param>
public TransmissionStatusEventArgs(HttpWebResponseWrapper response, long responseDurationInMs)
{
this.Response = response;
this.ResponseDurationInMs = responseDurationInMs;
}

/// <summary>
/// Gets the response from ingestion endpoint.
/// </summary>
public HttpWebResponseWrapper Response { get; }

/// <summary>
/// Gets response duration in milliseconds.
/// </summary>
public long ResponseDurationInMs { get; }
}
}
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## VNext
[Fix: telemetry parent id when using W3C activity format in TelemetryDiagnosticSourceListener](https://github.com/microsoft/ApplicationInsights-dotnet/issues/2142)
[Add ingestion response duration for transmission to data delivery status - TransmissionStatusEventArgs](https://github.com/microsoft/ApplicationInsights-dotnet/pull/2157)

## Version 2.17.0-beta1
- [Fix: Missing Dependencies when using Microsoft.Data.SqlClient v2.0.0](https://github.com/microsoft/ApplicationInsights-dotnet/issues/2032)
Expand Down

0 comments on commit 7223ab5

Please sign in to comment.