Skip to content

Commit

Permalink
Merge branch 'develop' into sig/nuxt-server
Browse files Browse the repository at this point in the history
  • Loading branch information
s1gr1d authored Jul 9, 2024
2 parents 1af2673 + a5ea680 commit 165cf5e
Show file tree
Hide file tree
Showing 68 changed files with 510 additions and 327 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,8 @@ jobs:
# See: https://github.com/actions/runner/issues/2205
if:
always() && needs.job_e2e_prepare.result == 'success' &&
(github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository)
(github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) &&
github.actor != 'dependabot[bot]'
needs: [job_get_metadata, job_build, job_e2e_prepare]
runs-on: ubuntu-20.04
timeout-minutes: 10
Expand Down
138 changes: 2 additions & 136 deletions dev-packages/browser-integration-tests/fixtures/loader.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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

Sentry.init({
dsn: 'https://[email protected]/1337',
integrations: [Sentry.moduleMetadataIntegration()],
beforeSend(event) {
const moduleMetadataEntries = [];

if (event.type === undefined) {
try {
event.exception.values.forEach(value => {
value.stacktrace.frames.forEach(frame => {
moduleMetadataEntries.push(frame.module_metadata);
});
});
} catch (e) {
// noop
}
}

event.extra = {
...event.extra,
module_metadata_entries: moduleMetadataEntries,
};

return event;
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
var _sentryModuleMetadataGlobal =
typeof window !== 'undefined'
? window
: typeof global !== 'undefined'
? global
: typeof self !== 'undefined'
? self
: {};

_sentryModuleMetadataGlobal._sentryModuleMetadata = _sentryModuleMetadataGlobal._sentryModuleMetadata || {};

_sentryModuleMetadataGlobal._sentryModuleMetadata[new Error().stack] = Object.assign(
{},
_sentryModuleMetadataGlobal._sentryModuleMetadata[new Error().stack],
{
foo: 'bar',
},
);

setTimeout(() => {
throw new Error('I am a module metadata Error');
}, 0);
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { expect } from '@playwright/test';
import type { Event } from '@sentry/types';

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

sentryTest('should provide module_metadata on stack frames in beforeSend', async ({ getLocalTestPath, page }) => {
// moduleMetadataIntegration is not included in any CDN bundles
if (process.env.PW_BUNDLE?.startsWith('bundle')) {
sentryTest.skip();
}

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

const errorEvent = await getFirstSentryEnvelopeRequest<Event>(page, url);
expect(errorEvent.extra?.['module_metadata_entries']).toEqual([{ foo: 'bar' }]);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import * as Sentry from '@sentry/browser';

Sentry.init({
dsn: 'https://[email protected]/1337',
integrations: [
Sentry.moduleMetadataIntegration(),
Sentry.rewriteFramesIntegration({
iteratee: frame => {
return {
...frame,
filename: 'bloop', // something that should completely mess with module metadata association
};
},
}),
],
beforeSend(event) {
const moduleMetadataEntries = [];

if (event.type === undefined) {
try {
event.exception.values.forEach(value => {
value.stacktrace.frames.forEach(frame => {
moduleMetadataEntries.push(frame.module_metadata);
});
});
} catch (e) {
// noop
}
}

event.extra = {
...event.extra,
module_metadata_entries: moduleMetadataEntries,
};

return event;
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
var _sentryModuleMetadataGlobal =
typeof window !== 'undefined'
? window
: typeof global !== 'undefined'
? global
: typeof self !== 'undefined'
? self
: {};

_sentryModuleMetadataGlobal._sentryModuleMetadata = _sentryModuleMetadataGlobal._sentryModuleMetadata || {};

_sentryModuleMetadataGlobal._sentryModuleMetadata[new Error().stack] = Object.assign(
{},
_sentryModuleMetadataGlobal._sentryModuleMetadata[new Error().stack],
{
foo: 'baz',
},
);

setTimeout(() => {
throw new Error('I am a module metadata Error');
}, 0);
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { expect } from '@playwright/test';
import type { Event } from '@sentry/types';

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

sentryTest(
'should provide module_metadata on stack frames in beforeSend even though an event processor (rewriteFramesIntegration) modified the filename',
async ({ getLocalTestPath, page }) => {
// moduleMetadataIntegration is not included in any CDN bundles
if (process.env.PW_BUNDLE?.startsWith('bundle')) {
sentryTest.skip();
}

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

const errorEvent = await getFirstSentryEnvelopeRequest<Event>(page, url);
expect(errorEvent?.extra?.['module_metadata_entries']).toEqual([{ foo: 'baz' }]);
},
);
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"dependencies": {
"@nestjs/common": "^10.0.0",
"@nestjs/core": "^10.0.0",
"@nestjs/schedule": "^4.1.0",
"@nestjs/platform-express": "^10.0.0",
"@sentry/nestjs": "latest || *",
"@sentry/types": "latest || *",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ export class AppController1 {
async testSpanDecoratorSync() {
return { result: await this.appService.testSpanDecoratorSync() };
}

@Get('kill-test-cron')
async killTestCron() {
this.appService.killTestCron();
}
}

@Controller()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Module } from '@nestjs/common';
import { ScheduleModule } from '@nestjs/schedule';
import { AppController1, AppController2 } from './app.controller';
import { AppService1, AppService2 } from './app.service';

@Module({
imports: [],
imports: [ScheduleModule.forRoot()],
controllers: [AppController1],
providers: [AppService1],
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
import { Cron, SchedulerRegistry } from '@nestjs/schedule';
import * as Sentry from '@sentry/nestjs';
import { SentryTraced } from '@sentry/nestjs';
import { SentryCron, SentryTraced } from '@sentry/nestjs';
import type { MonitorConfig } from '@sentry/types';
import { makeHttpRequest } from './utils';

const monitorConfig: MonitorConfig = {
schedule: {
type: 'crontab',
value: '* * * * *',
},
};

@Injectable()
export class AppService1 {
constructor(private schedulerRegistry: SchedulerRegistry) {}

testSuccess() {
return { version: 'v1' };
}
Expand Down Expand Up @@ -95,6 +106,21 @@ export class AppService1 {
async testSpanDecoratorSync() {
return this.getString();
}

/*
Actual cron schedule differs from schedule defined in config because Sentry
only supports minute granularity, but we don't want to wait (worst case) a
full minute for the tests to finish.
*/
@Cron('*/5 * * * * *', { name: 'test-cron-job' })
@SentryCron('test-cron-slug', monitorConfig)
async testCron() {
console.log('Test cron!');
}

async killTestCron() {
this.schedulerRegistry.deleteCronJob('test-cron-job');
}
}

@Injectable()
Expand Down
Loading

0 comments on commit 165cf5e

Please sign in to comment.