Skip to content

Commit

Permalink
Merge branch 'develop' into alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
billyvg committed Nov 12, 2024
2 parents 876ad70 + 0aa7f1d commit f5007a4
Show file tree
Hide file tree
Showing 57 changed files with 1,170 additions and 158 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/external-contributors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ jobs:
# This token is scoped to Daniel Griesser
# If we used the default GITHUB_TOKEN, the resulting PR would not trigger CI :(
token: ${{ secrets.REPO_SCOPED_TOKEN }}
commit-message: "ref: Add external contributor to CHANGELOG.md"
title: "ref: Add external contributor to CHANGELOG.md"
commit-message: "chore: Add external contributor to CHANGELOG.md"
title: "chore: Add external contributor to CHANGELOG.md"
branch: 'external-contributor/patch-${{ github.event.pull_request.user.login }}'
base: 'develop'
delete-branch: true
Expand Down
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@

- "You miss 100 percent of the chances you don't take. — Wayne Gretzky" — Michael Scott

## 8.38.0-alpha.0
Work in this release was contributed by @Zen-cronic. Thank you for your contribution!

Work in this release was contributed by @grahamhency, @Zen-cronic, @gilisho and @phuctm97. Thank you for your contributions!

## 8.39.0-dev.0

- debug statement for large events (>1MB)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import * as Sentry from '@sentry/browser';

Sentry.init({
dsn: 'https://[email protected]/1337',
integrations: [],
});

window.Sentry = {
...Sentry,
// Ensure this is _not_ set
moduleMetadataIntegration: undefined,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
window._testLazyLoadIntegration = async function run() {
const integration = await window.Sentry.lazyLoadIntegration('moduleMetadataIntegration');

window.Sentry.getClient()?.addIntegration(integration());

window._integrationLoaded = true;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { expect } from '@playwright/test';
import { SDK_VERSION } from '@sentry/browser';

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

sentryTest('it allows to lazy load the moduleMetadata integration', async ({ getLocalTestUrl, page }) => {
const url = await getLocalTestUrl({ testDir: __dirname });

await page.route(`https://browser.sentry-cdn.com/${SDK_VERSION}/modulemetadata.min.js`, route => {
return route.fulfill({
status: 200,
contentType: 'application/javascript;',
body: "window.Sentry.moduleMetadataIntegration = () => ({ name: 'ModuleMetadata' })",
});
});

await page.goto(url);

const hasIntegration = await page.evaluate('!!window.Sentry.getClient()?.getIntegrationByName("ModuleMetadata")');
expect(hasIntegration).toBe(false);

const scriptTagsBefore = await page.evaluate<number>('document.querySelectorAll("script").length');

await page.evaluate('window._testLazyLoadIntegration()');
await page.waitForFunction('window._integrationLoaded');

const scriptTagsAfter = await page.evaluate<number>('document.querySelectorAll("script").length');

const hasIntegration2 = await page.evaluate('!!window.Sentry.getClient()?.getIntegrationByName("ModuleMetadata")');
expect(hasIntegration2).toBe(true);

expect(scriptTagsAfter).toBe(scriptTagsBefore + 1);
});
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const IMPORTED_INTEGRATION_CDN_BUNDLE_PATHS: Record<string, string> = {
reportingObserverIntegration: 'reportingobserver',
sessionTimingIntegration: 'sessiontiming',
feedbackIntegration: 'feedback',
moduleMetadataIntegration: 'modulemetadata',
};

const BUNDLE_PATHS: Record<string, Record<string, string>> = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ test('should capture error with trpc context', async ({ page }) => {
const trpcError = await errorEventPromise;

expect(trpcError).toBeDefined();
expect(trpcError.contexts.trpc).toBeDefined();
expect(trpcError.contexts.trpc.procedure_type).toEqual('mutation');
expect(trpcError.contexts.trpc.input).toEqual({ name: 'I love dogs' });
expect(trpcError.contexts?.trpc).toBeDefined();
expect(trpcError.contexts?.trpc?.procedure_type).toEqual('mutation');
expect(trpcError.contexts?.trpc?.procedure_path).toBe('post.throwError');
expect(trpcError.contexts?.trpc?.input).toEqual({ name: 'I love dogs' });
});

test('should create transaction with trpc input for error', async ({ page }) => {
Expand All @@ -26,9 +27,5 @@ test('should create transaction with trpc input for error', async ({ page }) =>
await page.click('#error-button');

const trpcTransaction = await trpcTransactionPromise;

expect(trpcTransaction).toBeDefined();
expect(trpcTransaction.contexts.trpc).toBeDefined();
expect(trpcTransaction.contexts.trpc.procedure_type).toEqual('mutation');
expect(trpcTransaction.contexts.trpc.input).toEqual({ name: 'I love dogs' });
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,4 @@ test('should create transaction with trpc input for mutation', async ({ page })
const trpcTransaction = await trpcTransactionPromise;

expect(trpcTransaction).toBeDefined();
expect(trpcTransaction.contexts.trpc).toBeDefined();
expect(trpcTransaction.contexts.trpc.procedure_type).toEqual('mutation');
expect(trpcTransaction.contexts.trpc.input).toEqual({ name: 'I love dogs' });
});
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ test('Should record span for trpc query', async ({ baseURL }) => {
description: `trpc/getSomething`,
}),
);

expect(transaction.contexts?.trpc).toMatchObject({
procedure_type: 'query',
input: 'foobar',
});
});

test('Should record transaction for trpc mutation', async ({ baseURL }) => {
Expand Down Expand Up @@ -70,10 +65,6 @@ test('Should record transaction for trpc mutation', async ({ baseURL }) => {
description: `trpc/createSomething`,
}),
);

expect(transaction.contexts?.trpc).toMatchObject({
procedure_type: 'mutation',
});
});

