Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import * as Sentry from '@sentry/browser';

window.Sentry = Sentry;

window.fetchCallCount = 0;
window.spanEnded = false;

const originalWindowFetch = window.fetch;
window.fetch = (...args) => {
window.fetchCallCount++;
return originalWindowFetch(...args);
};

Sentry.init({
dsn: 'https://[email protected]/1337',
tracesSampleRate: 1.0,
enabled: false,
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Sentry.startSpan({ name: 'standalone_segment_span', experimental: { standalone: true } }, () => {});

window.spanEnded = true;
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { expect } from '@playwright/test';

import { sentryTest } from '../../../../utils/fixtures';
import { shouldSkipTracingTest } from '../../../../utils/helpers';

sentryTest("doesn't send a standalone span envelope if SDK is disabled", async ({ getLocalTestPath, page }) => {
if (shouldSkipTracingTest()) {
sentryTest.skip();
}

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

// @ts-expect-error this exists in the test init/subject
await page.waitForFunction(() => !!window.spanEnded);
await page.waitForTimeout(2000);

// @ts-expect-error this exists in the test init
const fetchCallCount = await page.evaluate(() => window.fetchCallCount);
// We expect no fetch calls because the SDK is disabled
expect(fetchCallCount).toBe(0);
});
2 changes: 1 addition & 1 deletion packages/core/src/baseclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {

if (this._isEnabled() && this._transport) {
return this._transport.send(envelope).then(null, reason => {
DEBUG_BUILD && logger.error('Error while sending event:', reason);
DEBUG_BUILD && logger.error('Error while sending envelope:', reason);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that sendEnvelope is called for multiple envelope item types (not just events), I opted to slightly change the message here to reflect this

return reason;
});
}
Expand Down
9 changes: 3 additions & 6 deletions packages/core/src/tracing/sentrySpan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,10 +429,7 @@ function sendSpanEnvelope(envelope: SpanEnvelope): void {
return;
}

const transport = client.getTransport();
if (transport) {
transport.send(envelope).then(null, reason => {
DEBUG_BUILD && logger.error('Error while sending span:', reason);
});
}
// sendEnvelope should not throw
// eslint-disable-next-line @typescript-eslint/no-floating-promises
client.sendEnvelope(envelope);
}
Loading