Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renovate/major sentry javascript monorepo #2277

Merged
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
@@ -0,0 +1,8 @@
---
'@envelop/immediate-introspection': major
---

dependencies updates:

- Updated dependency [`@sentry/node@^8.0.0` ↗︎](https://www.npmjs.com/package/@sentry/node/v/8.0.0)
(from `^6 || ^7`, in `peerDependencies`)
8 changes: 8 additions & 0 deletions .changeset/@envelop_sentry-2235-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@envelop/sentry': major
---

dependencies updates:

- Updated dependency [`@sentry/node@^8.0.0` ↗︎](https://www.npmjs.com/package/@sentry/node/v/8.0.0)
(from `^6 || ^7`, in `peerDependencies`)
2 changes: 1 addition & 1 deletion packages/plugins/immediate-introspection/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"typings": "dist/typings/index.d.ts",
"peerDependencies": {
"@envelop/core": "^5.0.0",
"@sentry/node": "^6 || ^7",
"@sentry/node": "^8.0.0",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wouldn't this change be considered breaking as v6 and v7 is not supported anymore?

"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
},
"dependencies": {},
Expand Down
8 changes: 4 additions & 4 deletions packages/plugins/sentry/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"typings": "dist/typings/index.d.ts",
"peerDependencies": {
"@envelop/core": "^5.0.2",
"@sentry/node": "^6 || ^7",
"@sentry/node": "^8.0.0",
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
},
"dependencies": {
Expand All @@ -57,9 +57,9 @@
"devDependencies": {
"@envelop/core": "workspace:^",
"@graphql-tools/schema": "10.0.6",
"@sentry/node": "7.108.0",
"@sentry/tracing": "7.108.0",
"@sentry/types": "7.108.0",
"@sentry/node": "^8.22.0",
"@sentry/tracing": "^7.114.0",
"@sentry/types": "^8.22.0",
"graphql": "16.8.1",
"sentry-testkit": "5.0.9",
"typescript": "5.1.3"
Expand Down
64 changes: 43 additions & 21 deletions packages/plugins/sentry/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,20 @@ export const useSentry = <PluginContext extends Record<string, any> = {}>(
...addedTags,
};

let rootSpan: Span;
let rootSpan: Span | undefined;

if (startTransaction) {
rootSpan = Sentry.startTransaction({
name: transactionName,
op,
tags,
...traceparentData,
});
Sentry.startSpan(
{
name: transactionName,
op,
attributes: tags,
...traceparentData,
},
span => {
rootSpan = span;
},
);

if (!rootSpan) {
const error = [
Expand All @@ -149,15 +154,33 @@ export const useSentry = <PluginContext extends Record<string, any> = {}>(
throw new Error(error.join('\n'));
}
} else {
const scope = Sentry.getCurrentHub().getScope();
const parentSpan = scope?.getSpan();
const span = parentSpan?.startChild({
description: transactionName,
op,
tags,
let childSpan: Span | undefined;
const scope = Sentry.getCurrentScope();
const parentSpan = scope?.getScopeData().span;
if (!parentSpan) {
// eslint-disable-next-line no-console
console.warn(
[
`Flag "startTransaction" is disabled but Sentry failed to find a transaction.`,
`Try to create a transaction before GraphQL execution phase is started.`,
].join('\n'),
);
return {};
}
Sentry.withActiveSpan(parentSpan, () => {
Sentry.startSpan(
{
name: transactionName,
op,
attributes: tags,
},
span => {
childSpan = span;
},
);
});

if (!span) {
if (!childSpan) {
// eslint-disable-next-line no-console
console.warn(
[
Expand All @@ -168,26 +191,25 @@ export const useSentry = <PluginContext extends Record<string, any> = {}>(
return {};
}

rootSpan = span;
rootSpan = childSpan;

if (renameTransaction) {
scope!.setTransactionName(transactionName);
}
}

Sentry.configureScope(scope => scope.setSpan(rootSpan));

rootSpan.setData('document', document);
rootSpan.setAttribute('document', document);

if (options.configureScope) {
Sentry.configureScope(scope => options.configureScope!(args, scope));
options.configureScope(args, Sentry.getCurrentScope());
}

return {
onExecuteDone(payload) {
const handleResult: OnExecuteDoneHookResultOnNextHook<{}> = ({ result, setResult }) => {
if (includeRawResult) {
rootSpan.setData('result', result);
// @ts-expect-error TODO: not sure if this is correct
rootSpan?.setAttribute('result', result);
}

if (result.errors && result.errors.length > 0) {
Expand Down Expand Up @@ -245,7 +267,7 @@ export const useSentry = <PluginContext extends Record<string, any> = {}>(
});
}

rootSpan.finish();
rootSpan?.end();
};
return handleStreamOrSingleExecutionResult(payload, handleResult);
},
Expand Down
Loading