test('Should record transaction and error for a crashing trpc handler', async ({ baseURL }) => {
Expand All @@ -100,6 +91,9 @@ test('Should record transaction and error for a crashing trpc handler', async ({

await expect(transactionEventPromise).resolves.toBeDefined();
await expect(errorEventPromise).resolves.toBeDefined();

expect((await errorEventPromise).contexts?.trpc?.['procedure_type']).toBe('mutation');
expect((await errorEventPromise).contexts?.trpc?.['procedure_path']).toBe('crashSomething');
});

test('Should record transaction and error for a trpc handler that returns a status code', async ({ baseURL }) => {
Expand Down
1 change: 1 addition & 0 deletions dev-packages/node-integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"graphql": "^16.3.0",
"http-terminator": "^3.2.0",
"ioredis": "^5.4.1",
"knex": "^2.5.1",
"kafkajs": "2.2.4",
"lru-memoizer": "2.3.0",
"mongodb": "^3.7.3",
Expand Down
2 changes: 2 additions & 0 deletions dev-packages/node-integration-tests/suites/anr/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ const assert = require('assert');

const Sentry = require('@sentry/node');

global._sentryDebugIds = { [new Error().stack]: 'aaaaaaaa-aaaa-4aaa-aaaa-aaaaaaaaaa' };

setTimeout(() => {
process.exit();
}, 10000);
Expand Down
2 changes: 2 additions & 0 deletions dev-packages/node-integration-tests/suites/anr/basic.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import * as crypto from 'crypto';

import * as Sentry from '@sentry/node';

global._sentryDebugIds = { [new Error().stack]: 'aaaaaaaa-aaaa-4aaa-aaaa-aaaaaaaaaa' };

setTimeout(() => {
process.exit();
}, 10000);
Expand Down
21 changes: 19 additions & 2 deletions dev-packages/node-integration-tests/suites/anr/test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Event } from '@sentry/types';
import { conditionalTest } from '../../utils';
import { cleanupChildProcesses, createRunner } from '../../utils/runner';

Expand Down Expand Up @@ -64,17 +65,33 @@ const ANR_EVENT_WITH_SCOPE = {
]),
};

const ANR_EVENT_WITH_DEBUG_META: Event = {
...ANR_EVENT_WITH_SCOPE,
debug_meta: {
images: [
{
type: 'sourcemap',
debug_id: 'aaaaaaaa-aaaa-4aaa-aaaa-aaaaaaaaaa',
code_file: expect.stringContaining('basic.'),
},
],
},
};

conditionalTest({ min: 16 })('should report ANR when event loop blocked', () => {
afterAll(() => {
cleanupChildProcesses();
});

test('CJS', done => {
createRunner(__dirname, 'basic.js').withMockSentryServer().expect({ event: ANR_EVENT_WITH_SCOPE }).start(done);
createRunner(__dirname, 'basic.js').withMockSentryServer().expect({ event: ANR_EVENT_WITH_DEBUG_META }).start(done);
});

test('ESM', done => {
createRunner(__dirname, 'basic.mjs').withMockSentryServer().expect({ event: ANR_EVENT_WITH_SCOPE }).start(done);
createRunner(__dirname, 'basic.mjs')
.withMockSentryServer()
.expect({ event: ANR_EVENT_WITH_DEBUG_META })
.start(done);
});

test('blocked indefinitely', done => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: '3.9'

services:
db_postgres:
image: postgres:13
restart: always
container_name: integration-tests-knex-postgres
ports:
- '5445:5432'
environment:
POSTGRES_USER: test
POSTGRES_PASSWORD: test
POSTGRES_DB: tests

db_mysql2:
image: mysql:8
restart: always
container_name: integration-tests-knex-mysql2
ports:
- '3307:3306'
environment:
MYSQL_ROOT_PASSWORD: docker
MYSQL_DATABASE: tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
const { loggingTransport } = require('@sentry-internal/node-integration-tests');
const Sentry = require('@sentry/node');

Sentry.init({
dsn: 'https://[email protected]/1337',
release: '1.0',
tracesSampleRate: 1.0,
transport: loggingTransport,
integrations: [Sentry.knexIntegration()],
});

// Stop the process from exiting before the transaction is sent
setInterval(() => {}, 1000);

const knex = require('knex').default;

const mysql2Client = knex({
client: 'mysql2',
connection: {
host: 'localhost',
port: 3307,
user: 'root',
password: 'docker',
database: 'tests',
},
});

async function run() {
await Sentry.startSpan(
{
name: 'Test Transaction',
op: 'transaction',
},
async () => {
try {
await mysql2Client.schema.createTable('User', table => {
table.increments('id').notNullable().primary({ constraintName: 'User_pkey' });
table.timestamp('createdAt', { precision: 3 }).notNullable().defaultTo(mysql2Client.fn.now(3));
table.text('email').notNullable();
table.text('name').notNullable();
});

await mysql2Client('User').insert({ name: 'jane', email: '[email protected]' });
await mysql2Client('User').select('*');
} finally {
await mysql2Client.destroy();
}
},
);
}

// eslint-disable-next-line @typescript-eslint/no-floating-promises
run();
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
const { loggingTransport } = require('@sentry-internal/node-integration-tests');
const Sentry = require('@sentry/node');

Sentry.init({
dsn: 'https://[email protected]/1337',
release: '1.0',
tracesSampleRate: 1.0,
transport: loggingTransport,
integrations: [Sentry.knexIntegration()],
});

// Stop the process from exiting before the transaction is sent
setInterval(() => {}, 1000);

const knex = require('knex').default;

const pgClient = knex({
client: 'pg',
connection: {
host: 'localhost',
port: 5445,
user: 'test',
password: 'test',
database: 'tests',
},
});

async function run() {
await Sentry.startSpan(
{
name: 'Test Transaction',
op: 'transaction',
},
async () => {
try {
await pgClient.schema.createTable('User', table => {
table.increments('id').notNullable().primary({ constraintName: 'User_pkey' });
table.timestamp('createdAt', { precision: 3 }).notNullable().defaultTo(pgClient.fn.now(3));
table.text('email').notNullable();
table.text('name').notNullable();
});

await pgClient('User').insert({ name: 'bob', email: '[email protected]' });
await pgClient('User').select('*');
} finally {
await pgClient.destroy();
}
},
);
}

// eslint-disable-next-line @typescript-eslint/no-floating-promises
run();
Loading

0 comments on commit f5007a4

Please sign in to comment.