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(node): Add shouldCreateSpanForRequest option #6055

Conversation

timfish
Copy link
Collaborator

@timfish timfish commented Oct 26, 2022

As per the summary here, this PR adds support for an optional shouldCreateSpanForRequest function in the options. When it's defined and returns false, spans will not be attached.

Copy link
Member

@lobsterkatie lobsterkatie left a comment

Choose a reason for hiding this comment

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

Looks good so far!

Comment on lines 113 to 119
const shouldCreateSpan = (url: string): boolean => {
if (options?.shouldCreateSpanForRequest === undefined) {
return true;
}

return options.shouldCreateSpanForRequest(url);
};
Copy link
Member

Choose a reason for hiding this comment

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

I think we should cache the results of shouldCreateSpanForRequest. On the browser side, I can't decide if it's worth it, but in node where bundle size isn't a concern but being able to most efficiently handle lots of incoming requests quickly is, I think we definitely should (the same way we're doing with tracePropagationTargets just below).

Copy link
Collaborator Author

@timfish timfish Oct 28, 2022

Choose a reason for hiding this comment

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

Since lru_map is already a dependency for the ContextLines integration, should I use that rather than an alternative that could potentially grow indefinitely?

If we cache the result of shouldCreateSpanForRequest we should probably mention this in the jsdocs/docs since it's not obvious and users may think they can use shouldCreateSpanForRequest to dynamically stop span generation.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I just used a map for now!

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, missed your question. You raise two good points. I think for now a map is simple and hasn't bitten us on the header front, so is unlikely to bite us here, either. If it does, I'm sure someone will let us know! And good point about the docs.

packages/node/src/types.ts Outdated Show resolved Hide resolved
@timfish timfish marked this pull request as ready for review October 31, 2022 14:09
@timfish timfish self-assigned this Oct 31, 2022
Copy link
Member

@lobsterkatie lobsterkatie left a comment

Choose a reason for hiding this comment

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

LGTM!

@lobsterkatie lobsterkatie changed the title feat(node): Add shouldCreateSpanForRequest option and don't add spans when it returns false feat(node): Add shouldCreateSpanForRequest option Nov 4, 2022
@lobsterkatie lobsterkatie merged commit 24e2a27 into getsentry:master Nov 4, 2022
@timfish timfish deleted the feat/node-add-shouldCreateSpanForRequest branch November 29, 2022 09:35
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.

2 participants