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

Only set params on Koa router layer #757

Merged
merged 4 commits into from
Nov 3, 2022
Merged

Only set params on Koa router layer #757

merged 4 commits into from
Nov 3, 2022

Conversation

unflxw
Copy link
Contributor

@unflxw unflxw commented Oct 11, 2022

Only set params on router layer

To avoid setting the params in many different spans, potentially
interfering with custom instrumentation on those same params, only
set the params on the router layer.

Bump Koa instrumentation version

Update to the latest version of @opentelemetry/instrumentation-koa
for the request hook info to contain the layer type.

Allow span to be passed to helpers

Not every instrumentation makes the spans that they're working
with into active spans for the current context. Additionally,
some instrumentations provide hooks where the relevant span is
provided as an argument, but is not the active span.

To account for these scenarios, the helpers now take an optional
span argument as their final argument (except for sendError, which
always creates a new span)

Pass span to params helper in Koa hook

When the Koa instrumentation request hook is executed, the current
active span is the span from the previous layer. This means that,
for the router layer, the active span is the last middleware in the
middleware chain.

While this is fine functionally, it makes the behaviour of the hook
hard to reason about. This change makes it so that the params are
set in the span passed to the hook, instead of in the active span.

The integration tests are also amended to check for the params in
the router child span.

@unflxw unflxw self-assigned this Oct 11, 2022
@unflxw unflxw added the chore label Oct 11, 2022
@backlog-helper
Copy link

backlog-helper bot commented Oct 11, 2022

✔️ All good!

New issue guide | Backlog management | Rules | Feedback

@unflxw unflxw force-pushed the fix-koa-span-params branch 2 times, most recently from 1a8f3f7 to 086d959 Compare November 3, 2022 13:27
@unflxw unflxw marked this pull request as ready for review November 3, 2022 13:34
@unflxw unflxw changed the title Only set params on router layer Only set params on Koa router layer Nov 3, 2022
Copy link
Member

@luismiramirez luismiramirez left a comment

Choose a reason for hiding this comment

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

I think this one needs a changeset

To avoid setting the params in many different spans, potentially
interfering with custom instrumentation on those same params, only
set the params on the router layer.
Update to the latest version of `@opentelemetry/instrumentation-koa`
for the request hook info to contain the layer type.
Not every instrumentation makes the spans that they're working
with into active spans for the current context. Additionally,
some instrumentations provide hooks where the relevant span is
provided as an argument, but is not the active span.

To account for these scenarios, the helpers now take an optional
span argument as their final argument (except for sendError, which
always creates a new span)
When the Koa instrumentation request hook is executed, the current
active span is the span from the _previous_ layer. This means that,
for the router layer, the active span is the last middleware in the
middleware chain.

While this is fine functionally, it makes the behaviour of the hook
hard to reason about. This change makes it so that the params are
set in the span passed to the hook, instead of in the active span.

The integration tests are also amended to check for the params in
the router child span.
@unflxw unflxw force-pushed the fix-koa-span-params branch from 086d959 to 295858e Compare November 3, 2022 14:07
@unflxw unflxw merged commit 1eba19e into main Nov 3, 2022
unflxw added a commit that referenced this pull request Nov 7, 2022
In #757, the signature of the helpers was changed to add an optional
span argument. If present, the custom attribute or event set by the
helper will be set in the given span, instead of on the current
active span.

I meant to add tests for it when making the change, but then I
forgot. Here are the tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants