GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — NestJS TypeScript sentry issues not showing local variables for errors · Issue #13768 · getsentry/sentry-javascript

NestJS TypeScript sentry issues not showing local variables for errors #13768

New issue
Copy link
New issue
Copy link
Closed
Closed
NestJS TypeScript sentry issues not showing local variables for errors#13768
Copy link
Assignees
timfish
Labels
Bug

Description

@ganjianwei
ganjianwei
opened on Sep 24, 2024
Issue body actions

Is there an existing issue for this?

  • I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
  • I have reviewed the documentation https://docs.sentry.io/
  • I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/nestjs

SDK Version

8.30.0

Framework Version

NestJS 10.3.0

Link to Sentry event

https://bloom-studios.sentry.io/issues/5891977466/?project=4506396368568320

Reproduction Example/SDK Setup

import { GrpcInstrumentation } from '@opentelemetry/instrumentation-grpc';
import * as Sentry from '@sentry/nestjs';
import { nodeProfilingIntegration } from '@sentry/profiling-node';

const IGNORE_TRANSACTIONS = [
  /__ApolloGetServiceDefinition__/g,
  /graphql.parse/g,
  /graphql.parseSchema/g,
  /redis-connect/g,
];

const MIN_TRANSACTION_DURATION = 0.3;

export function sentryInit() {
  // Ensure to call this before requiring any other modules!
  Sentry.init({
    dsn: process.env.SENTRY_DSN,
    attachStacktrace: true,
    environment: process.env.ENV,
    enabled: Boolean(process.env.IS_CLOUD),
    includeLocalVariables: true,
    integrations: [
      // Add our Profiling integration
      nodeProfilingIntegration(),
      Sentry.extraErrorDataIntegration({ captureErrorCause: true, depth: 10 }),
      Sentry.graphqlIntegration(),
      Sentry.dedupeIntegration(),
      Sentry.localVariablesIntegration({ captureAllExceptions: true }),
    ],
    ignoreTransactions: IGNORE_TRANSACTIONS,
    tracesSampleRate: 1.0,
    profilesSampleRate: 1.0,
    beforeSendTransaction(event) {
      if (event.timestamp && event.start_timestamp) {
        const duration = event.timestamp - event.start_timestamp;

        if (duration >= MIN_TRANSACTION_DURATION) {
          if (event.transaction?.includes('graphql')) {
            const match = /POST \/graphql \((.+)\)/.exec(event.transaction);
            const parsedOperation = match?.[1];

            if (parsedOperation) {
              event.transaction = parsedOperation.replace(/__.*/g, '');
            }
          }

          return event;
        }
      }

      return null;
    },
  });

  Sentry.addOpenTelemetryInstrumentation(new GrpcInstrumentation());
}

export const SentryGraphqlHooks = {
  preExecution: (_schema, documentNode, _mercuriusContext, variables) => {
    const operationDefinition = documentNode.definitions.find(
      (def) => def.kind === 'OperationDefinition'
    );
    const operation = operationDefinition?.operation;
    const operationName = operationDefinition?.name?.value?.replace(
      /__.*/g,
      ''
    );
    const currentScope = Sentry.getCurrentScope();

    if (operation) {
      currentScope.setTag(operation, operationName);
      currentScope.setTransactionName(`${operation} ${operationName}`);
      currentScope.setContext('variables', variables);
    }
  },
};

Steps to Reproduce

Setup NestJS (TypeScript) server app with Sentry like our above setup with:

    includeLocalVariables: true,
    integrations: [
      // ...
      Sentry.localVariablesIntegration({ captureAllExceptions: true }),
    ],

We also use GraphQL with Mercurius & Fastify.

Have any NestJS module > service > any other code throw an error, and it does not show local variables.

Note we used to use "@sentry/node": "^7.110.1" and just tried changing to NestJS to fix this issue, but to no avail.

Expected Result

