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

fix(instrumentation-http): set outgoing request attributes on start span #2349

Merged
merged 8 commits into from Jul 17, 2021
Merged

fix(instrumentation-http): set outgoing request attributes on start span #2349

merged 8 commits into from Jul 17, 2021

Conversation

blumamir
Copy link
Member

Which problem is this PR solving?

Fixes #1255
Fixes #2320
And fix an HTTP instrumentation test: 'should have 1 ended span when request throw on bad "options" object'

For HTTP instrumentation, the span for outgoing request is currently started (startSpan) without any attributes. Only later when response arrives, request and response attributes are calculated and set on it. This is problematic in 2 situations:

  • if exception is thrown before the response arrives (for example, if the parameters are not valid), then the span is closed and there are no attributes on it for user to understand the context (no URL, method).
  • sampler can only take decisions based on attributes that are available during startSpan function call (on the options). Request attributes are already available at this point, but since they are not sent to startSpan, sampling is impossible for this case.

Additionally, there is a test for HTTP instrumentation called 'should have 1 ended span when request throw on bad "options" object', which calls http.request assuming it will throw, and then asserting in the catch block, but the function did not actually throw, so the test didn't check anything at all.

Short description of the changes

I moved the request attributes calculation to happen before starting the span (instead of doing it when response arrive), which solves the 2 issues above.
I also changed the mentioned test so it actually throws an error, and added assertions in it for the logic I changed in the code.

@blumamir
Copy link
Member Author

Looks like I also pushed some layout changes in the http.ts which does not seem to be fixed by running lint:fix. I assume it happened when I clicked Options + Shift + F in vsc. Can someone point me to how I can revert them correctly?

@dyladan
Copy link
Member

dyladan commented Jul 14, 2021

Looks like I also pushed some layout changes in the http.ts which does not seem to be fixed by running lint:fix. I assume it happened when I clicked Options + Shift + F in vsc. Can someone point me to how I can revert them correctly?

I see you pushed an update after this. Did you manage to get it fixed? In my experience when the lint:fix doesn't work it's because there is a syntax error preventing the linter from correctly parsing the file. Otherwise it will explicitly print what the error was that it couldn't fix.

@codecov
Copy link

codecov bot commented Jul 14, 2021

Codecov Report

Merging #2349 (967a152) into main (5aabcc7) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##             main    #2349   +/-   ##
=======================================
  Coverage   92.77%   92.77%           
=======================================
  Files         145      145           
  Lines        5220     5221    +1     
  Branches     1069     1070    +1     
=======================================
+ Hits         4843     4844    +1     
  Misses        377      377           
Impacted Files Coverage Δ
...ges/opentelemetry-instrumentation-http/src/http.ts 94.88% <100.00%> (-0.03%) ⬇️
...es/opentelemetry-instrumentation-http/src/utils.ts 99.02% <100.00%> (+<0.01%) ⬆️

@dyladan dyladan added this to In progress in SDK General Availability via automation Jul 14, 2021
@blumamir
Copy link
Member Author

blumamir commented Jul 14, 2021

I see you pushed an update after this. Did you manage to get it fixed? In my experience when the lint:fix doesn't work it's because there is a syntax error preventing the linter from correctly parsing the file. Otherwise it will explicitly print what the error was that it couldn't fix.

Couldn't fix it yet. Looks like my IDE enforces a shorter line width (when calling "Option + Shift + F") which is something that is not configured in eslint.config.js for the project. Do you happen to know what is the value currently used in the project?

@blumamir
Copy link
Member Author

Looks like I also pushed some layout changes in the http.ts which does not seem to be fixed by running lint:fix. I assume it happened when I clicked Options + Shift + F in vsc. Can someone point me to how I can revert them correctly?

reverted the changes manually (it wasn't fun). ready for review :)

@dyladan
Copy link
Member

dyladan commented Jul 14, 2021

I see you pushed an update after this. Did you manage to get it fixed? In my experience when the lint:fix doesn't work it's because there is a syntax error preventing the linter from correctly parsing the file. Otherwise it will explicitly print what the error was that it couldn't fix.

Couldn't fix it yet. Looks like my IDE enforces a shorter line width (when calling "Option + Shift + F") which is something that is not configured in eslint.config.js for the project. Do you happen to know what is the value currently used in the project?

If it's not in the config it most likely uses the default value.

@blumamir
Copy link
Member Author

If it's not in the config it most likely uses the default value.

I'm not very familiar with linting. Is the default value coming from the environment and can be potentially different in different setups?

@weyert
Copy link
Contributor

weyert commented Jul 14, 2021

I think we should define a prettier config file in the js-repos to avoid this mismatches

Copy link
Contributor

@weyert weyert left a comment

Choose a reason for hiding this comment

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

Looks good to me!

SDK General Availability automation moved this from In progress to Reviewer approved Jul 17, 2021
@vmarchaud vmarchaud merged commit 0e3f03f into open-telemetry:main Jul 17, 2021
SDK General Availability automation moved this from Reviewer approved to Done Jul 17, 2021
@dyladan dyladan added the enhancement New feature or request label Jul 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
6 participants