From c508a9aaa9560d1fdf72ad161ebce8cd28bc54d2 Mon Sep 17 00:00:00 2001 From: Tim Fish Date: Tue, 2 Aug 2022 14:44:00 +0100 Subject: [PATCH 01/11] Add additional context for Node --- packages/node/src/integrations/context.ts | 332 ++++++++++++++++++++++ packages/node/src/integrations/index.ts | 1 + packages/node/src/sdk.ts | 11 +- packages/types/src/context.ts | 72 ++++- packages/types/src/index.ts | 2 +- 5 files changed, 415 insertions(+), 3 deletions(-) create mode 100644 packages/node/src/integrations/context.ts diff --git a/packages/node/src/integrations/context.ts b/packages/node/src/integrations/context.ts new file mode 100644 index 000000000000..54b11464f206 --- /dev/null +++ b/packages/node/src/integrations/context.ts @@ -0,0 +1,332 @@ +/* eslint-disable max-lines */ +import { + AppContext, + Contexts, + CultureContext, + DeviceContext, + Event, + EventProcessor, + Integration, + OsContext, +} from '@sentry/types'; +import { execFile } from 'child_process'; +import { readdir, readFile } from 'fs'; +import * as os from 'os'; +import { join } from 'path'; +import { promisify } from 'util'; + +// TODO: Required until we drop support for Node v8 +export const readFileAsync = promisify(readFile); +export const readDirAsync = promisify(readdir); + +interface DeviceContextOptions { + cpu?: boolean; + memory?: boolean; +} + +interface ContextOptions { + app?: boolean; + os?: boolean; + device?: DeviceContextOptions | boolean; + culture?: boolean; +} + +/** Add node modules / packages to the event */ +export class Context implements Integration { + /** + * @inheritDoc + */ + public static id: string = 'Context'; + + /** + * @inheritDoc + */ + public name: string = Context.id; + + /** + * Caches contexts so they're only evaluated once + */ + private _cachedContexts: Contexts | undefined; + + public constructor(private readonly _options: ContextOptions = { app: true, os: true, device: true, culture: true }) { + // + } + + /** + * @inheritDoc + */ + public setupOnce(addGlobalEventProcessor: (callback: EventProcessor) => void): void { + addGlobalEventProcessor(event => this.addContext(event)); + } + + /** Processes an event and adds context lines */ + public async addContext(event: Event): Promise { + if (this._cachedContexts === undefined) { + this._cachedContexts = {}; + + if (this._options.os) { + this._cachedContexts.os = await getOsContext(); + } + + if (this._options.app) { + this._cachedContexts.app = getAppContext(); + } + + if (this._options.device) { + this._cachedContexts.device = getDeviceContext(this._options.device); + } + + if (this._options.culture) { + const culture = getCultureContext(); + + if (culture) { + this._cachedContexts.culture = culture; + } + } + } + + event.contexts = { ...event.contexts, ...this._cachedContexts }; + + return event; + } +} + +/** + * Returns the operating system context. + * + * Based on the current platform, this uses a different strategy to provide the + * most accurate OS information. Since this might involve spawning subprocesses + * or accessing the file system, this should only be executed lazily and cached. + * + * - On macOS (Darwin), this will execute the `sw_vers` utility. The context + * has a `name`, `version`, `build` and `kernel_version` set. + * - On Linux, this will try to load a distribution release from `/etc` and set + * the `name`, `version` and `kernel_version` fields. + * - On all other platforms, only a `name` and `version` will be returned. Note + * that `version` might actually be the kernel version. + */ +async function getOsContext(): Promise { + const platformId = os.platform(); + switch (platformId) { + case 'darwin': + return getDarwinInfo(); + case 'linux': + return getLinuxInfo(); + default: + return { + name: PLATFORM_NAMES[platformId] || platformId, + version: os.release(), + }; + } +} + +function getCultureContext(): CultureContext | undefined { + try { + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any + if ((process.versions as unknown as any).icu !== 'string') { + // Node was built without ICU support + return; + } + + // Check that node was built with full Intl support. Its possible it was built without support for non-English + // locales which will make resolvedOptions inaccurate + // + // https://nodejs.org/api/intl.html#detecting-internationalization-support + const january = new Date(9e8); + const spanish = new Intl.DateTimeFormat('es', { month: 'long' }); + if (spanish.format(january) === 'enero') { + const options = Intl.DateTimeFormat().resolvedOptions(); + + return { + locale: options.locale, + timezone: options.timeZone, + }; + } + } catch (err) { + // + } + + return; +} + +function getAppContext(): AppContext { + const memory_used = process.memoryUsage().rss; + const app_start_time = new Date(Date.now() - process.uptime() * 1000).toISOString(); + + return { app_start_time, memory_used }; +} + +function getDeviceContext(deviceOpt: DeviceContextOptions | true): DeviceContext { + const device: DeviceContext = {}; + + device.boot_time = new Date(Date.now() - os.uptime() * 1000).toISOString(); + device.arch = os.arch(); + + if (deviceOpt === true || deviceOpt.memory) { + device.memory_size = os.totalmem(); + device.free_memory = os.freemem(); + } + + if (deviceOpt === true || deviceOpt.cpu) { + const cpuInfo: os.CpuInfo[] | undefined = os.cpus(); + if (cpuInfo && cpuInfo.length) { + const firstCpu = cpuInfo[0]; + + device.processor_count = cpuInfo.length; + device.cpu_description = firstCpu.model; + device.processor_frequency = firstCpu.speed; + } + } + + return device; +} + +/** Mapping of Node's platform names to actual OS names. */ +const PLATFORM_NAMES: { [platform: string]: string } = { + aix: 'IBM AIX', + freebsd: 'FreeBSD', + openbsd: 'OpenBSD', + sunos: 'SunOS', + win32: 'Windows', +}; + +/** Linux version file to check for a distribution. */ +interface DistroFile { + /** The file name, located in `/etc`. */ + name: string; + /** Potential distributions to check. */ + distros: string[]; +} + +/** Mapping of linux release files located in /etc to distributions. */ +const LINUX_DISTROS: DistroFile[] = [ + { name: 'fedora-release', distros: ['Fedora'] }, + { name: 'redhat-release', distros: ['Red Hat Linux', 'Centos'] }, + { name: 'redhat_version', distros: ['Red Hat Linux'] }, + { name: 'SuSE-release', distros: ['SUSE Linux'] }, + { name: 'lsb-release', distros: ['Ubuntu Linux', 'Arch Linux'] }, + { name: 'debian_version', distros: ['Debian'] }, + { name: 'debian_release', distros: ['Debian'] }, + { name: 'arch-release', distros: ['Arch Linux'] }, + { name: 'gentoo-release', distros: ['Gentoo Linux'] }, + { name: 'novell-release', distros: ['SUSE Linux'] }, + { name: 'alpine-release', distros: ['Alpine Linux'] }, +]; + +/** Functions to extract the OS version from Linux release files. */ +const LINUX_VERSIONS: { + [identifier: string]: (content: string) => string | undefined; +} = { + alpine: content => content, + arch: content => matchFirst(/distrib_release=(.*)/, content), + centos: content => matchFirst(/release ([^ ]+)/, content), + debian: content => content, + fedora: content => matchFirst(/release (..)/, content), + mint: content => matchFirst(/distrib_release=(.*)/, content), + red: content => matchFirst(/release ([^ ]+)/, content), + suse: content => matchFirst(/VERSION = (.*)\n/, content), + ubuntu: content => matchFirst(/distrib_release=(.*)/, content), +}; + +/** + * Executes a regular expression with one capture group. + * + * @param regex A regular expression to execute. + * @param text Content to execute the RegEx on. + * @returns The captured string if matched; otherwise undefined. + */ +function matchFirst(regex: RegExp, text: string): string | undefined { + const match = regex.exec(text); + return match ? match[1] : undefined; +} + +/** Loads the macOS operating system context. */ +async function getDarwinInfo(): Promise { + // Default values that will be used in case no operating system information + // can be loaded. The default version is computed via heuristics from the + // kernel version, but the build ID is missing. + const darwinInfo: OsContext = { + kernel_version: os.release(), + name: 'Mac OS X', + version: `10.${Number(os.release().split('.')[0]) - 4}`, + }; + + try { + // We try to load the actual macOS version by executing the `sw_vers` tool. + // This tool should be available on every standard macOS installation. In + // case this fails, we stick with the values computed above. + + const output = await new Promise((resolve, reject) => { + execFile('/usr/bin/sw_vers', (error: Error | null, stdout: string) => { + if (error) { + reject(error); + return; + } + resolve(stdout); + }); + }); + + darwinInfo.name = matchFirst(/^ProductName:\s+(.*)$/m, output); + darwinInfo.version = matchFirst(/^ProductVersion:\s+(.*)$/m, output); + darwinInfo.build = matchFirst(/^BuildVersion:\s+(.*)$/m, output); + } catch (e) { + // ignore + } + + return darwinInfo; +} + +/** Returns a distribution identifier to look up version callbacks. */ +function getLinuxDistroId(name: string): string { + return name.split(' ')[0].toLowerCase(); +} + +/** Loads the Linux operating system context. */ +async function getLinuxInfo(): Promise { + // By default, we cannot assume anything about the distribution or Linux + // version. `os.release()` returns the kernel version and we assume a generic + // "Linux" name, which will be replaced down below. + const linuxInfo: OsContext = { + kernel_version: os.release(), + name: 'Linux', + }; + + try { + // We start guessing the distribution by listing files in the /etc + // directory. This is were most Linux distributions (except Knoppix) store + // release files with certain distribution-dependent meta data. We search + // for exactly one known file defined in `LINUX_DISTROS` and exit if none + // are found. In case there are more than one file, we just stick with the + // first one. + const etcFiles = await readDirAsync('/etc'); + const distroFile = LINUX_DISTROS.find(file => etcFiles.includes(file.name)); + if (!distroFile) { + return linuxInfo; + } + + // Once that file is known, load its contents. To make searching in those + // files easier, we lowercase the file contents. Since these files are + // usually quite small, this should not allocate too much memory and we only + // hold on to it for a very short amount of time. + const distroPath = join('/etc', distroFile.name); + const contents = ((await readFileAsync(distroPath, { encoding: 'utf-8' })) as string).toLowerCase(); + + // Some Linux distributions store their release information in the same file + // (e.g. RHEL and Centos). In those cases, we scan the file for an + // identifier, that basically consists of the first word of the linux + // distribution name (e.g. "red" for Red Hat). In case there is no match, we + // just assume the first distribution in our list. + const { distros } = distroFile; + linuxInfo.name = distros.find(d => contents.indexOf(getLinuxDistroId(d)) >= 0) || distros[0]; + + // Based on the found distribution, we can now compute the actual version + // number. This is different for every distribution, so several strategies + // are computed in `LINUX_VERSIONS`. + const id = getLinuxDistroId(linuxInfo.name); + linuxInfo.version = LINUX_VERSIONS[id](contents); + } catch (e) { + // ignore + } + + return linuxInfo; +} diff --git a/packages/node/src/integrations/index.ts b/packages/node/src/integrations/index.ts index 8017ba458e49..05a25d7cbad3 100644 --- a/packages/node/src/integrations/index.ts +++ b/packages/node/src/integrations/index.ts @@ -5,3 +5,4 @@ export { OnUnhandledRejection } from './onunhandledrejection'; export { LinkedErrors } from './linkederrors'; export { Modules } from './modules'; export { ContextLines } from './contextlines'; +export { Context } from './context'; diff --git a/packages/node/src/sdk.ts b/packages/node/src/sdk.ts index fea6f4473ba8..db1e7e883ced 100644 --- a/packages/node/src/sdk.ts +++ b/packages/node/src/sdk.ts @@ -18,7 +18,15 @@ import * as domain from 'domain'; import * as url from 'url'; import { NodeClient } from './client'; -import { Console, ContextLines, Http, LinkedErrors, OnUncaughtException, OnUnhandledRejection } from './integrations'; +import { + Console, + Context, + ContextLines, + Http, + LinkedErrors, + OnUncaughtException, + OnUnhandledRejection, +} from './integrations'; import { getModule } from './module'; import { makeNodeTransport } from './transports'; import { NodeClientOptions, NodeOptions } from './types'; @@ -36,6 +44,7 @@ export const defaultIntegrations = [ new OnUnhandledRejection(), // Misc new LinkedErrors(), + new Context(), ]; /** diff --git a/packages/types/src/context.ts b/packages/types/src/context.ts index 6fbbeb00b6e6..61e7dd03fab9 100644 --- a/packages/types/src/context.ts +++ b/packages/types/src/context.ts @@ -1,2 +1,72 @@ export type Context = Record; -export type Contexts = Record; + +export interface Contexts extends Record { + app?: AppContext; + device?: DeviceContext; + os?: OsContext; + culture?: CultureContext; +} + +export interface AppContext extends Record { + app_name?: string; + app_start_time?: string; + app_version?: string; + app_identifier?: string; + build_type?: string; + memory_used?: number; +} + +export interface DeviceContext extends Record { + name?: string; + family?: string; + model?: string; + model_id?: string; + arch?: string; + battery_level?: number; + orientation?: 'portrait' | 'landscape'; + manufacturer?: string; + brand?: string; + screen_resolution?: string; + screen_height_pixels?: number; + screen_width_pixels?: number; + screen_density?: number; + screen_dpi?: number; + online?: boolean; + charging?: boolean; + low_memory?: boolean; + simulator?: boolean; + memory_size?: number; + free_memory?: number; + usable_memory?: number; + storage_size?: number; + free_storage?: number; + external_storage_size?: number; + external_free_storage?: number; + boot_time?: string; + processor_count?: number; + cpu_description?: string; + processor_frequency?: number; + device_type?: string; + battery_status?: string; + device_unique_identifier?: string; + supports_vibration?: boolean; + supports_accelerometer?: boolean; + supports_gyroscope?: boolean; + supports_audio?: boolean; + supports_location_service?: boolean; +} + +export interface OsContext extends Record { + name?: string; + version?: string; + build?: string; + kernel_version?: string; +} + +export interface CultureContext extends Record { + calendar?: string; + display_name?: string; + locale?: string; + is_24_hour_format?: boolean; + timezone?: string; +} diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts index 32b2d077a74c..e02c454a1b48 100644 --- a/packages/types/src/index.ts +++ b/packages/types/src/index.ts @@ -3,7 +3,7 @@ export type { AllowedBaggageKeys, Baggage, BaggageObj } from './baggage'; export type { Breadcrumb, BreadcrumbHint } from './breadcrumb'; export type { Client } from './client'; export type { ClientReport, Outcome, EventDropReason } from './clientreport'; -export type { Context, Contexts } from './context'; +export type { Context, Contexts, DeviceContext, OsContext, AppContext, CultureContext } from './context'; export type { DataCategory } from './datacategory'; export type { DsnComponents, DsnLike, DsnProtocol } from './dsn'; export type { DebugImage, DebugImageType, DebugMeta } from './debugMeta'; From 184180cde2a0dfd4d3258d6e5842719bc1d85fe6 Mon Sep 17 00:00:00 2001 From: Tim Fish Date: Tue, 2 Aug 2022 16:10:01 +0100 Subject: [PATCH 02/11] Correctly handle reentrancy --- packages/node/src/integrations/context.ts | 49 +++++++++++++---------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/packages/node/src/integrations/context.ts b/packages/node/src/integrations/context.ts index 54b11464f206..852f59c04aa9 100644 --- a/packages/node/src/integrations/context.ts +++ b/packages/node/src/integrations/context.ts @@ -46,7 +46,7 @@ export class Context implements Integration { /** * Caches contexts so they're only evaluated once */ - private _cachedContexts: Contexts | undefined; + private _cachedContextsPromise: Promise | undefined; public constructor(private readonly _options: ContextOptions = { app: true, os: true, device: true, culture: true }) { // @@ -59,35 +59,42 @@ export class Context implements Integration { addGlobalEventProcessor(event => this.addContext(event)); } - /** Processes an event and adds context lines */ + /** Processes an event and adds context */ public async addContext(event: Event): Promise { - if (this._cachedContexts === undefined) { - this._cachedContexts = {}; + if (this._cachedContextsPromise === undefined) { + this._cachedContextsPromise = this._getContexts(); + } - if (this._options.os) { - this._cachedContexts.os = await getOsContext(); - } + event.contexts = { ...event.contexts, ...(await this._cachedContextsPromise) }; - if (this._options.app) { - this._cachedContexts.app = getAppContext(); - } + return event; + } - if (this._options.device) { - this._cachedContexts.device = getDeviceContext(this._options.device); - } + /** Creates a promise that contains Contexts when resolved */ + private async _getContexts(): Promise { + const contexts: Contexts = {}; - if (this._options.culture) { - const culture = getCultureContext(); + if (this._options.os) { + contexts.os = await getOsContext(); + } - if (culture) { - this._cachedContexts.culture = culture; - } - } + if (this._options.app) { + contexts.app = getAppContext(); + } + + if (this._options.device) { + contexts.device = getDeviceContext(this._options.device); } - event.contexts = { ...event.contexts, ...this._cachedContexts }; + if (this._options.culture) { + const culture = getCultureContext(); - return event; + if (culture) { + contexts.culture = culture; + } + } + + return contexts; } } From 4895f2a04d3874707e8800a016b005ccae8413d4 Mon Sep 17 00:00:00 2001 From: Tim Fish Date: Tue, 2 Aug 2022 16:14:24 +0100 Subject: [PATCH 03/11] We should only cache OS --- packages/node/src/integrations/context.ts | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/packages/node/src/integrations/context.ts b/packages/node/src/integrations/context.ts index 852f59c04aa9..fe961598ccbf 100644 --- a/packages/node/src/integrations/context.ts +++ b/packages/node/src/integrations/context.ts @@ -44,9 +44,9 @@ export class Context implements Integration { public name: string = Context.id; /** - * Caches contexts so they're only evaluated once + * Caches OS context so it's only evaluated once */ - private _cachedContextsPromise: Promise | undefined; + private _cachedOsContext: Promise | undefined; public constructor(private readonly _options: ContextOptions = { app: true, os: true, device: true, culture: true }) { // @@ -61,21 +61,14 @@ export class Context implements Integration { /** Processes an event and adds context */ public async addContext(event: Event): Promise { - if (this._cachedContextsPromise === undefined) { - this._cachedContextsPromise = this._getContexts(); + if (this._cachedOsContext === undefined) { + this._cachedOsContext = getOsContext(); } - event.contexts = { ...event.contexts, ...(await this._cachedContextsPromise) }; - - return event; - } - - /** Creates a promise that contains Contexts when resolved */ - private async _getContexts(): Promise { const contexts: Contexts = {}; if (this._options.os) { - contexts.os = await getOsContext(); + contexts.os = await this._cachedOsContext; } if (this._options.app) { @@ -94,7 +87,9 @@ export class Context implements Integration { } } - return contexts; + event.contexts = { ...event.contexts, ...contexts }; + + return event; } } From 583422c75849fd243942e1cb57d5a9e3922bbbb7 Mon Sep 17 00:00:00 2001 From: Tim Fish Date: Tue, 2 Aug 2022 17:51:41 +0100 Subject: [PATCH 04/11] Cache entire context and only update dynamic properties --- packages/node/src/integrations/context.ts | 37 ++++++++++++++++++----- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/packages/node/src/integrations/context.ts b/packages/node/src/integrations/context.ts index fe961598ccbf..39d0b710ffd9 100644 --- a/packages/node/src/integrations/context.ts +++ b/packages/node/src/integrations/context.ts @@ -46,7 +46,7 @@ export class Context implements Integration { /** * Caches OS context so it's only evaluated once */ - private _cachedOsContext: Promise | undefined; + private _cachedContext: Promise | undefined; public constructor(private readonly _options: ContextOptions = { app: true, os: true, device: true, culture: true }) { // @@ -61,14 +61,39 @@ export class Context implements Integration { /** Processes an event and adds context */ public async addContext(event: Event): Promise { - if (this._cachedOsContext === undefined) { - this._cachedOsContext = getOsContext(); + if (this._cachedContext === undefined) { + this._cachedContext = this._getContexts(); } + event.contexts = { ...event.contexts, ...this._updateContext(await this._cachedContext) }; + + return event; + } + + /** + * Updates the context with dynamic values that can change + */ + private _updateContext(contexts: Contexts): Contexts { + // Only update properties if they exist + if (contexts?.app?.memory_used) { + contexts.app.memory_used = process.memoryUsage().rss; + } + + if (contexts?.device?.free_memory) { + contexts.device.free_memory = os.freemem(); + } + + return contexts; + } + + /** + * Gets the contexts for the current environment + */ + private async _getContexts(): Promise { const contexts: Contexts = {}; if (this._options.os) { - contexts.os = await this._cachedOsContext; + contexts.os = await getOsContext(); } if (this._options.app) { @@ -87,9 +112,7 @@ export class Context implements Integration { } } - event.contexts = { ...event.contexts, ...contexts }; - - return event; + return contexts; } } From f785a94315a9575fdfd80d3b76b0d0162aa15dae Mon Sep 17 00:00:00 2001 From: Tim Fish Date: Tue, 2 Aug 2022 23:25:43 +0100 Subject: [PATCH 05/11] Attempt to fix test failures --- .../public-api/captureException/catched-error/test.ts | 7 +++---- .../public-api/captureMessage/simple_message/test.ts | 7 +++---- .../public-api/setContext/multiple-contexts/test.ts | 9 ++++----- .../public-api/setExtra/non-serializable-extra/test.ts | 7 +++---- .../suites/public-api/setExtras/multiple-extras/test.ts | 7 +++---- .../suites/tracing/auto-instrument/mongodb/test.ts | 4 +++- packages/node-integration-tests/utils/index.ts | 8 ++++++++ 7 files changed, 27 insertions(+), 22 deletions(-) diff --git a/packages/node-integration-tests/suites/public-api/captureException/catched-error/test.ts b/packages/node-integration-tests/suites/public-api/captureException/catched-error/test.ts index 2070199f77d9..6c96af0b2e9f 100644 --- a/packages/node-integration-tests/suites/public-api/captureException/catched-error/test.ts +++ b/packages/node-integration-tests/suites/public-api/captureException/catched-error/test.ts @@ -1,11 +1,10 @@ -import { assertSentryEvent, getMultipleEnvelopeRequest, runServer } from '../../../../utils'; +import { assertSentryEvent, getMultipleEnvelopeRequest, runServer, filterEnvelopes } from '../../../../utils'; test('should work inside catch block', async () => { const url = await runServer(__dirname); - const envelopes = await getMultipleEnvelopeRequest(url, 2); - const errorEnvelope = envelopes[1]; + const events = filterEnvelopes(await getMultipleEnvelopeRequest(url, 2)); - assertSentryEvent(errorEnvelope[2], { + assertSentryEvent(events[0], { exception: { values: [ { diff --git a/packages/node-integration-tests/suites/public-api/captureMessage/simple_message/test.ts b/packages/node-integration-tests/suites/public-api/captureMessage/simple_message/test.ts index 2ecc0e86720d..00f712766890 100644 --- a/packages/node-integration-tests/suites/public-api/captureMessage/simple_message/test.ts +++ b/packages/node-integration-tests/suites/public-api/captureMessage/simple_message/test.ts @@ -1,11 +1,10 @@ -import { assertSentryEvent, getMultipleEnvelopeRequest, runServer } from '../../../../utils'; +import { assertSentryEvent, getMultipleEnvelopeRequest, runServer, filterEnvelopes } from '../../../../utils'; test('should capture a simple message string', async () => { const url = await runServer(__dirname); - const envelopes = await getMultipleEnvelopeRequest(url, 2); - const errorEnvelope = envelopes[1]; + const events = filterEnvelopes(await getMultipleEnvelopeRequest(url, 2)); - assertSentryEvent(errorEnvelope[2], { + assertSentryEvent(events[0], { message: 'Message', level: 'info', }); diff --git a/packages/node-integration-tests/suites/public-api/setContext/multiple-contexts/test.ts b/packages/node-integration-tests/suites/public-api/setContext/multiple-contexts/test.ts index f1c8981fad9a..2254c8db84f5 100644 --- a/packages/node-integration-tests/suites/public-api/setContext/multiple-contexts/test.ts +++ b/packages/node-integration-tests/suites/public-api/setContext/multiple-contexts/test.ts @@ -1,13 +1,12 @@ import { Event } from '@sentry/node'; -import { assertSentryEvent, getMultipleEnvelopeRequest, runServer } from '../../../../utils'; +import { assertSentryEvent, getMultipleEnvelopeRequest, runServer, filterEnvelopes } from '../../../../utils'; test('should record multiple contexts', async () => { const url = await runServer(__dirname); - const envelopes = await getMultipleEnvelopeRequest(url, 2); - const errorEnvelope = envelopes[1]; + const events = filterEnvelopes(await getMultipleEnvelopeRequest(url, 2)); - assertSentryEvent(errorEnvelope[2], { + assertSentryEvent(events[0], { message: 'multiple_contexts', contexts: { context_1: { @@ -18,5 +17,5 @@ test('should record multiple contexts', async () => { }, }); - expect((errorEnvelope[2] as Event).contexts?.context_3).not.toBeDefined(); + expect((events[0] as Event).contexts?.context_3).not.toBeDefined(); }); diff --git a/packages/node-integration-tests/suites/public-api/setExtra/non-serializable-extra/test.ts b/packages/node-integration-tests/suites/public-api/setExtra/non-serializable-extra/test.ts index 3cd2ca078eeb..d4453b7b1174 100644 --- a/packages/node-integration-tests/suites/public-api/setExtra/non-serializable-extra/test.ts +++ b/packages/node-integration-tests/suites/public-api/setExtra/non-serializable-extra/test.ts @@ -1,11 +1,10 @@ -import { assertSentryEvent, getMultipleEnvelopeRequest, runServer } from '../../../../utils'; +import { assertSentryEvent, getMultipleEnvelopeRequest, runServer, filterEnvelopes } from '../../../../utils'; test('should normalize non-serializable extra', async () => { const url = await runServer(__dirname); - const envelopes = await getMultipleEnvelopeRequest(url, 2); - const errorEnvelope = envelopes[1]; + const events = filterEnvelopes(await getMultipleEnvelopeRequest(url, 2)); - assertSentryEvent(errorEnvelope[2], { + assertSentryEvent(events[0], { message: 'non_serializable', extra: {}, }); diff --git a/packages/node-integration-tests/suites/public-api/setExtras/multiple-extras/test.ts b/packages/node-integration-tests/suites/public-api/setExtras/multiple-extras/test.ts index d23c8e815a06..3757a8c9ecde 100644 --- a/packages/node-integration-tests/suites/public-api/setExtras/multiple-extras/test.ts +++ b/packages/node-integration-tests/suites/public-api/setExtras/multiple-extras/test.ts @@ -1,11 +1,10 @@ -import { assertSentryEvent, getMultipleEnvelopeRequest, runServer } from '../../../../utils'; +import { assertSentryEvent, getMultipleEnvelopeRequest, runServer, filterEnvelopes } from '../../../../utils'; test('should record an extras object', async () => { const url = await runServer(__dirname); - const envelopes = await getMultipleEnvelopeRequest(url, 2); - const errorEnvelope = envelopes[1]; + const events = filterEnvelopes(await getMultipleEnvelopeRequest(url, 2)); - assertSentryEvent(errorEnvelope[2], { + assertSentryEvent(events[0], { message: 'multiple_extras', extra: { extra_1: [1, ['foo'], 'bar'], diff --git a/packages/node-integration-tests/suites/tracing/auto-instrument/mongodb/test.ts b/packages/node-integration-tests/suites/tracing/auto-instrument/mongodb/test.ts index 76cadd1518dd..3e0adc493658 100644 --- a/packages/node-integration-tests/suites/tracing/auto-instrument/mongodb/test.ts +++ b/packages/node-integration-tests/suites/tracing/auto-instrument/mongodb/test.ts @@ -14,7 +14,9 @@ conditionalTest({ min: 12 })('MongoDB Test', () => { }, 10000); afterAll(async () => { - await mongoServer.stop(); + if (mongoServer) { + await mongoServer.stop(); + } }); test('should auto-instrument `mongodb` package.', async () => { diff --git a/packages/node-integration-tests/utils/index.ts b/packages/node-integration-tests/utils/index.ts index 872c9d72521d..5b335799b36a 100644 --- a/packages/node-integration-tests/utils/index.ts +++ b/packages/node-integration-tests/utils/index.ts @@ -96,6 +96,14 @@ export const getMultipleEnvelopeRequest = async (url: string, count: number): Pr }); }; +/** + * Filters and returns only a specific type of envelope payload. + */ +export const filterEnvelopes = (envelopes: Record[][], type = 'event'): Record[] => { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return envelopes.filter(e => (e?.[1] as any)?.type === type).map(e => e[2] as any); +}; + /** * Sends a get request to given URL, with optional headers * From 55a9a9d4e43f98efdb174f8496137729b1229afe Mon Sep 17 00:00:00 2001 From: Tim Fish Date: Wed, 3 Aug 2022 13:18:47 +0100 Subject: [PATCH 06/11] More test fixes --- .../captureException/catched-error/test.ts | 4 ++-- .../public-api/captureException/empty-obj/test.ts | 7 +++---- .../captureException/simple-error/test.ts | 7 +++---- .../captureMessage/simple_message/test.ts | 4 ++-- .../setContext/multiple-contexts/test.ts | 4 ++-- .../setExtra/non-serializable-extra/test.ts | 4 ++-- .../public-api/setExtras/multiple-extras/test.ts | 4 ++-- .../public-api/setTags/with-primitives/test.ts | 7 +++---- .../suites/public-api/setUser/unset_user/test.ts | 14 +++++++------- packages/node-integration-tests/utils/index.ts | 5 ++++- 10 files changed, 30 insertions(+), 30 deletions(-) diff --git a/packages/node-integration-tests/suites/public-api/captureException/catched-error/test.ts b/packages/node-integration-tests/suites/public-api/captureException/catched-error/test.ts index 6c96af0b2e9f..98f1a74255a5 100644 --- a/packages/node-integration-tests/suites/public-api/captureException/catched-error/test.ts +++ b/packages/node-integration-tests/suites/public-api/captureException/catched-error/test.ts @@ -1,8 +1,8 @@ -import { assertSentryEvent, getMultipleEnvelopeRequest, runServer, filterEnvelopes } from '../../../../utils'; +import { assertSentryEvent, getMultipleEnvelopeRequest, runServer, filterEnvelopeItems } from '../../../../utils'; test('should work inside catch block', async () => { const url = await runServer(__dirname); - const events = filterEnvelopes(await getMultipleEnvelopeRequest(url, 2)); + const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(url, 2)); assertSentryEvent(events[0], { exception: { diff --git a/packages/node-integration-tests/suites/public-api/captureException/empty-obj/test.ts b/packages/node-integration-tests/suites/public-api/captureException/empty-obj/test.ts index 0df21996f08c..018d2d275eb2 100644 --- a/packages/node-integration-tests/suites/public-api/captureException/empty-obj/test.ts +++ b/packages/node-integration-tests/suites/public-api/captureException/empty-obj/test.ts @@ -1,11 +1,10 @@ -import { assertSentryEvent, getMultipleEnvelopeRequest, runServer } from '../../../../utils'; +import { assertSentryEvent, getMultipleEnvelopeRequest, runServer, filterEnvelopeItems } from '../../../../utils'; test('should capture an empty object', async () => { const url = await runServer(__dirname); - const envelopes = await getMultipleEnvelopeRequest(url, 2); - const errorEnvelope = envelopes[1]; + const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(url, 2)); - assertSentryEvent(errorEnvelope[2], { + assertSentryEvent(events[0], { exception: { values: [ { diff --git a/packages/node-integration-tests/suites/public-api/captureException/simple-error/test.ts b/packages/node-integration-tests/suites/public-api/captureException/simple-error/test.ts index 66ca0410377a..135e1d21c768 100644 --- a/packages/node-integration-tests/suites/public-api/captureException/simple-error/test.ts +++ b/packages/node-integration-tests/suites/public-api/captureException/simple-error/test.ts @@ -1,11 +1,10 @@ -import { assertSentryEvent, getMultipleEnvelopeRequest, runServer } from '../../../../utils'; +import { assertSentryEvent, getMultipleEnvelopeRequest, runServer, filterEnvelopeItems } from '../../../../utils'; test('should capture a simple error with message', async () => { const url = await runServer(__dirname); - const envelopes = await getMultipleEnvelopeRequest(url, 2); - const errorEnvelope = envelopes[1]; + const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(url, 2)); - assertSentryEvent(errorEnvelope[2], { + assertSentryEvent(events[0], { exception: { values: [ { diff --git a/packages/node-integration-tests/suites/public-api/captureMessage/simple_message/test.ts b/packages/node-integration-tests/suites/public-api/captureMessage/simple_message/test.ts index 00f712766890..9f451865e1ff 100644 --- a/packages/node-integration-tests/suites/public-api/captureMessage/simple_message/test.ts +++ b/packages/node-integration-tests/suites/public-api/captureMessage/simple_message/test.ts @@ -1,8 +1,8 @@ -import { assertSentryEvent, getMultipleEnvelopeRequest, runServer, filterEnvelopes } from '../../../../utils'; +import { assertSentryEvent, getMultipleEnvelopeRequest, runServer, filterEnvelopeItems } from '../../../../utils'; test('should capture a simple message string', async () => { const url = await runServer(__dirname); - const events = filterEnvelopes(await getMultipleEnvelopeRequest(url, 2)); + const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(url, 2)); assertSentryEvent(events[0], { message: 'Message', diff --git a/packages/node-integration-tests/suites/public-api/setContext/multiple-contexts/test.ts b/packages/node-integration-tests/suites/public-api/setContext/multiple-contexts/test.ts index 2254c8db84f5..c86f24ab68fc 100644 --- a/packages/node-integration-tests/suites/public-api/setContext/multiple-contexts/test.ts +++ b/packages/node-integration-tests/suites/public-api/setContext/multiple-contexts/test.ts @@ -1,10 +1,10 @@ import { Event } from '@sentry/node'; -import { assertSentryEvent, getMultipleEnvelopeRequest, runServer, filterEnvelopes } from '../../../../utils'; +import { assertSentryEvent, getMultipleEnvelopeRequest, runServer, filterEnvelopeItems } from '../../../../utils'; test('should record multiple contexts', async () => { const url = await runServer(__dirname); - const events = filterEnvelopes(await getMultipleEnvelopeRequest(url, 2)); + const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(url, 2)); assertSentryEvent(events[0], { message: 'multiple_contexts', diff --git a/packages/node-integration-tests/suites/public-api/setExtra/non-serializable-extra/test.ts b/packages/node-integration-tests/suites/public-api/setExtra/non-serializable-extra/test.ts index d4453b7b1174..13dcd09d138a 100644 --- a/packages/node-integration-tests/suites/public-api/setExtra/non-serializable-extra/test.ts +++ b/packages/node-integration-tests/suites/public-api/setExtra/non-serializable-extra/test.ts @@ -1,8 +1,8 @@ -import { assertSentryEvent, getMultipleEnvelopeRequest, runServer, filterEnvelopes } from '../../../../utils'; +import { assertSentryEvent, getMultipleEnvelopeRequest, runServer, filterEnvelopeItems } from '../../../../utils'; test('should normalize non-serializable extra', async () => { const url = await runServer(__dirname); - const events = filterEnvelopes(await getMultipleEnvelopeRequest(url, 2)); + const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(url, 2)); assertSentryEvent(events[0], { message: 'non_serializable', diff --git a/packages/node-integration-tests/suites/public-api/setExtras/multiple-extras/test.ts b/packages/node-integration-tests/suites/public-api/setExtras/multiple-extras/test.ts index 3757a8c9ecde..0e07f38b8c5a 100644 --- a/packages/node-integration-tests/suites/public-api/setExtras/multiple-extras/test.ts +++ b/packages/node-integration-tests/suites/public-api/setExtras/multiple-extras/test.ts @@ -1,8 +1,8 @@ -import { assertSentryEvent, getMultipleEnvelopeRequest, runServer, filterEnvelopes } from '../../../../utils'; +import { assertSentryEvent, getMultipleEnvelopeRequest, runServer, filterEnvelopeItems } from '../../../../utils'; test('should record an extras object', async () => { const url = await runServer(__dirname); - const events = filterEnvelopes(await getMultipleEnvelopeRequest(url, 2)); + const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(url, 2)); assertSentryEvent(events[0], { message: 'multiple_extras', diff --git a/packages/node-integration-tests/suites/public-api/setTags/with-primitives/test.ts b/packages/node-integration-tests/suites/public-api/setTags/with-primitives/test.ts index 88d78b70c655..c8cda554f259 100644 --- a/packages/node-integration-tests/suites/public-api/setTags/with-primitives/test.ts +++ b/packages/node-integration-tests/suites/public-api/setTags/with-primitives/test.ts @@ -1,11 +1,10 @@ -import { assertSentryEvent, getMultipleEnvelopeRequest, runServer } from '../../../../utils'; +import { assertSentryEvent, getMultipleEnvelopeRequest, runServer, filterEnvelopeItems } from '../../../../utils'; test('should set primitive tags', async () => { const url = await runServer(__dirname); - const envelopes = await getMultipleEnvelopeRequest(url, 2); - const envelope = envelopes[1]; + const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(url, 2)); - assertSentryEvent(envelope[2], { + assertSentryEvent(events[0], { message: 'primitive_tags', tags: { tag_1: 'foo', diff --git a/packages/node-integration-tests/suites/public-api/setUser/unset_user/test.ts b/packages/node-integration-tests/suites/public-api/setUser/unset_user/test.ts index 736ed1fdf38c..76917bb68182 100644 --- a/packages/node-integration-tests/suites/public-api/setUser/unset_user/test.ts +++ b/packages/node-integration-tests/suites/public-api/setUser/unset_user/test.ts @@ -1,18 +1,18 @@ import { Event } from '@sentry/node'; -import { assertSentryEvent, getMultipleEnvelopeRequest, runServer } from '../../../../utils'; +import { assertSentryEvent, getMultipleEnvelopeRequest, runServer, filterEnvelopeItems } from '../../../../utils'; test('should unset user', async () => { const url = await runServer(__dirname); - const envelopes = await getMultipleEnvelopeRequest(url, 6); + const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(url, 6)); - assertSentryEvent(envelopes[1][2], { + assertSentryEvent(events[0], { message: 'no_user', }); - expect((envelopes[0][2] as Event).user).not.toBeDefined(); + expect((events[0] as Event).user).not.toBeDefined(); - assertSentryEvent(envelopes[3][2], { + assertSentryEvent(events[1], { message: 'user', user: { id: 'foo', @@ -21,9 +21,9 @@ test('should unset user', async () => { }, }); - assertSentryEvent(envelopes[5][2], { + assertSentryEvent(events[2], { message: 'unset_user', }); - expect((envelopes[2][2] as Event).user).not.toBeDefined(); + expect((events[2] as Event).user).not.toBeDefined(); }); diff --git a/packages/node-integration-tests/utils/index.ts b/packages/node-integration-tests/utils/index.ts index 5b335799b36a..8dff4a59fc64 100644 --- a/packages/node-integration-tests/utils/index.ts +++ b/packages/node-integration-tests/utils/index.ts @@ -99,7 +99,10 @@ export const getMultipleEnvelopeRequest = async (url: string, count: number): Pr /** * Filters and returns only a specific type of envelope payload. */ -export const filterEnvelopes = (envelopes: Record[][], type = 'event'): Record[] => { +export const filterEnvelopeItems = ( + envelopes: Record[][], + type = 'event', +): Record[] => { // eslint-disable-next-line @typescript-eslint/no-explicit-any return envelopes.filter(e => (e?.[1] as any)?.type === type).map(e => e[2] as any); }; From f23492745e414be13a29c9d2913e53248d64aa63 Mon Sep 17 00:00:00 2001 From: Tim Fish Date: Wed, 3 Aug 2022 14:26:24 +0100 Subject: [PATCH 07/11] More test fixes --- .../addBreadcrumb/multiple_breadcrumbs/test.ts | 6 +++--- .../public-api/captureMessage/with_level/test.ts | 16 ++++++++-------- .../setContext/non-serializable-context/test.ts | 9 ++++----- .../public-api/setExtra/multiple-extras/test.ts | 7 +++---- .../public-api/setExtra/simple-extra/test.ts | 7 +++---- .../public-api/setTag/with-primitives/test.ts | 7 +++---- .../public-api/withScope/nested-scopes/test.ts | 16 ++++++++-------- 7 files changed, 32 insertions(+), 36 deletions(-) diff --git a/packages/node-integration-tests/suites/public-api/addBreadcrumb/multiple_breadcrumbs/test.ts b/packages/node-integration-tests/suites/public-api/addBreadcrumb/multiple_breadcrumbs/test.ts index 38ef745cb28e..9e4c4ca2b9e8 100644 --- a/packages/node-integration-tests/suites/public-api/addBreadcrumb/multiple_breadcrumbs/test.ts +++ b/packages/node-integration-tests/suites/public-api/addBreadcrumb/multiple_breadcrumbs/test.ts @@ -1,10 +1,10 @@ -import { assertSentryEvent, getMultipleEnvelopeRequest, runServer } from '../../../../utils'; +import { assertSentryEvent, getMultipleEnvelopeRequest, runServer, filterEnvelopeItems } from '../../../../utils'; test('should add multiple breadcrumbs', async () => { const url = await runServer(__dirname); - const envelopes = await getMultipleEnvelopeRequest(url, 2); + const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(url, 2)); - assertSentryEvent(envelopes[1][2], { + assertSentryEvent(events[0], { message: 'test_multi_breadcrumbs', breadcrumbs: [ { diff --git a/packages/node-integration-tests/suites/public-api/captureMessage/with_level/test.ts b/packages/node-integration-tests/suites/public-api/captureMessage/with_level/test.ts index 18bd395b148d..195b5bc39b8e 100644 --- a/packages/node-integration-tests/suites/public-api/captureMessage/with_level/test.ts +++ b/packages/node-integration-tests/suites/public-api/captureMessage/with_level/test.ts @@ -1,35 +1,35 @@ -import { assertSentryEvent, getMultipleEnvelopeRequest, runServer } from '../../../../utils'; +import { assertSentryEvent, getMultipleEnvelopeRequest, runServer, filterEnvelopeItems } from '../../../../utils'; test('should capture with different severity levels', async () => { const url = await runServer(__dirname); - const envelopes = await getMultipleEnvelopeRequest(url, 12); + const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(url, 12)); - assertSentryEvent(envelopes[1][2], { + assertSentryEvent(events[0], { message: 'debug_message', level: 'debug', }); - assertSentryEvent(envelopes[3][2], { + assertSentryEvent(events[1], { message: 'info_message', level: 'info', }); - assertSentryEvent(envelopes[5][2], { + assertSentryEvent(events[2], { message: 'warning_message', level: 'warning', }); - assertSentryEvent(envelopes[7][2], { + assertSentryEvent(events[3], { message: 'error_message', level: 'error', }); - assertSentryEvent(envelopes[9][2], { + assertSentryEvent(events[4], { message: 'fatal_message', level: 'fatal', }); - assertSentryEvent(envelopes[11][2], { + assertSentryEvent(events[5], { message: 'log_message', level: 'log', }); diff --git a/packages/node-integration-tests/suites/public-api/setContext/non-serializable-context/test.ts b/packages/node-integration-tests/suites/public-api/setContext/non-serializable-context/test.ts index 26b5fe8c7025..536976e4a051 100644 --- a/packages/node-integration-tests/suites/public-api/setContext/non-serializable-context/test.ts +++ b/packages/node-integration-tests/suites/public-api/setContext/non-serializable-context/test.ts @@ -1,16 +1,15 @@ import { Event } from '@sentry/node'; -import { assertSentryEvent, getMultipleEnvelopeRequest, runServer } from '../../../../utils'; +import { assertSentryEvent, getMultipleEnvelopeRequest, runServer, filterEnvelopeItems } from '../../../../utils'; test('should normalize non-serializable context', async () => { const url = await runServer(__dirname); - const envelopes = await getMultipleEnvelopeRequest(url, 2); - const errorEnvelope = envelopes[1]; + const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(url, 2)); - assertSentryEvent(errorEnvelope[2], { + assertSentryEvent(events[0], { message: 'non_serializable', contexts: {}, }); - expect((errorEnvelope[2] as Event).contexts?.context_3).not.toBeDefined(); + expect((events[0] as Event).contexts?.context_3).not.toBeDefined(); }); diff --git a/packages/node-integration-tests/suites/public-api/setExtra/multiple-extras/test.ts b/packages/node-integration-tests/suites/public-api/setExtra/multiple-extras/test.ts index 428ebd7f45c4..7035f3e16ee3 100644 --- a/packages/node-integration-tests/suites/public-api/setExtra/multiple-extras/test.ts +++ b/packages/node-integration-tests/suites/public-api/setExtra/multiple-extras/test.ts @@ -1,11 +1,10 @@ -import { assertSentryEvent, getMultipleEnvelopeRequest, runServer } from '../../../../utils'; +import { assertSentryEvent, getMultipleEnvelopeRequest, runServer, filterEnvelopeItems } from '../../../../utils'; test('should record multiple extras of different types', async () => { const url = await runServer(__dirname); - const envelopes = await getMultipleEnvelopeRequest(url, 2); - const errorEnvelope = envelopes[1]; + const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(url, 2)); - assertSentryEvent(errorEnvelope[2], { + assertSentryEvent(events[0], { message: 'multiple_extras', extra: { extra_1: { foo: 'bar', baz: { qux: 'quux' } }, diff --git a/packages/node-integration-tests/suites/public-api/setExtra/simple-extra/test.ts b/packages/node-integration-tests/suites/public-api/setExtra/simple-extra/test.ts index 33bfe641bfa3..f15e1f4bb804 100644 --- a/packages/node-integration-tests/suites/public-api/setExtra/simple-extra/test.ts +++ b/packages/node-integration-tests/suites/public-api/setExtra/simple-extra/test.ts @@ -1,11 +1,10 @@ -import { assertSentryEvent, getMultipleEnvelopeRequest, runServer } from '../../../../utils'; +import { assertSentryEvent, getMultipleEnvelopeRequest, runServer, filterEnvelopeItems } from '../../../../utils'; test('should set a simple extra', async () => { const url = await runServer(__dirname); - const envelopes = await getMultipleEnvelopeRequest(url, 2); - const errorEnvelope = envelopes[1]; + const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(url, 2)); - assertSentryEvent(errorEnvelope[2], { + assertSentryEvent(events[0], { message: 'simple_extra', extra: { foo: { diff --git a/packages/node-integration-tests/suites/public-api/setTag/with-primitives/test.ts b/packages/node-integration-tests/suites/public-api/setTag/with-primitives/test.ts index 88d78b70c655..c8cda554f259 100644 --- a/packages/node-integration-tests/suites/public-api/setTag/with-primitives/test.ts +++ b/packages/node-integration-tests/suites/public-api/setTag/with-primitives/test.ts @@ -1,11 +1,10 @@ -import { assertSentryEvent, getMultipleEnvelopeRequest, runServer } from '../../../../utils'; +import { assertSentryEvent, getMultipleEnvelopeRequest, runServer, filterEnvelopeItems } from '../../../../utils'; test('should set primitive tags', async () => { const url = await runServer(__dirname); - const envelopes = await getMultipleEnvelopeRequest(url, 2); - const envelope = envelopes[1]; + const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(url, 2)); - assertSentryEvent(envelope[2], { + assertSentryEvent(events[0], { message: 'primitive_tags', tags: { tag_1: 'foo', diff --git a/packages/node-integration-tests/suites/public-api/withScope/nested-scopes/test.ts b/packages/node-integration-tests/suites/public-api/withScope/nested-scopes/test.ts index b6399b8dd78e..9d898d2103f6 100644 --- a/packages/node-integration-tests/suites/public-api/withScope/nested-scopes/test.ts +++ b/packages/node-integration-tests/suites/public-api/withScope/nested-scopes/test.ts @@ -1,19 +1,19 @@ import { Event } from '@sentry/node'; -import { assertSentryEvent, getMultipleEnvelopeRequest, runServer } from '../../../../utils'; +import { assertSentryEvent, getMultipleEnvelopeRequest, runServer, filterEnvelopeItems } from '../../../../utils'; test('should allow nested scoping', async () => { const url = await runServer(__dirname); - const envelopes = await getMultipleEnvelopeRequest(url, 10); + const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(url, 10)); - assertSentryEvent(envelopes[1][2], { + assertSentryEvent(events[0], { message: 'root_before', user: { id: 'qux', }, }); - assertSentryEvent(envelopes[3][2], { + assertSentryEvent(events[1], { message: 'outer_before', user: { id: 'qux', @@ -23,7 +23,7 @@ test('should allow nested scoping', async () => { }, }); - assertSentryEvent(envelopes[5][2], { + assertSentryEvent(events[2], { message: 'inner', tags: { foo: false, @@ -31,9 +31,9 @@ test('should allow nested scoping', async () => { }, }); - expect((envelopes[4][2] as Event).user).toBeUndefined(); + expect((events[2] as Event).user).toBeUndefined(); - assertSentryEvent(envelopes[7][2], { + assertSentryEvent(events[3], { message: 'outer_after', user: { id: 'baz', @@ -43,7 +43,7 @@ test('should allow nested scoping', async () => { }, }); - assertSentryEvent(envelopes[9][2], { + assertSentryEvent(events[4], { message: 'root_after', user: { id: 'qux', From a1163697aaebd9fa0c1860bed539d08ae9880076 Mon Sep 17 00:00:00 2001 From: Tim Fish Date: Tue, 16 Aug 2022 15:57:00 +0100 Subject: [PATCH 08/11] Comment type --- packages/node/src/integrations/context.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/node/src/integrations/context.ts b/packages/node/src/integrations/context.ts index 39d0b710ffd9..8e1103ff8a63 100644 --- a/packages/node/src/integrations/context.ts +++ b/packages/node/src/integrations/context.ts @@ -44,7 +44,7 @@ export class Context implements Integration { public name: string = Context.id; /** - * Caches OS context so it's only evaluated once + * Caches context so it's only evaluated once */ private _cachedContext: Promise | undefined; From 566c08aeb48eabcd504230fb7395c529e6b0f440 Mon Sep 17 00:00:00 2001 From: Tim Fish Date: Wed, 17 Aug 2022 08:02:46 +0100 Subject: [PATCH 09/11] Lint --- packages/node-integration-tests/package.json | 3 +++ .../public-api/addBreadcrumb/multiple_breadcrumbs/test.ts | 4 ++-- .../suites/public-api/captureException/catched-error/test.ts | 4 ++-- .../suites/public-api/captureException/empty-obj/test.ts | 4 ++-- .../suites/public-api/captureException/simple-error/test.ts | 4 ++-- .../suites/public-api/captureMessage/simple_message/test.ts | 4 ++-- .../suites/public-api/captureMessage/with_level/test.ts | 4 ++-- .../suites/public-api/setContext/multiple-contexts/test.ts | 4 ++-- .../public-api/setContext/non-serializable-context/test.ts | 4 ++-- .../suites/public-api/setExtra/multiple-extras/test.ts | 4 ++-- .../suites/public-api/setExtra/non-serializable-extra/test.ts | 4 ++-- .../suites/public-api/setExtra/simple-extra/test.ts | 4 ++-- .../suites/public-api/setExtras/multiple-extras/test.ts | 4 ++-- .../suites/public-api/setTag/with-primitives/test.ts | 4 ++-- .../suites/public-api/setTags/with-primitives/test.ts | 4 ++-- .../suites/public-api/setUser/unset_user/test.ts | 4 ++-- .../suites/public-api/withScope/nested-scopes/test.ts | 4 ++-- 17 files changed, 35 insertions(+), 32 deletions(-) diff --git a/packages/node-integration-tests/package.json b/packages/node-integration-tests/package.json index ce592de5619e..1684b82a5354 100644 --- a/packages/node-integration-tests/package.json +++ b/packages/node-integration-tests/package.json @@ -12,6 +12,9 @@ "lint": "run-s lint:prettier lint:eslint", "lint:eslint": "eslint . --cache --cache-location '../../eslintcache/' --format stylish", "lint:prettier": "prettier --check \"{suites,utils}/**/*.ts\"", + "fix": "run-s fix:eslint fix:prettier", + "fix:eslint": "eslint . --format stylish --fix", + "fix:prettier": "prettier --write \"{suites,utils}/**/*.ts\"", "type-check": "tsc", "pretest": "run-s --silent prisma:init", "test": "jest --runInBand --forceExit", diff --git a/packages/node-integration-tests/suites/public-api/addBreadcrumb/multiple_breadcrumbs/test.ts b/packages/node-integration-tests/suites/public-api/addBreadcrumb/multiple_breadcrumbs/test.ts index 3be8279253d8..61b851be55f7 100644 --- a/packages/node-integration-tests/suites/public-api/addBreadcrumb/multiple_breadcrumbs/test.ts +++ b/packages/node-integration-tests/suites/public-api/addBreadcrumb/multiple_breadcrumbs/test.ts @@ -1,8 +1,8 @@ -import { assertSentryEvent, getMultipleEnvelopeRequest, runServer, filterEnvelopeItems } from '../../../../utils'; +import { assertSentryEvent, filterEnvelopeItems, getMultipleEnvelopeRequest, runServer } from '../../../../utils'; test('should add multiple breadcrumbs', async () => { const config = await runServer(__dirname); - const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(config,{ count: 2 })); + const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(config, { count: 2 })); assertSentryEvent(events[0], { message: 'test_multi_breadcrumbs', diff --git a/packages/node-integration-tests/suites/public-api/captureException/catched-error/test.ts b/packages/node-integration-tests/suites/public-api/captureException/catched-error/test.ts index efbbfb643a04..19dd6b7108d1 100644 --- a/packages/node-integration-tests/suites/public-api/captureException/catched-error/test.ts +++ b/packages/node-integration-tests/suites/public-api/captureException/catched-error/test.ts @@ -1,8 +1,8 @@ -import { assertSentryEvent, getMultipleEnvelopeRequest, runServer, filterEnvelopeItems } from '../../../../utils'; +import { assertSentryEvent, filterEnvelopeItems, getMultipleEnvelopeRequest, runServer } from '../../../../utils'; test('should work inside catch block', async () => { const config = await runServer(__dirname); - const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(config, {count: 2})); + const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(config, { count: 2 })); assertSentryEvent(events[0], { exception: { diff --git a/packages/node-integration-tests/suites/public-api/captureException/empty-obj/test.ts b/packages/node-integration-tests/suites/public-api/captureException/empty-obj/test.ts index e669d4c81743..8550c1e43fa3 100644 --- a/packages/node-integration-tests/suites/public-api/captureException/empty-obj/test.ts +++ b/packages/node-integration-tests/suites/public-api/captureException/empty-obj/test.ts @@ -1,8 +1,8 @@ -import { assertSentryEvent, getMultipleEnvelopeRequest, runServer, filterEnvelopeItems } from '../../../../utils'; +import { assertSentryEvent, filterEnvelopeItems, getMultipleEnvelopeRequest, runServer } from '../../../../utils'; test('should capture an empty object', async () => { const config = await runServer(__dirname); - const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(config,{count: 2})); + const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(config, { count: 2 })); assertSentryEvent(events[0], { exception: { diff --git a/packages/node-integration-tests/suites/public-api/captureException/simple-error/test.ts b/packages/node-integration-tests/suites/public-api/captureException/simple-error/test.ts index 72403d4e7ace..26e336bab3ab 100644 --- a/packages/node-integration-tests/suites/public-api/captureException/simple-error/test.ts +++ b/packages/node-integration-tests/suites/public-api/captureException/simple-error/test.ts @@ -1,8 +1,8 @@ -import { assertSentryEvent, getMultipleEnvelopeRequest, runServer, filterEnvelopeItems } from '../../../../utils'; +import { assertSentryEvent, filterEnvelopeItems, getMultipleEnvelopeRequest, runServer } from '../../../../utils'; test('should capture a simple error with message', async () => { const config = await runServer(__dirname); - const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(config, {count:2})); + const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(config, { count: 2 })); assertSentryEvent(events[0], { exception: { diff --git a/packages/node-integration-tests/suites/public-api/captureMessage/simple_message/test.ts b/packages/node-integration-tests/suites/public-api/captureMessage/simple_message/test.ts index 86a7d231ee80..d41fd76ddf76 100644 --- a/packages/node-integration-tests/suites/public-api/captureMessage/simple_message/test.ts +++ b/packages/node-integration-tests/suites/public-api/captureMessage/simple_message/test.ts @@ -1,8 +1,8 @@ -import { assertSentryEvent, getMultipleEnvelopeRequest, runServer, filterEnvelopeItems } from '../../../../utils'; +import { assertSentryEvent, filterEnvelopeItems, getMultipleEnvelopeRequest, runServer } from '../../../../utils'; test('should capture a simple message string', async () => { const config = await runServer(__dirname); - const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(config,{count: 2})); + const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(config, { count: 2 })); assertSentryEvent(events[0], { message: 'Message', diff --git a/packages/node-integration-tests/suites/public-api/captureMessage/with_level/test.ts b/packages/node-integration-tests/suites/public-api/captureMessage/with_level/test.ts index bfc2ff4e4aa7..e3ec43a8389b 100644 --- a/packages/node-integration-tests/suites/public-api/captureMessage/with_level/test.ts +++ b/packages/node-integration-tests/suites/public-api/captureMessage/with_level/test.ts @@ -1,8 +1,8 @@ -import { assertSentryEvent, getMultipleEnvelopeRequest, runServer, filterEnvelopeItems } from '../../../../utils'; +import { assertSentryEvent, filterEnvelopeItems, getMultipleEnvelopeRequest, runServer } from '../../../../utils'; test('should capture with different severity levels', async () => { const config = await runServer(__dirname); - const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(config,{count: 12})); + const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(config, { count: 12 })); assertSentryEvent(events[0], { message: 'debug_message', diff --git a/packages/node-integration-tests/suites/public-api/setContext/multiple-contexts/test.ts b/packages/node-integration-tests/suites/public-api/setContext/multiple-contexts/test.ts index 52e0d4a1a0a1..b21e87d244a9 100644 --- a/packages/node-integration-tests/suites/public-api/setContext/multiple-contexts/test.ts +++ b/packages/node-integration-tests/suites/public-api/setContext/multiple-contexts/test.ts @@ -1,10 +1,10 @@ import { Event } from '@sentry/node'; -import { assertSentryEvent, getMultipleEnvelopeRequest, runServer, filterEnvelopeItems } from '../../../../utils'; +import { assertSentryEvent, filterEnvelopeItems, getMultipleEnvelopeRequest, runServer } from '../../../../utils'; test('should record multiple contexts', async () => { const config = await runServer(__dirname); - const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(config,{count: 2})); + const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(config, { count: 2 })); assertSentryEvent(events[0], { message: 'multiple_contexts', diff --git a/packages/node-integration-tests/suites/public-api/setContext/non-serializable-context/test.ts b/packages/node-integration-tests/suites/public-api/setContext/non-serializable-context/test.ts index d393244349de..704281213985 100644 --- a/packages/node-integration-tests/suites/public-api/setContext/non-serializable-context/test.ts +++ b/packages/node-integration-tests/suites/public-api/setContext/non-serializable-context/test.ts @@ -1,10 +1,10 @@ import { Event } from '@sentry/node'; -import { assertSentryEvent, getMultipleEnvelopeRequest, runServer, filterEnvelopeItems } from '../../../../utils'; +import { assertSentryEvent, filterEnvelopeItems, getMultipleEnvelopeRequest, runServer } from '../../../../utils'; test('should normalize non-serializable context', async () => { const config = await runServer(__dirname); - const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(config,{count: 2})); + const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(config, { count: 2 })); assertSentryEvent(events[0], { message: 'non_serializable', diff --git a/packages/node-integration-tests/suites/public-api/setExtra/multiple-extras/test.ts b/packages/node-integration-tests/suites/public-api/setExtra/multiple-extras/test.ts index 16656c6a1bb3..80b861ded5f4 100644 --- a/packages/node-integration-tests/suites/public-api/setExtra/multiple-extras/test.ts +++ b/packages/node-integration-tests/suites/public-api/setExtra/multiple-extras/test.ts @@ -1,8 +1,8 @@ -import { assertSentryEvent, getMultipleEnvelopeRequest, runServer, filterEnvelopeItems } from '../../../../utils'; +import { assertSentryEvent, filterEnvelopeItems, getMultipleEnvelopeRequest, runServer } from '../../../../utils'; test('should record multiple extras of different types', async () => { const config = await runServer(__dirname); - const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(config, {count:2})); + const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(config, { count: 2 })); assertSentryEvent(events[0], { message: 'multiple_extras', diff --git a/packages/node-integration-tests/suites/public-api/setExtra/non-serializable-extra/test.ts b/packages/node-integration-tests/suites/public-api/setExtra/non-serializable-extra/test.ts index 0021ac1541d8..cea3cf2a9166 100644 --- a/packages/node-integration-tests/suites/public-api/setExtra/non-serializable-extra/test.ts +++ b/packages/node-integration-tests/suites/public-api/setExtra/non-serializable-extra/test.ts @@ -1,8 +1,8 @@ -import { assertSentryEvent, getMultipleEnvelopeRequest, runServer, filterEnvelopeItems } from '../../../../utils'; +import { assertSentryEvent, filterEnvelopeItems, getMultipleEnvelopeRequest, runServer } from '../../../../utils'; test('should normalize non-serializable extra', async () => { const config = await runServer(__dirname); - const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(config, {count:2})); + const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(config, { count: 2 })); assertSentryEvent(events[0], { message: 'non_serializable', diff --git a/packages/node-integration-tests/suites/public-api/setExtra/simple-extra/test.ts b/packages/node-integration-tests/suites/public-api/setExtra/simple-extra/test.ts index 47bfb240b3d6..7ce98e2817b3 100644 --- a/packages/node-integration-tests/suites/public-api/setExtra/simple-extra/test.ts +++ b/packages/node-integration-tests/suites/public-api/setExtra/simple-extra/test.ts @@ -1,8 +1,8 @@ -import { assertSentryEvent, getMultipleEnvelopeRequest, runServer, filterEnvelopeItems } from '../../../../utils'; +import { assertSentryEvent, filterEnvelopeItems, getMultipleEnvelopeRequest, runServer } from '../../../../utils'; test('should set a simple extra', async () => { const config = await runServer(__dirname); - const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(config, {count:2})); + const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(config, { count: 2 })); assertSentryEvent(events[0], { message: 'simple_extra', diff --git a/packages/node-integration-tests/suites/public-api/setExtras/multiple-extras/test.ts b/packages/node-integration-tests/suites/public-api/setExtras/multiple-extras/test.ts index b6167ecfacbe..5dcc0a6e0cd8 100644 --- a/packages/node-integration-tests/suites/public-api/setExtras/multiple-extras/test.ts +++ b/packages/node-integration-tests/suites/public-api/setExtras/multiple-extras/test.ts @@ -1,8 +1,8 @@ -import { assertSentryEvent, getMultipleEnvelopeRequest, runServer, filterEnvelopeItems } from '../../../../utils'; +import { assertSentryEvent, filterEnvelopeItems, getMultipleEnvelopeRequest, runServer } from '../../../../utils'; test('should record an extras object', async () => { const config = await runServer(__dirname); - const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(config,{count: 2})); + const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(config, { count: 2 })); assertSentryEvent(events[0], { message: 'multiple_extras', diff --git a/packages/node-integration-tests/suites/public-api/setTag/with-primitives/test.ts b/packages/node-integration-tests/suites/public-api/setTag/with-primitives/test.ts index ed66e59e951d..a59630198a34 100644 --- a/packages/node-integration-tests/suites/public-api/setTag/with-primitives/test.ts +++ b/packages/node-integration-tests/suites/public-api/setTag/with-primitives/test.ts @@ -1,8 +1,8 @@ -import { assertSentryEvent, getMultipleEnvelopeRequest, runServer, filterEnvelopeItems } from '../../../../utils'; +import { assertSentryEvent, filterEnvelopeItems, getMultipleEnvelopeRequest, runServer } from '../../../../utils'; test('should set primitive tags', async () => { const config = await runServer(__dirname); - const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(config, {count:2})); + const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(config, { count: 2 })); assertSentryEvent(events[0], { message: 'primitive_tags', diff --git a/packages/node-integration-tests/suites/public-api/setTags/with-primitives/test.ts b/packages/node-integration-tests/suites/public-api/setTags/with-primitives/test.ts index ed66e59e951d..a59630198a34 100644 --- a/packages/node-integration-tests/suites/public-api/setTags/with-primitives/test.ts +++ b/packages/node-integration-tests/suites/public-api/setTags/with-primitives/test.ts @@ -1,8 +1,8 @@ -import { assertSentryEvent, getMultipleEnvelopeRequest, runServer, filterEnvelopeItems } from '../../../../utils'; +import { assertSentryEvent, filterEnvelopeItems, getMultipleEnvelopeRequest, runServer } from '../../../../utils'; test('should set primitive tags', async () => { const config = await runServer(__dirname); - const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(config, {count:2})); + const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(config, { count: 2 })); assertSentryEvent(events[0], { message: 'primitive_tags', diff --git a/packages/node-integration-tests/suites/public-api/setUser/unset_user/test.ts b/packages/node-integration-tests/suites/public-api/setUser/unset_user/test.ts index a406d3f82a86..3b0c08772346 100644 --- a/packages/node-integration-tests/suites/public-api/setUser/unset_user/test.ts +++ b/packages/node-integration-tests/suites/public-api/setUser/unset_user/test.ts @@ -1,10 +1,10 @@ import { Event } from '@sentry/node'; -import { assertSentryEvent, getMultipleEnvelopeRequest, runServer, filterEnvelopeItems } from '../../../../utils'; +import { assertSentryEvent, filterEnvelopeItems, getMultipleEnvelopeRequest, runServer } from '../../../../utils'; test('should unset user', async () => { const config = await runServer(__dirname); - const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(config, {count:6})); + const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(config, { count: 6 })); assertSentryEvent(events[0], { message: 'no_user', diff --git a/packages/node-integration-tests/suites/public-api/withScope/nested-scopes/test.ts b/packages/node-integration-tests/suites/public-api/withScope/nested-scopes/test.ts index 14c2da5a12a2..996956d7668b 100644 --- a/packages/node-integration-tests/suites/public-api/withScope/nested-scopes/test.ts +++ b/packages/node-integration-tests/suites/public-api/withScope/nested-scopes/test.ts @@ -1,10 +1,10 @@ import { Event } from '@sentry/node'; -import { assertSentryEvent, getMultipleEnvelopeRequest, runServer, filterEnvelopeItems } from '../../../../utils'; +import { assertSentryEvent, filterEnvelopeItems, getMultipleEnvelopeRequest, runServer } from '../../../../utils'; test('should allow nested scoping', async () => { const config = await runServer(__dirname); - const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(config, {count:10})); + const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(config, { count: 10 })); assertSentryEvent(events[0], { message: 'root_before', From 880108368d66da5388a2c5519afe51e9fbeb8f7e Mon Sep 17 00:00:00 2001 From: Tim Fish Date: Mon, 29 Aug 2022 19:35:54 +0100 Subject: [PATCH 10/11] remove usage of `filterEnvelopeItems` --- .../addBreadcrumb/multiple_breadcrumbs/test.ts | 6 +++--- .../captureException/catched-error/test.ts | 6 +++--- .../captureException/empty-obj/test.ts | 6 +++--- .../captureException/simple-error/test.ts | 6 +++--- .../captureMessage/simple_message/test.ts | 6 +++--- .../public-api/captureMessage/with_level/test.ts | 16 ++++++++-------- .../setContext/multiple-contexts/test.ts | 6 +++--- .../setContext/non-serializable-context/test.ts | 6 +++--- .../public-api/setContext/simple-context/test.ts | 8 ++++---- .../public-api/setExtra/multiple-extras/test.ts | 6 +++--- .../setExtra/non-serializable-extra/test.ts | 6 +++--- .../public-api/setExtra/simple-extra/test.ts | 6 +++--- .../setExtras/consecutive-calls/test.ts | 6 +++--- .../public-api/setExtras/multiple-extras/test.ts | 6 +++--- .../public-api/setTag/with-primitives/test.ts | 6 +++--- .../public-api/setTags/with-primitives/test.ts | 6 +++--- .../suites/public-api/setUser/unset_user/test.ts | 10 +++++----- .../public-api/withScope/nested-scopes/test.ts | 14 +++++++------- packages/node-integration-tests/utils/index.ts | 11 ----------- 19 files changed, 66 insertions(+), 77 deletions(-) diff --git a/packages/node-integration-tests/suites/public-api/addBreadcrumb/multiple_breadcrumbs/test.ts b/packages/node-integration-tests/suites/public-api/addBreadcrumb/multiple_breadcrumbs/test.ts index f9d35e0243db..9f5ca599f891 100644 --- a/packages/node-integration-tests/suites/public-api/addBreadcrumb/multiple_breadcrumbs/test.ts +++ b/packages/node-integration-tests/suites/public-api/addBreadcrumb/multiple_breadcrumbs/test.ts @@ -1,10 +1,10 @@ -import { assertSentryEvent, filterEnvelopeItems, getMultipleEnvelopeRequest, runServer } from '../../../../utils'; +import { assertSentryEvent, getEnvelopeRequest, runServer } from '../../../../utils'; test('should add multiple breadcrumbs', async () => { const config = await runServer(__dirname); - const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(config, { count: 1 })); + const events = await getEnvelopeRequest(config); - assertSentryEvent(events[0], { + assertSentryEvent(events[2], { message: 'test_multi_breadcrumbs', breadcrumbs: [ { diff --git a/packages/node-integration-tests/suites/public-api/captureException/catched-error/test.ts b/packages/node-integration-tests/suites/public-api/captureException/catched-error/test.ts index f24c39d6f21a..e09f29fae48a 100644 --- a/packages/node-integration-tests/suites/public-api/captureException/catched-error/test.ts +++ b/packages/node-integration-tests/suites/public-api/captureException/catched-error/test.ts @@ -1,10 +1,10 @@ -import { assertSentryEvent, filterEnvelopeItems, getMultipleEnvelopeRequest, runServer } from '../../../../utils'; +import { assertSentryEvent, getMultipleEnvelopeRequest, runServer } from '../../../../utils'; test('should work inside catch block', async () => { const config = await runServer(__dirname); - const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(config, { count: 1 })); + const events = await getMultipleEnvelopeRequest(config, { count: 1 }); - assertSentryEvent(events[0], { + assertSentryEvent(events[0][2], { exception: { values: [ { diff --git a/packages/node-integration-tests/suites/public-api/captureException/empty-obj/test.ts b/packages/node-integration-tests/suites/public-api/captureException/empty-obj/test.ts index 47c9bec9f666..d0fca28137c6 100644 --- a/packages/node-integration-tests/suites/public-api/captureException/empty-obj/test.ts +++ b/packages/node-integration-tests/suites/public-api/captureException/empty-obj/test.ts @@ -1,10 +1,10 @@ -import { assertSentryEvent, filterEnvelopeItems, getMultipleEnvelopeRequest, runServer } from '../../../../utils'; +import { assertSentryEvent, getEnvelopeRequest, runServer } from '../../../../utils'; test('should capture an empty object', async () => { const config = await runServer(__dirname); - const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(config, { count: 1 })); + const events = await getEnvelopeRequest(config); - assertSentryEvent(events[0], { + assertSentryEvent(events[2], { exception: { values: [ { diff --git a/packages/node-integration-tests/suites/public-api/captureException/simple-error/test.ts b/packages/node-integration-tests/suites/public-api/captureException/simple-error/test.ts index 76c53163b755..f09d75769385 100644 --- a/packages/node-integration-tests/suites/public-api/captureException/simple-error/test.ts +++ b/packages/node-integration-tests/suites/public-api/captureException/simple-error/test.ts @@ -1,10 +1,10 @@ -import { assertSentryEvent, filterEnvelopeItems, getMultipleEnvelopeRequest, runServer } from '../../../../utils'; +import { assertSentryEvent, getEnvelopeRequest, runServer } from '../../../../utils'; test('should capture a simple error with message', async () => { const config = await runServer(__dirname); - const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(config, { count: 1 })); + const events = await getEnvelopeRequest(config); - assertSentryEvent(events[0], { + assertSentryEvent(events[2], { exception: { values: [ { diff --git a/packages/node-integration-tests/suites/public-api/captureMessage/simple_message/test.ts b/packages/node-integration-tests/suites/public-api/captureMessage/simple_message/test.ts index 17826f80e222..bc940f99eafc 100644 --- a/packages/node-integration-tests/suites/public-api/captureMessage/simple_message/test.ts +++ b/packages/node-integration-tests/suites/public-api/captureMessage/simple_message/test.ts @@ -1,10 +1,10 @@ -import { assertSentryEvent, filterEnvelopeItems, getMultipleEnvelopeRequest, runServer } from '../../../../utils'; +import { assertSentryEvent, getEnvelopeRequest, runServer } from '../../../../utils'; test('should capture a simple message string', async () => { const config = await runServer(__dirname); - const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(config, { count: 1 })); + const events = await getEnvelopeRequest(config); - assertSentryEvent(events[0], { + assertSentryEvent(events[2], { message: 'Message', level: 'info', }); diff --git a/packages/node-integration-tests/suites/public-api/captureMessage/with_level/test.ts b/packages/node-integration-tests/suites/public-api/captureMessage/with_level/test.ts index 04ff876f794b..ff327c0c866d 100644 --- a/packages/node-integration-tests/suites/public-api/captureMessage/with_level/test.ts +++ b/packages/node-integration-tests/suites/public-api/captureMessage/with_level/test.ts @@ -1,35 +1,35 @@ -import { assertSentryEvent, filterEnvelopeItems, getMultipleEnvelopeRequest, runServer } from '../../../../utils'; +import { assertSentryEvent, getMultipleEnvelopeRequest, runServer } from '../../../../utils'; test('should capture with different severity levels', async () => { const config = await runServer(__dirname); - const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(config, { count: 6 })); + const events = await getMultipleEnvelopeRequest(config, { count: 6 }); - assertSentryEvent(events[0], { + assertSentryEvent(events[0][2], { message: 'debug_message', level: 'debug', }); - assertSentryEvent(events[1], { + assertSentryEvent(events[1][2], { message: 'info_message', level: 'info', }); - assertSentryEvent(events[2], { + assertSentryEvent(events[2][2], { message: 'warning_message', level: 'warning', }); - assertSentryEvent(events[3], { + assertSentryEvent(events[3][2], { message: 'error_message', level: 'error', }); - assertSentryEvent(events[4], { + assertSentryEvent(events[4][2], { message: 'fatal_message', level: 'fatal', }); - assertSentryEvent(events[5], { + assertSentryEvent(events[5][2], { message: 'log_message', level: 'log', }); diff --git a/packages/node-integration-tests/suites/public-api/setContext/multiple-contexts/test.ts b/packages/node-integration-tests/suites/public-api/setContext/multiple-contexts/test.ts index 3e6107d2814d..a365f63af9fa 100644 --- a/packages/node-integration-tests/suites/public-api/setContext/multiple-contexts/test.ts +++ b/packages/node-integration-tests/suites/public-api/setContext/multiple-contexts/test.ts @@ -1,12 +1,12 @@ import { Event } from '@sentry/node'; -import { assertSentryEvent, filterEnvelopeItems, getMultipleEnvelopeRequest, runServer } from '../../../../utils'; +import { assertSentryEvent, getEnvelopeRequest, runServer } from '../../../../utils'; test('should record multiple contexts', async () => { const config = await runServer(__dirname); - const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(config, { count: 1 })); + const events = await getEnvelopeRequest(config); - assertSentryEvent(events[0], { + assertSentryEvent(events[2], { message: 'multiple_contexts', contexts: { context_1: { diff --git a/packages/node-integration-tests/suites/public-api/setContext/non-serializable-context/test.ts b/packages/node-integration-tests/suites/public-api/setContext/non-serializable-context/test.ts index f7f8a34cb11d..d685215aa0c7 100644 --- a/packages/node-integration-tests/suites/public-api/setContext/non-serializable-context/test.ts +++ b/packages/node-integration-tests/suites/public-api/setContext/non-serializable-context/test.ts @@ -1,12 +1,12 @@ import { Event } from '@sentry/node'; -import { assertSentryEvent, filterEnvelopeItems, getMultipleEnvelopeRequest, runServer } from '../../../../utils'; +import { assertSentryEvent, getEnvelopeRequest, runServer } from '../../../../utils'; test('should normalize non-serializable context', async () => { const config = await runServer(__dirname); - const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(config, { count: 1 })); + const events = await getEnvelopeRequest(config); - assertSentryEvent(events[0], { + assertSentryEvent(events[2], { message: 'non_serializable', contexts: {}, }); diff --git a/packages/node-integration-tests/suites/public-api/setContext/simple-context/test.ts b/packages/node-integration-tests/suites/public-api/setContext/simple-context/test.ts index ea787fbea7c7..16a4ab8486d3 100644 --- a/packages/node-integration-tests/suites/public-api/setContext/simple-context/test.ts +++ b/packages/node-integration-tests/suites/public-api/setContext/simple-context/test.ts @@ -1,12 +1,12 @@ import { Event } from '@sentry/node'; -import { assertSentryEvent, getMultipleEnvelopeRequest, runServer } from '../../../../utils'; +import { assertSentryEvent, getEnvelopeRequest, runServer } from '../../../../utils'; test('should set a simple context', async () => { const config = await runServer(__dirname); - const envelopes = await getMultipleEnvelopeRequest(config, { count: 1 }); + const envelopes = await getEnvelopeRequest(config); - assertSentryEvent(envelopes[0][2], { + assertSentryEvent(envelopes[2], { message: 'simple_context_object', contexts: { foo: { @@ -15,5 +15,5 @@ test('should set a simple context', async () => { }, }); - expect((envelopes[0][2] as Event).contexts?.context_3).not.toBeDefined(); + expect((envelopes[2] as Event).contexts?.context_3).not.toBeDefined(); }); diff --git a/packages/node-integration-tests/suites/public-api/setExtra/multiple-extras/test.ts b/packages/node-integration-tests/suites/public-api/setExtra/multiple-extras/test.ts index ec6c478f9220..0bad46b894de 100644 --- a/packages/node-integration-tests/suites/public-api/setExtra/multiple-extras/test.ts +++ b/packages/node-integration-tests/suites/public-api/setExtra/multiple-extras/test.ts @@ -1,10 +1,10 @@ -import { assertSentryEvent, filterEnvelopeItems, getMultipleEnvelopeRequest, runServer } from '../../../../utils'; +import { assertSentryEvent, getEnvelopeRequest, runServer } from '../../../../utils'; test('should record multiple extras of different types', async () => { const config = await runServer(__dirname); - const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(config, { count: 1 })); + const events = await getEnvelopeRequest(config); - assertSentryEvent(events[0], { + assertSentryEvent(events[2], { message: 'multiple_extras', extra: { extra_1: { foo: 'bar', baz: { qux: 'quux' } }, diff --git a/packages/node-integration-tests/suites/public-api/setExtra/non-serializable-extra/test.ts b/packages/node-integration-tests/suites/public-api/setExtra/non-serializable-extra/test.ts index d0e90feab7e2..9af242805d36 100644 --- a/packages/node-integration-tests/suites/public-api/setExtra/non-serializable-extra/test.ts +++ b/packages/node-integration-tests/suites/public-api/setExtra/non-serializable-extra/test.ts @@ -1,10 +1,10 @@ -import { assertSentryEvent, filterEnvelopeItems, getMultipleEnvelopeRequest, runServer } from '../../../../utils'; +import { assertSentryEvent, getEnvelopeRequest, runServer } from '../../../../utils'; test('should normalize non-serializable extra', async () => { const config = await runServer(__dirname); - const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(config, { count: 1 })); + const events = await getEnvelopeRequest(config); - assertSentryEvent(events[0], { + assertSentryEvent(events[2], { message: 'non_serializable', extra: {}, }); diff --git a/packages/node-integration-tests/suites/public-api/setExtra/simple-extra/test.ts b/packages/node-integration-tests/suites/public-api/setExtra/simple-extra/test.ts index 2241f39b0bc8..4441f0939000 100644 --- a/packages/node-integration-tests/suites/public-api/setExtra/simple-extra/test.ts +++ b/packages/node-integration-tests/suites/public-api/setExtra/simple-extra/test.ts @@ -1,10 +1,10 @@ -import { assertSentryEvent, filterEnvelopeItems, getMultipleEnvelopeRequest, runServer } from '../../../../utils'; +import { assertSentryEvent, getEnvelopeRequest, runServer } from '../../../../utils'; test('should set a simple extra', async () => { const config = await runServer(__dirname); - const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(config, { count: 1 })); + const events = await getEnvelopeRequest(config); - assertSentryEvent(events[0], { + assertSentryEvent(events[2], { message: 'simple_extra', extra: { foo: { diff --git a/packages/node-integration-tests/suites/public-api/setExtras/consecutive-calls/test.ts b/packages/node-integration-tests/suites/public-api/setExtras/consecutive-calls/test.ts index 277361de82bb..87a5f10994d2 100644 --- a/packages/node-integration-tests/suites/public-api/setExtras/consecutive-calls/test.ts +++ b/packages/node-integration-tests/suites/public-api/setExtras/consecutive-calls/test.ts @@ -1,10 +1,10 @@ -import { assertSentryEvent, getMultipleEnvelopeRequest, runServer } from '../../../../utils'; +import { assertSentryEvent, getEnvelopeRequest, runServer } from '../../../../utils'; test('should set extras from multiple consecutive calls', async () => { const config = await runServer(__dirname); - const envelopes = await getMultipleEnvelopeRequest(config, { count: 1 }); + const envelopes = await getEnvelopeRequest(config); - assertSentryEvent(envelopes[0][2], { + assertSentryEvent(envelopes[2], { message: 'consecutive_calls', extra: { extra: [], Infinity: 2, null: 0, obj: { foo: ['bar', 'baz', 1] } }, }); diff --git a/packages/node-integration-tests/suites/public-api/setExtras/multiple-extras/test.ts b/packages/node-integration-tests/suites/public-api/setExtras/multiple-extras/test.ts index 60a637d14bfb..4174ca98df93 100644 --- a/packages/node-integration-tests/suites/public-api/setExtras/multiple-extras/test.ts +++ b/packages/node-integration-tests/suites/public-api/setExtras/multiple-extras/test.ts @@ -1,10 +1,10 @@ -import { assertSentryEvent, filterEnvelopeItems, getMultipleEnvelopeRequest, runServer } from '../../../../utils'; +import { assertSentryEvent, getEnvelopeRequest, runServer } from '../../../../utils'; test('should record an extras object', async () => { const config = await runServer(__dirname); - const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(config, { count: 1 })); + const events = await getEnvelopeRequest(config); - assertSentryEvent(events[0], { + assertSentryEvent(events[2], { message: 'multiple_extras', extra: { extra_1: [1, ['foo'], 'bar'], diff --git a/packages/node-integration-tests/suites/public-api/setTag/with-primitives/test.ts b/packages/node-integration-tests/suites/public-api/setTag/with-primitives/test.ts index 6bcfbc05bed4..16c81c323a58 100644 --- a/packages/node-integration-tests/suites/public-api/setTag/with-primitives/test.ts +++ b/packages/node-integration-tests/suites/public-api/setTag/with-primitives/test.ts @@ -1,10 +1,10 @@ -import { assertSentryEvent, filterEnvelopeItems, getMultipleEnvelopeRequest, runServer } from '../../../../utils'; +import { assertSentryEvent, getEnvelopeRequest, runServer } from '../../../../utils'; test('should set primitive tags', async () => { const config = await runServer(__dirname); - const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(config, { count: 1 })); + const events = await getEnvelopeRequest(config); - assertSentryEvent(events[0], { + assertSentryEvent(events[2], { message: 'primitive_tags', tags: { tag_1: 'foo', diff --git a/packages/node-integration-tests/suites/public-api/setTags/with-primitives/test.ts b/packages/node-integration-tests/suites/public-api/setTags/with-primitives/test.ts index 6bcfbc05bed4..16c81c323a58 100644 --- a/packages/node-integration-tests/suites/public-api/setTags/with-primitives/test.ts +++ b/packages/node-integration-tests/suites/public-api/setTags/with-primitives/test.ts @@ -1,10 +1,10 @@ -import { assertSentryEvent, filterEnvelopeItems, getMultipleEnvelopeRequest, runServer } from '../../../../utils'; +import { assertSentryEvent, getEnvelopeRequest, runServer } from '../../../../utils'; test('should set primitive tags', async () => { const config = await runServer(__dirname); - const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(config, { count: 1 })); + const events = await getEnvelopeRequest(config); - assertSentryEvent(events[0], { + assertSentryEvent(events[2], { message: 'primitive_tags', tags: { tag_1: 'foo', diff --git a/packages/node-integration-tests/suites/public-api/setUser/unset_user/test.ts b/packages/node-integration-tests/suites/public-api/setUser/unset_user/test.ts index 7aaeb9d8eec3..2f9934bd87e7 100644 --- a/packages/node-integration-tests/suites/public-api/setUser/unset_user/test.ts +++ b/packages/node-integration-tests/suites/public-api/setUser/unset_user/test.ts @@ -1,18 +1,18 @@ import { Event } from '@sentry/node'; -import { assertSentryEvent, filterEnvelopeItems, getMultipleEnvelopeRequest, runServer } from '../../../../utils'; +import { assertSentryEvent, getMultipleEnvelopeRequest, runServer } from '../../../../utils'; test('should unset user', async () => { const config = await runServer(__dirname); - const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(config, { count: 3 })); + const events = await getMultipleEnvelopeRequest(config, { count: 3 }); - assertSentryEvent(events[0], { + assertSentryEvent(events[0][2], { message: 'no_user', }); expect((events[0] as Event).user).not.toBeDefined(); - assertSentryEvent(events[1], { + assertSentryEvent(events[1][2], { message: 'user', user: { id: 'foo', @@ -21,7 +21,7 @@ test('should unset user', async () => { }, }); - assertSentryEvent(events[2], { + assertSentryEvent(events[2][2], { message: 'unset_user', }); diff --git a/packages/node-integration-tests/suites/public-api/withScope/nested-scopes/test.ts b/packages/node-integration-tests/suites/public-api/withScope/nested-scopes/test.ts index 8629e97ec86e..daea172170c9 100644 --- a/packages/node-integration-tests/suites/public-api/withScope/nested-scopes/test.ts +++ b/packages/node-integration-tests/suites/public-api/withScope/nested-scopes/test.ts @@ -1,19 +1,19 @@ import { Event } from '@sentry/node'; -import { assertSentryEvent, filterEnvelopeItems, getMultipleEnvelopeRequest, runServer } from '../../../../utils'; +import { assertSentryEvent, getMultipleEnvelopeRequest, runServer } from '../../../../utils'; test('should allow nested scoping', async () => { const config = await runServer(__dirname); - const events = filterEnvelopeItems(await getMultipleEnvelopeRequest(config, { count: 5 })); + const events = await getMultipleEnvelopeRequest(config, { count: 5 }); - assertSentryEvent(events[0], { + assertSentryEvent(events[0][2], { message: 'root_before', user: { id: 'qux', }, }); - assertSentryEvent(events[1], { + assertSentryEvent(events[1][2], { message: 'outer_before', user: { id: 'qux', @@ -23,7 +23,7 @@ test('should allow nested scoping', async () => { }, }); - assertSentryEvent(events[2], { + assertSentryEvent(events[2][2], { message: 'inner', tags: { foo: false, @@ -33,7 +33,7 @@ test('should allow nested scoping', async () => { expect((events[2] as Event).user).toBeUndefined(); - assertSentryEvent(events[3], { + assertSentryEvent(events[3][2], { message: 'outer_after', user: { id: 'baz', @@ -43,7 +43,7 @@ test('should allow nested scoping', async () => { }, }); - assertSentryEvent(events[4], { + assertSentryEvent(events[4][2], { message: 'root_after', user: { id: 'qux', diff --git a/packages/node-integration-tests/utils/index.ts b/packages/node-integration-tests/utils/index.ts index 1eafd3b726f2..4724eabd0246 100644 --- a/packages/node-integration-tests/utils/index.ts +++ b/packages/node-integration-tests/utils/index.ts @@ -173,17 +173,6 @@ const makeRequest = async (method: 'get' | 'post', url: string): Promise = } }; -/** - * Filters and returns only a specific type of envelope payload. - */ -export const filterEnvelopeItems = ( - envelopes: Record[][], - type = 'event', -): Record[] => { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - return envelopes.filter(e => (e?.[1] as any)?.type === type).map(e => e[2] as any); -}; - /** * Sends a get request to given URL, with optional headers. Returns the response. * Ends the server instance and flushes the Sentry event queue. From 26fed7e7cfb5267a946952d004ca71a71654045a Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Mon, 29 Aug 2022 15:01:50 -0400 Subject: [PATCH 11/11] Switch from `memory_used` -> `app_memory` --- packages/node/src/integrations/context.ts | 8 ++++---- packages/types/src/context.ts | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/node/src/integrations/context.ts b/packages/node/src/integrations/context.ts index 8e1103ff8a63..62c2b4df8f68 100644 --- a/packages/node/src/integrations/context.ts +++ b/packages/node/src/integrations/context.ts @@ -75,8 +75,8 @@ export class Context implements Integration { */ private _updateContext(contexts: Contexts): Contexts { // Only update properties if they exist - if (contexts?.app?.memory_used) { - contexts.app.memory_used = process.memoryUsage().rss; + if (contexts?.app?.app_memory) { + contexts.app.app_memory = process.memoryUsage().rss; } if (contexts?.device?.free_memory) { @@ -175,10 +175,10 @@ function getCultureContext(): CultureContext | undefined { } function getAppContext(): AppContext { - const memory_used = process.memoryUsage().rss; + const app_memory = process.memoryUsage().rss; const app_start_time = new Date(Date.now() - process.uptime() * 1000).toISOString(); - return { app_start_time, memory_used }; + return { app_start_time, app_memory }; } function getDeviceContext(deviceOpt: DeviceContextOptions | true): DeviceContext { diff --git a/packages/types/src/context.ts b/packages/types/src/context.ts index 61e7dd03fab9..4b6a08585273 100644 --- a/packages/types/src/context.ts +++ b/packages/types/src/context.ts @@ -13,7 +13,7 @@ export interface AppContext extends Record { app_version?: string; app_identifier?: string; build_type?: string; - memory_used?: number; + app_memory?: number; } export interface DeviceContext extends Record {