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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as domain from 'domain';
import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core';

import { wrapCloudEventFunction } from '../../src/gcpfunction/cloud_events';
Expand Down Expand Up @@ -44,21 +43,21 @@ describe('wrapCloudEventFunction', () => {

function handleCloudEvent(fn: CloudEventFunctionWithCallback): Promise<any> {
return new Promise((resolve, reject) => {
// eslint-disable-next-line deprecation/deprecation
const d = domain.create();
const context = {
type: 'event.type',
};
d.on('error', reject);
d.run(() =>
process.nextTick(fn, context, (err: any, result: any) => {

try {
fn(context, (err: any, result: any) => {
if (err != null || err != undefined) {
reject(err);
} else {
resolve(result);
}
}),
);
});
} catch (error) {
reject(error);
}
});
}

Expand Down
21 changes: 8 additions & 13 deletions packages/google-cloud-serverless/test/gcpfunction/events.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as domain from 'domain';
import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core';

import type { Event } from '@sentry/core';
Expand Down Expand Up @@ -45,22 +44,18 @@ describe('wrapEventFunction', () => {

function handleEvent(fn: EventFunctionWithCallback): Promise<any> {
return new Promise((resolve, reject) => {
// eslint-disable-next-line deprecation/deprecation
const d = domain.create();
const context = {
eventType: 'event.type',
resource: 'some.resource',
};
d.on('error', reject);
d.run(() =>
process.nextTick(fn, {}, context, (err: any, result: any) => {
if (err != null || err != undefined) {
reject(err);
} else {
resolve(result);
}
}),
);

fn({}, context, (err: any, result: any) => {
if (err != null || err != undefined) {
reject(err);
} else {
resolve(result);
}
});
});
}

Expand Down
12 changes: 6 additions & 6 deletions packages/google-cloud-serverless/test/gcpfunction/http.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import * as domain from 'domain';

import type { Integration } from '@sentry/core';

import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core';
Expand Down Expand Up @@ -58,17 +56,19 @@ describe('GCPFunction', () => {
headers = { ...headers, ...trace_headers };
}
return new Promise((resolve, _reject) => {
// eslint-disable-next-line deprecation/deprecation
const d = domain.create();
const req = {
method: 'POST',
url: '/path?q=query',
headers: headers,
body: { foo: 'bar' },
} as Request;
const res = { end: resolve } as Response;
d.on('error', () => res.end());
d.run(() => process.nextTick(fn, req, res));

try {
fn(req, res);
} catch (error) {
res.end();
}
});
}

Expand Down
Loading