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

Multiple incompatible Scope types in v8.x #12053

Closed
3 tasks done
alumni opened this issue May 15, 2024 · 4 comments · Fixed by #12067
Closed
3 tasks done

Multiple incompatible Scope types in v8.x #12053

alumni opened this issue May 15, 2024 · 4 comments · Fixed by #12067
Labels
Package: node Issues related to the Sentry Node SDK Type: Bug

Comments

@alumni
Copy link

alumni commented May 15, 2024

Is there an existing issue for this?

How do you use Sentry?

Self-hosted/on-premise

Which SDK are you using?

@sentry/node

SDK Version

8.0.0

Framework Version

NestJS 10

Link to Sentry event

No response

SDK Setup

No response

Steps to Reproduce

It seems there are multiple types for Scope which are incompatible with each other.

withScope() from @sentry/core is using Scope from @sentry/types, but there is also a Scope in @sentry/core.

Both are directly or indirectly exported also by @sentry/node.

Expected Result

We tend to use everything from @sentry/node (since we should not care about the internals of Sentry). It would be great to have proper type compatibility.

Actual Result

The two Scope types are not compatible with each other:

Argument of type
'import(".../node_modules/@sentry/types/types/scope").Scope'
is not assignable to parameter of type
'import(".../node_modules/@sentry/core/types/scope").Scope'.

@github-actions github-actions bot added the Package: node Issues related to the Sentry Node SDK label May 15, 2024
@roderik
Copy link

roderik commented May 16, 2024

To make it worse, the re-exported withScope in @sentry/node is using this different Scope, so even an import line like import { Scope, addRequestDataToEvent, captureException, withScope } from '@sentry/node'; is incompatible

Nor does this work

import { Scope, withScope } from '@sentry/core';
import { addRequestDataToEvent, captureException } from '@sentry/node';

@mydea
Copy link
Member

mydea commented May 16, 2024

Hey,

could you share the actual code that is triggering this problem for you? e.g.

import {Scope} from '@sentry/node';

function myFunction(scope: Scope): void {
  xxx(scope);
}

It should be the case that you can pass the scope from @sentry/node everywhere - this is the actual scope class, while in all places that accept a scope we should be using the scope type. but it may be the case that we missed some place there 🤔

@alumni
Copy link
Author

alumni commented May 16, 2024

Sorry, I didn't write properly in the issue description, but it's exactly what @roderik is mentioning as well.

import { type Scope, withScope } from '@sentry/node';

withScope((scope: Scope) => {});
//         ^
// Argument of type
// 'import(".../node_modules/@sentry/types/types/scope").Scope'
// is not assignable to parameter of type
// 'import(".../node_modules/@sentry/core/types/scope").Scope'.

@sentry/node exports the Scope class from @sentry/core.
@sentry/node also exports withScope from @sentry/core. This withScope method has a callback argument of type Scope, an interface that comes from @sentry/types.

This was not the case in v7, where the Scope class was also used by the callback of withScope.

The class and the interface are not compatible with each other.

@mydea
Copy link
Member

mydea commented May 16, 2024

Ah, I see now.

Yeah, this is a bit annoying/tricky. What you can do for now is install @sentry/types and import all the types you use in your app from there:

import { withScope } from '@sentry/node';
import type { Scope } from '@sentry/types';

withScope(scope: Scope, () => {});

(that, or let the type be inferred, which should be correct as well).

I have opened a PR to fix this behavior in the next version: #12067
There, it should work again to do import type {Scope} from '@sentry/node' and get the expected behavior!

mydea added a commit that referenced this issue May 16, 2024
To make interop with e.g. importing `Scope` from `@sentry/node` easier.

Closes #12053
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: node Issues related to the Sentry Node SDK Type: Bug
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants