APM Manual transactions with @sentry/node

I’m trying to test out manual transactions using @sentry/node following the examples here: https://docs.sentry.io/performance/distributed-tracing/#setting-up-tracing

I can’t seem to get it to work though.

I’m initializing Sentry like this:

import * as Sentry from '@sentry/node'
// We need to import @sentry/apm for it to work, but don't actually need to use it anywhere
// @ts-ignore
import * as APM from '@sentry/apm'


    dsn: sharedConfig.BAGEL_SENTRY_DSN,
    environment: sharedConfig.BAGEL_RELEASE_ENV,
    release: sharedConfig.BAGEL_CLIENT_HASH,
    serverName: os.hostname(),
    debug: true,
    tracesSampleRate: 0.25

and my transaction code in a different file looks like this:

import * as Sentry from '@sentry/node'


  onQuery: async (req, ctx) => {
    const transaction = Sentry.startTransaction({
      op: req.type,
      name: (req.constructor as any).qkind
    const res = await graphql(schema, req.query, null, ctx, req.args)
    return res

But it doesn’t seem to be working at all. I get errors like this from the API code:

[APIServer] error:  {
  id: 1,
  errors: [
      message: TypeError: Cannot read property 'finish' of undefined
          at /Users/chris/bagel/src/backend/server.ts:60:17
          at Generator.next (<anonymous>)
          at fulfilled (/Users/chris/bagel/node_modules/tslib/tslib.js:104:62)
          at processTicksAndRejections (internal/process/task_queues.js:97:5)

so it looks like transaction is undefined when it should be defined. When I enabled debug logging for Sentry, I see logging like this:

Sentry Logger [Warn]: Extension method startTransaction couldn't be found, doing nothing.

Am I missing something? Is there another import line or something similar that I need to add in here?

I am using versions 5.17.0 of both @sentry/apm and @sentry/node.

Ugh! I figured it out. The @sentry/apm import was getting compiled out because it wasn’t being used. Closing this, not a Sentry bug.

1 Like