Skip to content

Commit

Permalink
feat: Make parameterize function available through browser and node…
Browse files Browse the repository at this point in the history
… API (#10085)

Move `parameterize` function to core, export it to upstream packages via browser and node.
  • Loading branch information
AleshaOleg authored Jan 23, 2024
1 parent 7e3207d commit a27deca
Show file tree
Hide file tree
Showing 14 changed files with 13 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { parameterize } from '@sentry/utils';

const x = 'first';
const y = 'second';

Sentry.captureMessage(parameterize`This is a log statement with ${x} and ${y} params`);
Sentry.captureMessage(Sentry.parameterize`This is a log statement with ${x} and ${y} params`);
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@ import { sentryTest } from '../../../../utils/fixtures';
import { getFirstSentryEnvelopeRequest } from '../../../../utils/helpers';

sentryTest('should capture a parameterized representation of the message', async ({ getLocalTestPath, page }) => {
const bundle = process.env.PW_BUNDLE;

if (bundle && bundle.startsWith('bundle_')) {
sentryTest.skip();
}

const url = await getLocalTestPath({ testDir: __dirname });

const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as Sentry from '@sentry/node';
import { parameterize } from '@sentry/utils';

Sentry.init({
dsn: 'https://[email protected]/1337',
Expand All @@ -9,4 +8,4 @@ Sentry.init({
const x = 'first';
const y = 'second';

Sentry.captureMessage(parameterize`This is a log statement with ${x} and ${y} params`);
Sentry.captureMessage(Sentry.parameterize`This is a log statement with ${x} and ${y} params`);
1 change: 1 addition & 0 deletions packages/astro/src/index.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export {
startSpanManual,
continueTrace,
cron,
parameterize,
} from '@sentry/node';

// We can still leave this for the carrier init and type exports
Expand Down
1 change: 1 addition & 0 deletions packages/browser/src/exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export {
metrics,
functionToStringIntegration,
inboundFiltersIntegration,
parameterize,
} from '@sentry/core';

export { WINDOW } from './helpers';
Expand Down
1 change: 1 addition & 0 deletions packages/bun/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export {
inboundFiltersIntegration,
linkedErrorsIntegration,
requestDataIntegration,
parameterize,
} from '@sentry/core';
export type { SpanStatusType } from '@sentry/core';
export { autoDiscoverNodePerformanceMonitoringIntegrations, cron } from '@sentry/node';
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export { createCheckInEnvelope } from './checkin';
export { hasTracingEnabled } from './utils/hasTracingEnabled';
export { isSentryRequestUrl } from './utils/isSentryRequestUrl';
export { handleCallbackErrors } from './utils/handleCallbackErrors';
export { parameterize } from './utils/parameterize';
export {
spanToTraceHeader,
spanToJSON,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import type { ParameterizedString } from '@sentry/types';
/**
* Tagged template function which returns paramaterized representation of the message
* For example: parameterize`This is a log statement with ${x} and ${y} params`, would return:
* "__sentry_template_string__": "My raw message with interpreted strings like %s",
* "__sentry_template_values__": ["this"]
* "__sentry_template_string__": 'This is a log statement with %s and %s params',
* "__sentry_template_values__": ['first', 'second']
* @param strings An array of string values splitted between expressions
* @param values Expressions extracted from template string
* @returns String with template information in __sentry_template_string__ and __sentry_template_values__ properties
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ParameterizedString } from '@sentry/types';

import { parameterize } from '../src/parameterize';
import { parameterize } from '../../../src/utils/parameterize';

describe('parameterize()', () => {
test('works with empty string', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/node/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export {
startInactiveSpan,
startSpanManual,
continueTrace,
parameterize,
metrics,
functionToStringIntegration,
inboundFiltersIntegration,
Expand Down
1 change: 1 addition & 0 deletions packages/remix/src/index.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export {
Integrations,
Handlers,
cron,
parameterize,
} from '@sentry/node';

// Keeping the `*` exports for backwards compatibility and types
Expand Down
1 change: 1 addition & 0 deletions packages/serverless/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,5 @@ export {
startInactiveSpan,
startSpanManual,
continueTrace,
parameterize,
} from '@sentry/node';
1 change: 1 addition & 0 deletions packages/sveltekit/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export {
startSpanManual,
continueTrace,
cron,
parameterize,
} from '@sentry/node';

// We can still leave this for the carrier init and type exports
Expand Down
1 change: 0 additions & 1 deletion packages/utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export * from './url';
export * from './userIntegrations';
export * from './cache';
export * from './eventbuilder';
export * from './parameterize';
export * from './anr';
export * from './lru';
export * from './buildPolyfills';

0 comments on commit a27deca

Please sign in to comment.