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

feat: record exceptions in http instrumentation #3008

Merged

Conversation

luismiramirez
Copy link
Contributor

Which problem is this PR solving?

When an error is captured, it is now recorded as an event using recordException().

Short description of the changes

Added the recordException call right after the status setup in setSpanWithError().

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Updated the helper that compares spans so it supports errors being passed and checks if they've been recorded.

Checklist:

  • Followed the style guidelines of this project
  • Unit tests have been added
  • Documentation has been updated

@luismiramirez luismiramirez requested a review from a team May 31, 2022 09:40
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented May 31, 2022

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: luismiramirez / name: Luismi Ramírez (a1a8945)

@luismiramirez luismiramirez force-pushed the record-http-errors-as-events branch from a1a8945 to 63c0929 Compare May 31, 2022 11:53
@codecov
Copy link

codecov bot commented May 31, 2022

Codecov Report

Merging #3008 (317d839) into main (922e963) will decrease coverage by 1.39%.
The diff coverage is n/a.

❗ Current head 317d839 differs from pull request most recent head 279dec9. Consider uploading reports for the commit 279dec9 to get more accurate results

@@            Coverage Diff             @@
##             main    #3008      +/-   ##
==========================================
- Coverage   92.63%   91.24%   -1.40%     
==========================================
  Files         187       68     -119     
  Lines        6166     1850    -4316     
  Branches     1301      392     -909     
==========================================
- Hits         5712     1688    -4024     
+ Misses        454      162     -292     
Impacted Files Coverage Δ
packages/opentelemetry-resources/karma.worker.js 0.00% <0.00%> (-100.00%) ⬇️
...ckages/opentelemetry-sdk-trace-web/karma.worker.js 0.00% <0.00%> (-100.00%) ⬇️
...s/opentelemetry-core/src/platform/node/sdk-info.ts 0.00% <0.00%> (-100.00%) ⬇️
...opentelemetry-core/src/platform/node/globalThis.ts 0.00% <0.00%> (-100.00%) ⬇️
...pentelemetry-core/src/platform/node/performance.ts 0.00% <0.00%> (-100.00%) ⬇️
...emetry-api-metrics/src/platform/node/globalThis.ts 0.00% <0.00%> (-100.00%) ⬇️
...lemetry-resources/src/detectors/ProcessDetector.ts 31.81% <0.00%> (-68.19%) ⬇️
...perimental/packages/otlp-exporter-base/src/util.ts 79.41% <0.00%> (-17.65%) ⬇️
...ckages/opentelemetry-exporter-zipkin/src/zipkin.ts 84.48% <0.00%> (-15.52%) ⬇️
...lemetry-resources/src/detectors/BrowserDetector.ts 93.33% <0.00%> (-6.67%) ⬇️
... and 119 more

Copy link
Member

@blumamir blumamir left a comment

Choose a reason for hiding this comment

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

LGTM
Thanks for the contribution

Interesting OTEP regarding the future of SpanEvents: https://github.com/open-telemetry/oteps/pull/202/files

@luismiramirez luismiramirez force-pushed the record-http-errors-as-events branch from 63c0929 to 1248bb6 Compare June 1, 2022 06:57
Copy link
Member

@dyladan dyladan left a comment

Choose a reason for hiding this comment

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

LGTM % testing nit

@luismiramirez luismiramirez force-pushed the record-http-errors-as-events branch from 1248bb6 to b6d57fc Compare June 1, 2022 14:26
@luismiramirez luismiramirez force-pushed the record-http-errors-as-events branch from b6d57fc to 03cabe4 Compare June 1, 2022 14:59
Copy link
Member

@legendecas legendecas left a comment

Choose a reason for hiding this comment

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

LGTM % nits.

assert.strictEqual(span.events[0].name, 'exception');

const eventAttributes = span.events[0].attributes as Object;
assert.deepEqual(
Copy link
Member

Choose a reason for hiding this comment

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

Strict version of assert.deepEqual is preferred:

Suggested change
assert.deepEqual(
assert.deepStrictEqual(

assert.strictEqual(span.events.length, 1);
assert.strictEqual(span.events[0].name, 'exception');

const eventAttributes = span.events[0].attributes as Object;
Copy link
Member

Choose a reason for hiding this comment

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

I'd suggest asserting the eventAttributes to be non-nullish rather than casting it as an object -- the casting has no runtime-effect, we'll get a TypeError below if it is actually an undefined.

Suggested change
const eventAttributes = span.events[0].attributes as Object;
const eventAttributes = span.events[0].attributes;
assert.ok(eventAttributes != null);

@luismiramirez luismiramirez force-pushed the record-http-errors-as-events branch 3 times, most recently from 074c0a3 to 5f6880e Compare June 8, 2022 07:14
@luismiramirez luismiramirez force-pushed the record-http-errors-as-events branch from 5f6880e to 279dec9 Compare June 9, 2022 07:52
@legendecas legendecas merged commit c8c4ec6 into open-telemetry:main Jun 13, 2022
@legendecas
Copy link
Member

Thank you for your contribution!

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.

5 participants