Skip to content

Commit

Permalink
Add response duration to TransmissionStatusEventArgs
Browse files Browse the repository at this point in the history
  • Loading branch information
rajkumar-rangaraj committed Jan 22, 2021
1 parent 5c999c8 commit 8d6e3a9
Show file tree
Hide file tree
Showing 6 changed files with 30 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; }
}
}

0 comments on commit 8d6e3a9

Please sign in to comment.