Skip to content

Conversation

@nkomonen-amazon
Copy link
Contributor

@nkomonen-amazon nkomonen-amazon commented Oct 19, 2024

See each commit for the specific change. But this has multiple improvements to the @withTelemetryContext decorator.

The main change to note:

  • Adding the @withTelemetryContext decorator to a method can wrap thrown errors with context about that function. This helps us to build some sort of stack trace in the reasonDesc of our telemetry when errors are thrown.
  • The decorator allows for minimal diffs to the code. It is replacing this previous code which would cause a diff in the column indentation since all the method code needed to be in a callback

License: I confirm that my contribution is made under the terms of the Apache 2.0 license.

@nkomonen-amazon nkomonen-amazon requested a review from a team as a code owner October 19, 2024 03:16
@nkomonen-amazon nkomonen-amazon force-pushed the addErrorContext branch 4 times, most recently from b3f2ad9 to 5b1ee06 Compare October 22, 2024 16:22
@nkomonen-amazon
Copy link
Contributor Author

/runIntegrationTests

@nkomonen-amazon
Copy link
Contributor Author

@justinmk3 can you give this a look when you have time

)
})

const customWithTelemetryContext = withTelemetryContextFactory({ class: 'TestCustomContext', emit: true })
Copy link
Contributor

Choose a reason for hiding this comment

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

Modules can define their own predefined fields. That's more explicit, and avoids this extra layer (we already have too many layers). And avoids these extra tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense, removed

@justinmk3
Copy link
Contributor

Manually annotating the "code path" can be useful in specific, but it is not a sustainable approach in general. Can we evaluate something like https://github.com/felixge/node-stack-trace to inspect the actual stacktrace instead?

@nkomonen-amazon
Copy link
Contributor Author

@justinmk3 agreed that something more automatic would be better. A possible issue with stack traces is due to the bundling, there may be a way around that but it doesn't look trivial.

@justinmk3
Copy link
Contributor

possible issue with stack traces is due to the bundling

Ah right. I think we can (and should) fix that with sourcemaps, and e.g. webpack config: https://stackoverflow.com/a/58448086/152142

To unblock this, can we remove withTelemetryContextFactory.

The withTelemetryContext() decorator adds context to telemetry
but not thrown errors.

Solution:

Adding this decorator to a method will add context to any thrown exceptions.
This is helpful in telemetry as it will provide information about the caller.

Signed-off-by: nkomonen-amazon <[email protected]>
Now the @withTelemetryContext decorator can have a method emit when called
and will also add the `source` field automatically.

By default it does not emit.

Signed-off-by: nkomonen-amazon <[email protected]>
Signed-off-by: nkomonen-amazon <[email protected]>
Signed-off-by: nkomonen-amazon <[email protected]>
- Simplify tests
- Fix typos

Signed-off-by: nkomonen-amazon <[email protected]>
Signed-off-by: nkomonen-amazon <[email protected]>
It can just be done explicitly by anything that needs it

Signed-off-by: nkomonen-amazon <[email protected]>
Copy link
Contributor

@justinmk3 justinmk3 left a comment

Choose a reason for hiding this comment

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

We should find a way to solve this problem that doesn't require explicit annotations. Can merge this for now though.

@nkomonen-amazon nkomonen-amazon merged commit 135c3e5 into aws:master Nov 18, 2024
22 of 25 checks passed
@nkomonen-amazon nkomonen-amazon deleted the addErrorContext branch November 18, 2024 14:52
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.

3 participants