Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HttpClient] Add error.type for traces and metrics #5005

Conversation

vishweshbankwar
Copy link
Member

@vishweshbankwar vishweshbankwar commented Oct 30, 2023

Fixes #
Design discussion issue #

Changes

Adds error.type attribute to activity and http.client.request.duration for HttpClient for non-netframework targets.

  1. Adds error.type attribute to activity for netstandard, net6.0 , net7.0 and net8.0 targets. For net8.0 target the value will vary due to the addition of HttpRequestError Enum, which allows further drilldown of HttpRequestException \ HttpIOExceptiontype. This is in sync with how the tag is emitted on httpclient.request.duration metric on .NET8.0.
  2. Adds error.type attribute to http.client.request.duration metric for netstandard, net6.0 and net7.0 targets. On net8.0, metric will be emitted via added meter System.Net.Http within instrumentation library.

TODO: Cover HttpWebRequest.

Merge requirement checklist

  • CONTRIBUTING guidelines followed (nullable enabled, static analysis, etc.)
  • Unit tests added/updated
  • Appropriate CHANGELOG.md files updated for non-trivial changes
  • Changes in public API reviewed (if applicable)

@codecov
Copy link

codecov bot commented Oct 30, 2023

Codecov Report

Merging #5005 (783ef33) into main (f2ab976) will decrease coverage by 0.31%.
Report is 1 commits behind head on main.
The diff coverage is 78.75%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #5005      +/-   ##
==========================================
- Coverage   83.69%   83.39%   -0.31%     
==========================================
  Files         296      296              
  Lines       12403    12452      +49     
==========================================
+ Hits        10381    10384       +3     
- Misses       2022     2068      +46     
Flag Coverage Δ
unittests 83.39% <78.75%> (-0.31%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
...ementation/HttpHandlerMetricsDiagnosticListener.cs 90.14% <87.27%> (-7.64%) ⬇️
...tp/Implementation/HttpHandlerDiagnosticListener.cs 73.50% <60.00%> (-3.06%) ⬇️

... and 7 files with indirect coverage changes

@vishweshbankwar vishweshbankwar marked this pull request as ready for review November 6, 2023 19:26
@vishweshbankwar vishweshbankwar requested a review from a team as a code owner November 6, 2023 19:26
@@ -271,6 +271,11 @@ public void OnStopActivity(Activity activity, object payload)

if (TryFetchResponse(payload, out HttpResponseMessage response))
{
if (currentStatusCode == ActivityStatusCode.Unset)
{
activity.SetStatus(SpanHelper.ResolveSpanStatusForHttpStatusCode(activity.Kind, (int)response.StatusCode));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this change related to "error.type" ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this was there already

if (currentStatusCode == ActivityStatusCode.Unset)
{
activity.SetStatus(SpanHelper.ResolveSpanStatusForHttpStatusCode(activity.Kind, (int)response.StatusCode));
}
. I just moved it to the top.

vishweshbankwar and others added 4 commits November 6, 2023 16:06
…lerDiagnosticListener.cs

Co-authored-by: Utkarsh Umesan Pillai <66651184+utpilla@users.noreply.github.com>
Co-authored-by: Utkarsh Umesan Pillai <66651184+utpilla@users.noreply.github.com>
…lerMetricsDiagnosticListener.cs

Co-authored-by: Timothy Mothra <tilee@microsoft.com>
vishweshbankwar and others added 3 commits November 6, 2023 16:18
Co-authored-by: Utkarsh Umesan Pillai <66651184+utpilla@users.noreply.github.com>
Co-authored-by: Utkarsh Umesan Pillai <66651184+utpilla@users.noreply.github.com>
…lerMetricsDiagnosticListener.cs

Co-authored-by: Utkarsh Umesan Pillai <66651184+utpilla@users.noreply.github.com>
Copy link
Contributor

@utpilla utpilla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Tests should be simplified once #4928 is addressed.

Copy link
Member

@CodeBlanch CodeBlanch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@CodeBlanch CodeBlanch merged commit 4a3c8d3 into open-telemetry:main Nov 8, 2023
70 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants