Skip to content

Commit

Permalink
fix stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
mydea committed Jul 11, 2024
1 parent eebe1b5 commit e5b41be
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ sentryTest('error after navigation has navigation traceId', async ({ getLocalTes
sentryTest.skip();
}

await page.route('https://dsn.ingest.sentry.io/**/*', route => {
return route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({ id: 'test-id' }),
});
});

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

// ensure pageload transaction is finished
Expand Down
4 changes: 2 additions & 2 deletions packages/browser/src/tracing/browserTracingIntegration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
return;
}

if (activeSpan) {
if (activeSpan && !spanToJSON(activeSpan).timestamp) {
DEBUG_BUILD && logger.log(`[Tracing] Finishing current root span with op: ${spanToJSON(activeSpan).op}`);
// If there's an open transaction on the scope, we need to finish it before creating an new one.
activeSpan.end();
Expand All @@ -304,7 +304,7 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
return;
}

if (activeSpan) {
if (activeSpan && !spanToJSON(activeSpan).timestamp) {
DEBUG_BUILD && logger.log(`[Tracing] Finishing current root span with op: ${spanToJSON(activeSpan).op}`);
// If there's an open transaction on the scope, we need to finish it before creating an new one.
activeSpan.end();
Expand Down
18 changes: 5 additions & 13 deletions packages/core/src/baseclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -459,27 +459,19 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {

/** @inheritdoc */
public on(hook: string, callback: unknown): () => void {
// Note that the code below, with nullish coalescing assignment,
// may reduce the code, so it may be switched to when Node 14 support
// is dropped (the `??=` operator is supported since Node 15).
// (this._hooks[hook] ??= []).push(callback);
if (!this._hooks[hook]) {
this._hooks[hook] = [];
}
const hooks = (this._hooks[hook] = this._hooks[hook] || []);

// @ts-expect-error We assue the types are correct
this._hooks[hook].push(callback);
hooks.push(callback);

// This function returns a callback execution handler that, when invoked,
// deregisters a callback. This is crucial for managing instances where callbacks
// need to be unregistered to prevent self-referencing in callback closures,
// ensuring proper garbage collection.
return () => {
const hooks = this._hooks[hook];

if (hooks) {
// @ts-expect-error We assue the types are correct
const cbIndex = hooks.indexOf(callback);
// @ts-expect-error We assue the types are correct
const cbIndex = hooks.indexOf(callback);
if (cbIndex > -1) {
hooks.splice(cbIndex, 1);
}
};
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/tracing/idleSpan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,11 @@ export function startIdleSpan(startSpanOptions: StartSpanOptions, options: Parti
}

function onIdleSpanEnded(endTimestamp: number): void {
_cleanupHooks.forEach(cleanup => cleanup());

_finished = true;
activities.clear();

_cleanupHooks.forEach(cleanup => cleanup());

_setSpanForScope(scope, previousActiveSpan);

const spanJSON = spanToJSON(span);
Expand Down

0 comments on commit e5b41be

Please sign in to comment.