I'd expect to see local variables in my Sentry page for easier debugging, as we've seen in other integrations (e.g. Django/Python, and also we see the local variables when there's errors in our NestJS controller code specifically, but not everywhere else).

E.g. from your blog post: https://blog.sentry.io/local-variables-for-nodejs-in-sentry/

Image

Actual Result

No local variables in my Sentry issue page for debugging

E.g.
Image
Image
Image

Thank you!

Activity

Next
  1. getsantry
    added
    Waiting for: Product Owner
    on Sep 24, 2024
  2. getsantry
    added this to GitHub Issues with 👀 3on Sep 24, 2024
  3. getsantry
    moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Sep 24, 2024
  4. github-actions
    added
    Package: nestjs
    on Sep 24, 2024
  5. Lms24 commented on Sep 25, 2024

    @Lms24
    Lms24
    on Sep 25, 2024
    Member
    More actions

    Hi @ganjianwei thanks for writing in! Local variables in Node/JS are a bit more complicated than in other languages like python. But I'm gonna tag our local variables integration expert: @timfish could you take a look when you have some time? Thanks!

  6. getsantry
    removed
    Waiting for: Product Owner
    on Sep 25, 2024
  7. getsantry
    moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Sep 25, 2024
  8. Lms24
    assigned
    timfish
    on Sep 25, 2024
  9. timfish commented on Sep 25, 2024

    @timfish
    timfish
    on Sep 25, 2024
    Collaborator
    More actions

    v8.30.0 of the SDKs saw some major changes and improvements to local variables capture but this only affects Node >= v20.

    @ganjianwei What version of Node are you using?

  10. Lms24
    added
    Waiting for: Community
    on Sep 25, 2024
  11. getsantry
    moved this to Waiting for: Community in GitHub Issues with 👀 3on Sep 25, 2024
  12. ganjianwei commented on Sep 25, 2024

    @ganjianwei
    ganjianwei
    on Sep 25, 2024
    Author
    More actions

    hey @timfish we're using Node v20.10.0.

    in case it's helpful, we remember some Sentry issues where it showed local instance variables (e.g. in the NestJS controller code?) so we thought it was because of Mercurius. Unfortunately I can't find those issues with local vars captured to easily pull up

    Then for this example below it's being run in a bull queue so maybe bull's exception handling for the bull dashboard is messing with Sentry capturing the local vars?
    Image

    Thank you! 🙏

  13. getsantry
    added
    Waiting for: Product Owner
    and removed
    Waiting for: Community
    on Sep 25, 2024
  14. getsantry
    moved this from Waiting for: Community to Waiting for: Product Owner in GitHub Issues with 👀 3on Sep 25, 2024
  15. 12 remaining items

  16. getsantry
    moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Sep 29, 2024
  17. bruno-dasilva commented on Sep 29, 2024

    @bruno-dasilva
    bruno-dasilva
    on Sep 29, 2024
    More actions

    xref this comment I added to the PR of why I think this happens: #13827 (comment)

    a minimal reproducible example would likely be to throw an exception but immediately throw it away (+ let it be GC'd?) without doing a Sentry.captureException(). Perhaps that could be added as a test.

    I believe what's happening is exceptions that get caught and thrown away before the 1s releaseObject timer runs result in this lovely inspector error
    Image

  18. getsantry
    added
    Waiting for: Product Owner
    on Sep 29, 2024
  19. getsantry
    moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Sep 29, 2024
  20. chargome
    removed
    Waiting for: Product Owner
    on Sep 30, 2024
  21. getsantry
    moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Sep 30, 2024
  22. ganjianwei commented on Oct 2, 2024

    @ganjianwei
    ganjianwei
    on Oct 2, 2024
    Author
    More actions

    hey sentry folks, let us know if you have a timeline / if it's fixable, especially the interceptor issue. Or if there's any workarounds we should try on our side. thanks again for looking into this!

  23. getsantry
    added
    Waiting for: Product Owner
    on Oct 2, 2024
  24. getsantry
    moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Oct 2, 2024
  25. chargome commented on Oct 2, 2024

    @chargome
    chargome
    on Oct 2, 2024
    Member
    More actions

    @ganjianwei you can watch #13827

    Reacted by Wei
  26. getsantry
    removed
    Waiting for: Product Owner
    on Oct 2, 2024
  27. getsantry
    moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Oct 2, 2024
  28. AbhiPrasad commented on Nov 1, 2024

    @AbhiPrasad
    AbhiPrasad
    on Nov 1, 2024
    Contributor
    More actions

    We've merged and released #13827 + have expanded our docs to indicate places where local variables might not work as expected (usually when using esm setups).

    Please upgrade your SDK to the latest version and try again.

    Going to close this for now as such. Please re-open if this is still a problem. Thanks!

  29. AbhiPrasad
    closed this as completedon Nov 1, 2024
  30. ghost added
    Bug
    on Aug 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @timfish
    timfish

Labels

Bug

Projects

  • GitHub Issues with 👀 3
    Status
    No status
    Show more project fields

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.