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(tracer): specify subsegment name when capturing class method #1092

Conversation

dreamorosi
Copy link
Contributor

@dreamorosi dreamorosi commented Sep 19, 2022

Description of your changes

Community member @misterjoshua suggested a feature in #1084 to allow customers to set a custom name for the subsegment generated by the Tracer.captureMethod method.

At the moment Tracer automatically sets the subsegment name to the same value of the name of the method. This is a sensible choice but in some cases, when using non descriptive method names, customers might want to set their own names.

This PR adds an optional parameter to the options for captureMethod so that the custom name can be set. The PR also splits the type used for the options in captureMethod and captureLambdaHandler so that the new parameter is valid only for the former (the latter will always be called ## index.${HANDLER NAME} for now).

The PR also adds unit test cases as well as e2e test cases and does some light housekeeping around the e2e tests and docstrings related to this feature.

How to verify this change

Check out newly added unit test cases and new e2e test cases (results here).

Related issues, RFCs

Issue number: #1084

PR status

Is this ready for review?: YES
Is it a breaking change?: NO

Checklist

  • My changes meet the tenets criteria
  • I have performed a self-review of my own code
  • I have commented my code where necessary, particularly in areas that should be flagged with a TODO, or hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding changes to the examples
  • My changes generate no new warnings
  • The code coverage hasn't decreased
  • I have added tests that prove my change is effective and works
  • New and existing unit tests pass locally and in Github Actions
  • Any dependent changes have been merged and published in downstream module
  • The PR title follows the conventional commit semantics

Breaking change checklist

N/A


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@dreamorosi dreamorosi added the tracer This item relates to the Tracer Utility label Sep 19, 2022
@dreamorosi dreamorosi self-assigned this Sep 19, 2022
Copy link
Contributor

@misterjoshua misterjoshua left a comment

Choose a reason for hiding this comment

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

Just a few small nitpicks in the docs. Otherwise, this looks good to me.

docs/core/tracer.md Outdated Show resolved Hide resolved
packages/tracer/src/types/Tracer.ts Outdated Show resolved Hide resolved
dreamorosi and others added 2 commits September 20, 2022 11:14
Co-authored-by: Josh Kellendonk <misterjoshua@users.noreply.github.com>
@dreamorosi
Copy link
Contributor Author

Just a few small nitpicks in the docs. Otherwise, this looks good to me.

Thank you for taking a look at this and good spotting the mistakes in the docstrings, I have committed your suggestions :)

ijemmy
ijemmy previously approved these changes Oct 6, 2022
Comment on lines +12 to +13
const customMetadataValue = process.env.EXPECTED_CUSTOM_METADATA_VALUE ? JSON.parse(process.env.EXPECTED_CUSTOM_METADATA_VALUE) : { bar: 'baz' };
const customResponseValue = process.env.EXPECTED_CUSTOM_RESPONSE_VALUE ? JSON.parse(process.env.EXPECTED_CUSTOM_RESPONSE_VALUE) : { foo: 'bar' };
Copy link
Contributor

Choose a reason for hiding this comment

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

Question: Why switching away from ?? here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Parsing a non-JSON / undefined value throws an error rather than evaluate to false, so if the goal was to use the default value (after the ??) when one is not explicitly provided in the env, then this should be correct.

image

Happy to revert if you think it's not ok or I misunderstood the intent of the original expression.

Copy link
Contributor

Choose a reason for hiding this comment

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

No. I just want to check that it's really a missing edge case.

@dreamorosi dreamorosi merged commit d4174eb into main Oct 11, 2022
@dreamorosi dreamorosi deleted the 1084-feature-tracer-allow-users-to-specify-segment-names-for-captured-methods branch October 11, 2022 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tracer This item relates to the Tracer Utility
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: Allow users to specify segment names for captured methods
4 participants