Skip to content

Commit e06ae30

Browse files
committed
feat: Update isolateTrace implementation to use startNewTrace
Update withMonitor to use startNewTrace() instead of startSpan() when isolateTrace is enabled, following PR feedback to only isolate traces without creating spans.
1 parent 4dfa0af commit e06ae30

File tree

2 files changed

+27
-33
lines changed

2 files changed

+27
-33
lines changed

packages/core/src/exports.ts

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { isThenable } from './utils/is';
1515
import { uuid4 } from './utils/misc';
1616
import type { ExclusiveEventHintOrCaptureContext } from './utils/prepareEvent';
1717
import { parseEventHintOrCaptureContext } from './utils/prepareEvent';
18-
import { startSpan } from './tracing/trace';
18+
import { startNewTrace } from './tracing/trace';
1919
import { timestampInSeconds } from './utils/time';
2020
import { GLOBAL_OBJ } from './utils/worldwide';
2121

@@ -170,38 +170,31 @@ export function withMonitor<T>(
170170
return withIsolationScope(() => {
171171
// If isolateTrace is enabled, start a new trace for this monitor execution
172172
if (upsertMonitorConfig?.isolateTrace) {
173-
return startSpan(
174-
{
175-
name: `monitor.${monitorSlug}`,
176-
op: 'monitor',
177-
forceTransaction: true,
178-
},
179-
() => {
180-
let maybePromiseResult: T;
181-
try {
182-
maybePromiseResult = callback();
183-
} catch (e) {
184-
finishCheckIn('error');
185-
throw e;
186-
}
187-
188-
if (isThenable(maybePromiseResult)) {
189-
return maybePromiseResult.then(
190-
r => {
191-
finishCheckIn('ok');
192-
return r;
193-
},
194-
e => {
195-
finishCheckIn('error');
196-
throw e;
197-
},
198-
) as T;
199-
}
200-
finishCheckIn('ok');
201-
202-
return maybePromiseResult;
203-
},
204-
);
173+
return startNewTrace(() => {
174+
let maybePromiseResult: T;
175+
try {
176+
maybePromiseResult = callback();
177+
} catch (e) {
178+
finishCheckIn('error');
179+
throw e;
180+
}
181+
182+
if (isThenable(maybePromiseResult)) {
183+
return maybePromiseResult.then(
184+
r => {
185+
finishCheckIn('ok');
186+
return r;
187+
},
188+
e => {
189+
finishCheckIn('error');
190+
throw e;
191+
},
192+
) as T;
193+
}
194+
finishCheckIn('ok');
195+
196+
return maybePromiseResult;
197+
});
205198
}
206199

207200
// Default behavior without isolateTrace

packages/core/test/lib/client.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
SyncPromise,
1212
withMonitor,
1313
} from '../../src';
14+
import { startNewTrace } from '../../src/tracing';
1415
import * as integrationModule from '../../src/integration';
1516
import { _INTERNAL_captureLog } from '../../src/logs/internal';
1617
import { _INTERNAL_captureMetric } from '../../src/metrics/internal';

0 commit comments

Comments
 (0)