Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
23 changes: 9 additions & 14 deletions packages/google-cloud-serverless/test/gcpfunction/events.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as domain from 'domain';
import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core';
import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, isThenable } from '@sentry/core';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe isThenable is not used.

also thank you for this simplification - I've missed the fact that _wrapEventFunction calls callback and no extra Promise waiting needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

should I just add a commit to fix biome warning? not sure about squashing at this point though.

Copy link
Contributor

Choose a reason for hiding this comment

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

feel free to!

Copy link
Contributor

Choose a reason for hiding this comment

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

we squash all of our prs - don't worry about clean commit history

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah ok - thanks for clarification. pushed a fix


import type { Event } from '@sentry/core';
import { wrapEventFunction } from '../../src/gcpfunction/events';
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