dd-trace-dotnet icon indicating copy to clipboard operation
dd-trace-dotnet copied to clipboard

Show full duration of response for HttpClient calls

Open AbubakerB opened this issue 4 years ago • 1 comments

Hi, I'm not sure if this is a bug or a request for a new feature or both!

Are you requesting automatic instrumentation for a framework or library? Please describe.

  • Framework or library name : .NET Core
  • Library type: System.Net.Http
  • Library version: 5.0.0.0

Is your feature request related to a problem? Please describe.

TL;DR: Calls using HttpClient seem to only instrument the duration of the requests up until all the headers read, but not the content.

Explanation: We are using automatic instrumentation and are seeing odd spaces in between http calls. For example,

[--------------------------- controller / action invoked ----------------------]
...[http - POST /api/s1]......................[http - GET /api/s2][http GET xyz]

The three http calls pretty much all happen one after the other. There are a few POCO mappings in between calls based on the response. I looked into this a little bit and realised that the issue may be due to how DataDog auto-instruments HTTP calls.

The first service call has quite a large response and it seems that auto instrumentation hooks into the SendAsync methods of the (derived) HttpMessageHandler. However, as you're most likely aware, HttpClient.SendAsync (and all other calls - GetAsync/PostAsync/etc...) has an HttpCompletionOption of ResponseContentRead by default, but the content is read outside of the HttpMessageHandler.SendAsync method, which explains why we have a gap in our span.

Describe the solution you'd like Ideally we'd like to see the whole method of HttpClient.SendAsync included in the span by default (maybe even split into request/response duration if HttpCompletionOption.ResponseContentRead is used?).

Describe alternatives you've considered From what I understand, I can add this myself into my code by:

  1. Installing the instrumentation package
  2. Changing my HttpClient.SendAsync to take the HttpCompletionOption.ResponseHeadersRead
  3. Adding a custom span across the response.Content.ReadXYZ() methods.

Additional context

  • .NET Core 5.0
  • Auto Instrumentation
  • Tracer version 1.27.1

AbubakerB avatar Jul 21 '21 18:07 AbubakerB

Thanks for reporting this, @AbubakerB. We will look into it and report back.

lucaspimentel avatar Jul 21 '21 19:07 lucaspimentel