-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(cloudflare): Add allow list to enableRpcTracePropagation #23363
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
Open
+219
−3
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import { stringMatchesSomePattern } from '@sentry/core'; | ||
| import type { CloudflareOptions } from '../client'; | ||
|
|
||
| const PROPAGATE_TO_NONE = () => false; | ||
| const PROPAGATE_TO_ALL = () => true; | ||
|
|
||
| /** | ||
| * Builds the per-binding predicate that decides whether a binding takes part in RPC trace | ||
| * propagation. | ||
| */ | ||
| export function createRpcPropagationResolver(options: CloudflareOptions | undefined): (bindingName: string) => boolean { | ||
| const value: CloudflareOptions['enableRpcTracePropagation'] | undefined = options?.enableRpcTracePropagation; | ||
|
|
||
| if (value === true) { | ||
| return PROPAGATE_TO_ALL; | ||
| } | ||
|
|
||
| if (!Array.isArray(value) || !value.length) { | ||
| return PROPAGATE_TO_NONE; | ||
| } | ||
|
|
||
| // Strings must match a binding name exactly, without this, an entry of `DB` would also enable | ||
| // propagation for a binding named `MY_DB`. Regular expressions still give pattern matching. | ||
| return (bindingName: string) => stringMatchesSomePattern(bindingName, value, true); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import { describe, expect, it } from 'vitest'; | ||
| import { createRpcPropagationResolver } from '../../src/utils/rpcPropagation'; | ||
|
|
||
| describe('createRpcPropagationResolver', () => { | ||
| it('propagates to nothing when no options are available', () => { | ||
| const shouldPropagate = createRpcPropagationResolver(undefined); | ||
|
|
||
| expect(shouldPropagate('MY_DO')).toBe(false); | ||
| }); | ||
|
|
||
| it('propagates to nothing when the option is unset', () => { | ||
| const shouldPropagate = createRpcPropagationResolver({ enableRpcTracePropagation: undefined }); | ||
|
|
||
| expect(shouldPropagate('MY_DO')).toBe(false); | ||
| expect(shouldPropagate('EXTERNAL')).toBe(false); | ||
| }); | ||
|
|
||
| it('propagates to nothing when the option is `false`', () => { | ||
| const shouldPropagate = createRpcPropagationResolver({ enableRpcTracePropagation: false }); | ||
|
|
||
| expect(shouldPropagate('MY_DO')).toBe(false); | ||
| }); | ||
|
|
||
| it('propagates to every binding when the option is `true`', () => { | ||
| const shouldPropagate = createRpcPropagationResolver({ enableRpcTracePropagation: true }); | ||
|
|
||
| expect(shouldPropagate('MY_DO')).toBe(true); | ||
| expect(shouldPropagate('EXTERNAL')).toBe(true); | ||
| }); | ||
|
|
||
| it('propagates only to allowlisted binding names', () => { | ||
| const shouldPropagate = createRpcPropagationResolver({ enableRpcTracePropagation: ['MY_DO', 'EXTERNAL'] }); | ||
|
|
||
| expect(shouldPropagate('MY_DO')).toBe(true); | ||
| expect(shouldPropagate('EXTERNAL')).toBe(true); | ||
| expect(shouldPropagate('OTHER')).toBe(false); | ||
| }); | ||
|
|
||
| it('propagates to nothing for an empty allowlist', () => { | ||
| const shouldPropagate = createRpcPropagationResolver({ enableRpcTracePropagation: [] }); | ||
|
|
||
| expect(shouldPropagate('MY_DO')).toBe(false); | ||
| }); | ||
|
|
||
| it('matches binding names exactly, never as a substring', () => { | ||
| const shouldPropagate = createRpcPropagationResolver({ enableRpcTracePropagation: ['DB'] }); | ||
|
|
||
| expect(shouldPropagate('DB')).toBe(true); | ||
| expect(shouldPropagate('MY_DB')).toBe(false); | ||
| expect(shouldPropagate('DB_REPLICA')).toBe(false); | ||
| }); | ||
|
|
||
| it('supports regular expressions for pattern matching', () => { | ||
| const shouldPropagate = createRpcPropagationResolver({ enableRpcTracePropagation: [/^SVC_/] }); | ||
|
|
||
| expect(shouldPropagate('SVC_ORDERS')).toBe(true); | ||
| expect(shouldPropagate('SVC_USERS')).toBe(true); | ||
| expect(shouldPropagate('ORDERS')).toBe(false); | ||
| expect(shouldPropagate('PREFIXED_SVC_ORDERS')).toBe(false); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: The module-level
instrumentedBindingscache is checked before theshouldPropagateRpcTracepredicate, causing cached bindings to bypass RPC propagation rules on subsequent requests with different configurations.Severity: MEDIUM
Suggested Fix
The order of operations should be changed. The
shouldPropagateRpcTracepredicate should be checked before attempting to retrieve a binding from theinstrumentedBindingscache. This ensures that the current invocation's configuration is always respected, even if a cached version of the binding exists from a previous invocation with a different configuration.Prompt for AI Agent
Did we get this right? 👍 / 👎 to inform future reviews.