-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(utils): Add parameterize
function
#9145
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
Merged
Lms24
merged 32 commits into
getsentry:develop
from
AleshaOleg:feature/added-parametrize-function
Jan 5, 2024
Merged
Changes from 27 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
db66295
Added parametrize function
AleshaOleg e15d5f1
Populate logentry parameter if it's exist for eventFromMessage functions
AleshaOleg 7b27a1e
Merge branch 'develop' of github.com:getsentry/sentry-javascript into…
AleshaOleg e4c4d4c
Renamed parametrize to parameterize and moved ParameterizedString typ…
AleshaOleg 8fa0552
Added integration tests
AleshaOleg d83411a
Fixing tests and improvements
AleshaOleg 70e6864
isParameterized -> isParameterizedString in docs
AleshaOleg cbd0805
Fixed lint errors
AleshaOleg 1020b14
Minor optimization
AleshaOleg 99c4fbb
Merge branch 'develop' of github.com:getsentry/sentry-javascript into…
AleshaOleg 3cbe665
Minor improvements, reverted prisma update
AleshaOleg de6e723
Fixed typo
AleshaOleg 28758b6
Fixed typo
AleshaOleg 17a4bbd
Merge branch 'develop' of github.com:getsentry/sentry-javascript into…
AleshaOleg 2c3393f
[email protected] -> prisma@^3.12.0
AleshaOleg f6347a3
Merge branch 'develop' of github.com:getsentry/sentry-javascript into…
AleshaOleg cefa81c
prisma@^3.12.0 -> [email protected]
AleshaOleg e80f23a
[email protected] -> prisma@^3.12.0
AleshaOleg 3b67901
Merge branch 'develop' of github.com:getsentry/sentry-javascript into…
AleshaOleg 2789d04
[email protected] -> prisma@^3.12.0
AleshaOleg 3e3b441
Merge branch 'develop' of github.com:AleshaOleg/sentry-javascript int…
AleshaOleg 0d67997
Fixed Biome errors
AleshaOleg dcd1549
Merge branch 'develop' of https://github.com/getsentry/sentry-javascr…
AleshaOleg ca8a58a
Merge branch 'develop' of https://github.com/getsentry/sentry-javascr…
AleshaOleg 8c8bf10
Skipping test for some bundles
AleshaOleg a631c55
Prevent running test for tracing builds
AleshaOleg aa3c9d1
Merge branch 'develop' of https://github.com/getsentry/sentry-javascr…
AleshaOleg de11d01
Skipping all test for bundle builds
AleshaOleg 5aeedf7
Merge branch 'develop' of https://github.com/getsentry/sentry-javascr…
AleshaOleg f68be1f
Test migration to dev-packages folder
AleshaOleg 5681add
Merge branch 'develop' of https://github.com/getsentry/sentry-javascr…
AleshaOleg 4b0c53c
Merge branch 'develop' into feature/added-parametrize-function
AleshaOleg 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
6 changes: 6 additions & 0 deletions
6
...owser-integration-tests/suites/public-api/captureMessage/parameterized_message/subject.js
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,6 @@ | ||
import { parameterize } from '@sentry/utils'; | ||
|
||
const x = 'first'; | ||
const y = 'second'; | ||
|
||
Sentry.captureMessage(parameterize`This is a log statement with ${x} and ${y} params`); |
21 changes: 21 additions & 0 deletions
21
.../browser-integration-tests/suites/public-api/captureMessage/parameterized_message/test.ts
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,21 @@ | ||
import { expect } from '@playwright/test'; | ||
import type { Event } from '@sentry/types'; | ||
|
||
import { sentryTest } from '../../../../utils/fixtures'; | ||
import { getFirstSentryEnvelopeRequest, shouldSkipTracingTest } from '../../../../utils/helpers'; | ||
import { shouldSkipReplayTest } from '../../../../utils/replayHelpers'; | ||
|
||
sentryTest('should capture a parameterized representation of the message', async ({ getLocalTestPath, page }) => { | ||
if (shouldSkipReplayTest() || !shouldSkipTracingTest()) { | ||
sentryTest.skip(); | ||
} | ||
|
||
const url = await getLocalTestPath({ testDir: __dirname }); | ||
|
||
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url); | ||
|
||
expect(eventData.logentry).toStrictEqual({ | ||
message: 'This is a log statement with %s and %s params', | ||
params: ['first', 'second'], | ||
}); | ||
}); |
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
12 changes: 12 additions & 0 deletions
12
...node-integration-tests/suites/public-api/captureMessage/parameterized_message/scenario.ts
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,12 @@ | ||
import * as Sentry from '@sentry/node'; | ||
import { parameterize } from '@sentry/utils'; | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
release: '1.0', | ||
}); | ||
|
||
const x = 'first'; | ||
const y = 'second'; | ||
|
||
Sentry.captureMessage(parameterize`This is a log statement with ${x} and ${y} params`); |
13 changes: 13 additions & 0 deletions
13
...ges/node-integration-tests/suites/public-api/captureMessage/parameterized_message/test.ts
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,13 @@ | ||
import { TestEnv, assertSentryEvent } from '../../../../utils'; | ||
|
||
test('should capture a parameterized representation of the message', async () => { | ||
const env = await TestEnv.init(__dirname); | ||
const event = await env.getEnvelopeRequest(); | ||
|
||
assertSentryEvent(event[2], { | ||
logentry: { | ||
message: 'This is a log statement with %s and %s params', | ||
params: ['first', 'second'], | ||
}, | ||
}); | ||
}); |
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,4 @@ | ||
export type ParameterizedString = string & { | ||
__sentry_template_string__?: string; | ||
__sentry_template_values__?: string[]; | ||
}; |
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
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.
I think this is not gonna be enough. We need to skip all
bundle_
variants for now. These two functions won't do that.basically like in this test:
sentry-javascript/packages/browser-integration-tests/suites/replay/replayShim/test.ts
Lines 8 to 13 in 94bc349
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.
Thanks for the hint about skipping the test for all bundle builds.
I made changes, should work now.
Can you also explain how you are testing such functions for public API for CDN bundles? Because importing functions directly to tests will not work, and I'm wondering how I can test them. Just an example would be enough, I didn't find anything similar in
browser-integration-tests
. Will do it as a separate PR as you mentionedThere 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.
So as soon as we export
parameterize
from @sentry/browser, our CDN bundles will also include it as a top level function to call on theSentry
object. Meaning, CDN bundle users can callwe can adjust the integration tests to do that and stop importing it from @sentry/utils.
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.
that's generally how we test public API in the browser integration tests, across NPM package (
esm
,cjs
) and CDN bundle variants.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.
For a simple example, take a look at this test: https://github.com/getsentry/sentry-javascript/blob/23ef22b115c8868861896cc9003bd4bb6afb0690/dev-packages/browser-integration-tests/suites/public-api/setTag/with_primitives/subject.js
calling
Sentry.parameterize
should work just like callingSentry.setTag
once we export it from the browser package.Uh oh!
There was an error while loading. Please reload this page.
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.
Thanks, just tried also throws timeouts locally, but works with esm, cjs builds. Will do separate PR for that, and will mention you to run tests there, let's see if it will work on cloud setup. A lot of other tests also failing for me locally because of timeout for example for bundle_tracing_replay_es6_min, so I'm not quite sure if it works or not.
For now please merge it, just pulled latest changes from
develop
and I'll do separate PR for running tests for all of the builds and make this function available from browser API. Thanks!