Skip to content

Commit 4641fac

Browse files
committed
some more cleanup
1 parent 743b362 commit 4641fac

File tree

5 files changed

+17
-30
lines changed

5 files changed

+17
-30
lines changed

packages/svelte/src/config.ts

+11-18
Original file line numberDiff line numberDiff line change
@@ -22,30 +22,23 @@ export function withSentryConfig(
2222
const mergedOptions = {
2323
...DEFAULT_SENTRY_OPTIONS,
2424
...sentryOptions,
25+
componentTracking: {
26+
...DEFAULT_SENTRY_OPTIONS.componentTracking,
27+
...(sentryOptions && sentryOptions.componentTracking),
28+
},
2529
};
2630

2731
const originalPreprocessors = getOriginalPreprocessorArray(originalConfig);
2832

29-
// Map is insertion-order-preserving. It's important to add preprocessors
30-
// to this map in the right order we want to see them being executed.
31-
// see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map
32-
const sentryPreprocessors = new Map<string, SentryPreprocessorGroup>();
33-
34-
const shouldTrackComponents = mergedOptions.componentTracking && mergedOptions.componentTracking.trackComponents;
35-
if (shouldTrackComponents) {
36-
const firstPassPreproc: SentryPreprocessorGroup = componentTrackingPreprocessor(mergedOptions.componentTracking);
37-
sentryPreprocessors.set(firstPassPreproc.sentryId || '', firstPassPreproc);
33+
// Bail if users already added the preprocessor
34+
if (originalPreprocessors.find((p: PreprocessorGroup) => !!(p as SentryPreprocessorGroup).sentryId)) {
35+
return originalConfig;
3836
}
3937

40-
// We prioritize user-added preprocessors, so we don't insert sentry processors if they
41-
// have already been added by users.
42-
originalPreprocessors.forEach((p: SentryPreprocessorGroup) => {
43-
if (p.sentryId) {
44-
sentryPreprocessors.delete(p.sentryId);
45-
}
46-
});
47-
48-
const mergedPreprocessors = [...sentryPreprocessors.values(), ...originalPreprocessors];
38+
const mergedPreprocessors = [...originalPreprocessors];
39+
if (mergedOptions.componentTracking.trackComponents) {
40+
mergedPreprocessors.unshift(componentTrackingPreprocessor(mergedOptions.componentTracking));
41+
}
4942

5043
return {
5144
...originalConfig,

packages/svelte/src/constants.ts

-5
This file was deleted.

packages/svelte/src/performance.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import type { Span } from '@sentry/core';
33
import { afterUpdate, beforeUpdate, onMount } from 'svelte';
44

55
import { logger, startInactiveSpan } from '@sentry/core';
6-
import { DEFAULT_COMPONENT_NAME, UI_SVELTE_INIT, UI_SVELTE_UPDATE } from './constants';
76
import type { TrackComponentOptions } from './types';
87

98
const defaultTrackComponentOptions: {
@@ -29,7 +28,7 @@ export function trackComponent(options?: TrackComponentOptions): void {
2928

3029
const customComponentName = mergedOptions.componentName;
3130

32-
const componentName = `<${customComponentName || DEFAULT_COMPONENT_NAME}>`;
31+
const componentName = `<${customComponentName || 'Svelte Component'}>`;
3332

3433
if (mergedOptions.trackInit) {
3534
recordInitSpan(componentName);
@@ -38,7 +37,7 @@ export function trackComponent(options?: TrackComponentOptions): void {
3837
if (mergedOptions.trackUpdates) {
3938
try {
4039
recordUpdateSpans(componentName);
41-
} catch (e) {
40+
} catch {
4241
logger.warn(
4342
"Cannot track component updates. This is likely because you're using Svelte 5 in Runes mode. Set `trackUpdates: false` in `withSentryConfig` or `trackComponent` to disable this warning.",
4443
);
@@ -49,7 +48,7 @@ export function trackComponent(options?: TrackComponentOptions): void {
4948
function recordInitSpan(componentName: string): void {
5049
const initSpan = startInactiveSpan({
5150
onlyIfParent: true,
52-
op: UI_SVELTE_INIT,
51+
op: 'ui.svelte.init',
5352
name: componentName,
5453
attributes: { [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.svelte' },
5554
});
@@ -64,7 +63,7 @@ function recordUpdateSpans(componentName: string): void {
6463
beforeUpdate(() => {
6564
updateSpan = startInactiveSpan({
6665
onlyIfParent: true,
67-
op: UI_SVELTE_UPDATE,
66+
op: 'ui.svelte.update',
6867
name: componentName,
6968
attributes: { [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.svelte' },
7069
});

packages/svelte/test/config.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ describe('withSentryConfig', () => {
6060

6161
const wrappedConfig = withSentryConfig(originalConfig);
6262

63-
expect(wrappedConfig).toEqual({ ...originalConfig, preprocess: [sentryPreproc] });
63+
expect(wrappedConfig).toEqual({ ...originalConfig });
6464
});
6565

6666
it('handles multiple wraps correctly by only adding our preprocessors once', () => {

packages/svelte/test/performance.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe('Sentry.trackComponent()', () => {
3232

3333
init({
3434
dsn: PUBLIC_DSN,
35-
enableTracing: true,
35+
tracesSampleRate: 1.0,
3636
beforeSendTransaction,
3737
});
3838
});

0 commit comments

Comments
 (0)