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(koa): add requestHook support #1099

Merged
merged 9 commits into from
Aug 10, 2022

Conversation

luismiramirez
Copy link
Contributor

The requestHook support allows custom span handling per middleware
layer on requests.

Which problem is this PR solving?

  • Adds requestHook support so users can add custom handling on spans per middleware layer on requests.

Short description of the changes

  • It's inspired by how requestHook is implemented in other instrumentations
  • The requestHook user-defined function is called any time a patched middleware runs and if the function exists.

Checklist

  • Ran npm run test-all-versions for the edited package(s) on the latest commit if applicable.

@luismiramirez luismiramirez requested a review from a team July 27, 2022 11:11
Comment on lines +35 to +39
export type KoaRequestInfo = {
context: KoaContext;
middlewareLayer: KoaMiddleware;
};

Copy link
Member

Choose a reason for hiding this comment

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

Why do we need this type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for noticing. This should be part of the requestHook. Fixing it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed! The idea is to replicate the behaviour suggested here: #1091 (comment)

Copy link
Member

Choose a reason for hiding this comment

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

Oh yea, i wasn't sure if that's what u meant to do.
Nice :)

@codecov
Copy link

codecov bot commented Jul 27, 2022

Codecov Report

Merging #1099 (9a7d5e9) into main (cff4e77) will increase coverage by 0.29%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #1099      +/-   ##
==========================================
+ Coverage   96.07%   96.36%   +0.29%     
==========================================
  Files          14       19       +5     
  Lines         892     1046     +154     
  Branches      191      220      +29     
==========================================
+ Hits          857     1008     +151     
- Misses         35       38       +3     
Impacted Files Coverage Δ
...ode/opentelemetry-instrumentation-koa/src/types.ts 100.00% <ø> (ø)
...lemetry-instrumentation-koa/src/instrumentation.ts 97.53% <100.00%> (ø)
...tapackages/auto-instrumentations-node/src/utils.ts 98.00% <0.00%> (ø)
...ode/opentelemetry-instrumentation-koa/src/utils.ts 100.00% <0.00%> (ø)
...ry-instrumentation-koa/src/enums/AttributeNames.ts 100.00% <0.00%> (ø)

The `requestHook` support allows custom span handling per middleware
layer on requests.
);

const requestHook = sinon.spy((span: Span, info: KoaRequestInfo) => {
span.setAttribute('http.method', info.context.request.method);
Copy link
Member

Choose a reason for hiding this comment

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

better to use the enum SemanticAttributes.HTTP_METHOD

@vmarchaud
Copy link
Member

@luismiramirez friendly ping because the lint is failling

@luismiramirez
Copy link
Contributor Author

@vmarchaud Linter issues addressed!

@vmarchaud vmarchaud merged commit 99279d5 into open-telemetry:main Aug 10, 2022
@dyladan dyladan mentioned this pull request Aug 10, 2022
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.

4 participants