Skip to content

Fastify showing instrumentation warning even when instrumented #12247

@AlexDochioiu

Description

@AlexDochioiu

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/node

SDK Version

8.4.0

Framework Version

No response

Link to Sentry event

No response

SDK Setup

import * as Sentry from "@sentry/node";
import { hostname } from "os";
if (config.sentryEnv !== "disabled") {
  Sentry.init({
    dsn: config.sentryDsn,
    environment: config.sentryEnv,
    release: process.env.npm_package_version,
    serverName: hostname(),
    sampleRate: 1.0,
    // tracesSampleRate: 1.0,
    tracesSampler(samplingContext) {
      if (samplingContext.parentSampled === true) {
        return 1.0;
      }

      // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
      const url = samplingContext.attributes?.["http.target"] ?? samplingContext.attributes?.["http.url"] ?? "";
      if (!_.isString(url)) {
        console.warn("tracesSampler", "url is not a string", url);
        return config.sentrySampleRate;
      }
      console.log("tracesSampler", url);
      if (_.some(["/v4/images", "/v4/asset/image"], (path) => url.includes(path))) {
        console.log("tracesSampler", url, "0.0001");
        return 0.0001; // 0.01% of traces
      }
      if (_.some(["/wallet/txsubmit", "/wallet/txssubmit", "/wallet/swap/review"], (path) => url.includes(path))) {
        console.log("tracesSampler", url, "1.0");
        return 1.0; // 100% of traces
      }
      if (_.some(["/wallet/detailed"], (path) => url.includes(path))) {
        console.log("tracesSampler", url, "0.5");
        return 0.5; // 50% of traces
      }
      console.log("tracesSampler", url, config.sentrySampleRate);
      return config.sentrySampleRate;
    },
    beforeSend(event, hint) {
      // if (hint?.originalException instanceof Error) {
      //   recordSentryError(hint.originalException);
      // }
      hint;
      return event;
    },
    beforeSendTransaction(event, hint) {
      hint;
      console.log(event.request);

      return event;
    },
  });
}

Steps to Reproduce

Run the app. I tried to setup instrumentation:

Both options load the instrumentation fine (and well before fastify)

Expected Result

Instrumentation should work as expected and no warning should be given.

Actual Result

I think the instrumentation works as expected (possibly)? But I still get the following message:

console message:

[Sentry] fastify is not instrumented. Please make sure to initialize Sentry in a separate file that you `--import` when running node, see: 
https://docs.sentry.io/platforms/javascript/guides/fastify/install/esm/.

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status

    Waiting for: Community

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions