supabase-community / sentry-integration-js

MIT License
11 stars 3 forks source link

Does not appear to work server-side/NextJS 14.2 #18

Open t1mmen opened 3 weeks ago

t1mmen commented 3 weeks ago

Bug report

sentry-integration-js loads in node/server-side environment, but does not appear to do anything (both in local dev & deployed to prod)

Describe the bug

To Reproduce

// instrumentation.ts
export async function register() {
  if (process.env.NEXT_RUNTIME === 'nodejs') {
    await import('../sentry.server.config');
  }
}
// sentry.server.config.ts
import * as Sentry from '@sentry/nextjs';
import { sentryDefaults } from '@/utils/sentry/sentry-config';
import { nodeProfilingIntegration } from '@sentry/profiling-node';
import { SupabaseClient } from '@supabase/supabase-js';
import { Payload, supabaseIntegration } from '@supabase/sentry-js-integration';

if (sentryDefaults.useSentry) {
  Sentry.init({
    ...sentryDefaults.config, // DNS, enabled: true, debug: true, etc..
    integrations: [
      nodeProfilingIntegration(),
      Sentry.zodErrorsIntegration(),
      supabaseIntegration(SupabaseClient, Sentry, {
        tracing: true,
        breadcrumbs: true,
        errors: true,
        shouldCreateSpan: (payload: Payload) => true,
        shouldCreateBreadcrumb: (payload: Payload) => true,
        sanitizeBody: (table: string, key: string, value: unknown) => {
          if (table === 'memories' && key === 'title') {
            return '***';
          }
          return value;
        },
      }),
      Sentry.requestDataIntegration({
        include: {
          // Don't log request body (in prod).
          // IF disabling this, you MUST re-visit sentry-pii-scrubber.node.ts as it doesn't work as expected.
          data: sentryDefaults.restrictSentry ? false : true,
        },
      }),
    ],
  });
}

CleanShot 2024-10-23 at 12 42 21

Expected behavior

System information

"@sentry/nextjs": "^8.35.0",
"next": "^14.2.15",
"@supabase/sentry-js-integration": "^0.3.0",
"@supabase/auth-helpers-nextjs": "^0.10.0",
"@supabase/auth-helpers-react": "^0.5.0",
"@supabase/supabase-js": "^2.45.4",

Running Node 20.x

(I've attempted upgrading to @supabase/ssr, but ran issues with JWT format changing to include Base64 prefix, which broke our hand-rolled JWT's, so put that aside. Presumably not related to this issue, but mentioning for completeness)

Additional context

I have tried initializing Supabase client in sentry.server.config.ts with identical parameters to how it's initialized/used in API handlers, but that didn't change anything.

Local dev logs:

  ▲ Next.js 14.2.15
  - Local:        http://localhost:3001
  - Environments: .env
  - Experiments (use with caution):
    · instrumentationHook

 ✓ Starting...
 ○ Compiling /instrumentation ...
 ✓ Compiled /instrumentation in 1140ms (1066 modules)
Sentry Logger [log]: Initializing SDK...
Sentry Logger [log]: Initializing Sentry: process: 73477, thread: main.
Sentry Logger [warn]: No DSN provided, client will not send events.
Sentry Logger [log]: Integration installed: InboundFilters
Sentry Logger [log]: Integration installed: FunctionToString
Sentry Logger [log]: Integration installed: LinkedErrors
Sentry Logger [log]: Integration installed: RequestData
Sentry Logger [log]: Integration installed: Console
Sentry Logger [log]: Integration installed: Http
Sentry Logger [log]: Integration installed: NodeFetch
Sentry Logger [log]: Integration installed: OnUncaughtException
Sentry Logger [log]: Integration installed: OnUnhandledRejection
Sentry Logger [log]: Integration installed: ContextLines
Sentry Logger [log]: Integration installed: LocalVariablesAsync
Sentry Logger [log]: Integration installed: Context
Sentry Logger [log]: Integration installed: Modules
Sentry Logger [log]: Integration installed: Express
Sentry Logger [log]: Integration installed: Fastify
Sentry Logger [log]: Integration installed: Graphql
Sentry Logger [log]: Integration installed: Mongo
Sentry Logger [log]: Integration installed: Mongoose
Sentry Logger [log]: Integration installed: Mysql
Sentry Logger [log]: Integration installed: Mysql2
Sentry Logger [log]: Integration installed: Redis
Sentry Logger [log]: Integration installed: Postgres
Sentry Logger [log]: Integration installed: Nest
Sentry Logger [log]: Integration installed: Hapi
Sentry Logger [log]: Integration installed: Koa
Sentry Logger [log]: Integration installed: Connect
Sentry Logger [log]: Integration installed: GenericPool
Sentry Logger [log]: Integration installed: Kafka
Sentry Logger [log]: Integration installed: Amqplib
Sentry Logger [log]: Integration installed: LruMemoizer
Sentry Logger [log]: Integration installed: DistDirRewriteFrames
Sentry Logger [log]: [Profiling] Profiling integration setup.
Sentry Logger [log]: [Profiling] Span profiler mode enabled.
Sentry Logger [log]: Integration installed: ProfilingIntegration
Sentry Logger [log]: Integration installed: ZodErrors
Sentry Logger [log]: Integration installed: SupabaseIntegration # <----------
Sentry Logger [log]: Integration installed: Spotlight
Sentry Logger [log]: Running in CommonJS mode.
Sentry Logger [debug]: @opentelemetry/api: Registered a global for diag v1.9.0.
Sentry Logger [debug]: @opentelemetry/api: Registered a global for trace v1.9.0.
Sentry Logger [debug]: @opentelemetry/api: Registered a global for context v1.9.0.
Sentry Logger [debug]: @opentelemetry/api: Registered a global for propagation v1.9.0.
Sentry Logger [log]: SDK successfully initialized
 ✓ Ready in 2.7s
Sentry Logger [log]: [Tracing] Starting sampled root span
  op: < unknown op >
  name: GET /api/1.0/users/me?accountId=123
  ID: 2a48f3bebc6e347c
Sentry Logger [log]: [Profiling] started profiling transaction: GET /api/1.0/users/me?accountId=123
 ○ Compiling /api/[...ts-rest] ...
 ✓ Compiled /api/[...ts-rest] in 1368ms (1945 modules)
Sentry Logger [debug]: @opentelemetry_sentry-patched/instrumentation-http Applying instrumentation patch for nodejs core module on require hook { module: 'http' }
Sentry Logger [debug]: @sentry/instrumentation-http Applying instrumentation patch for nodejs core module on require hook { module: 'http' }
Sentry Logger [debug]: @opentelemetry_sentry-patched/instrumentation-http Applying instrumentation patch for nodejs core module on require hook { module: 'https' }
Sentry Logger [debug]: @sentry/instrumentation-http Applying instrumentation patch for nodejs core module on require hook { module: 'https' }
Sentry Logger [log]: [Tracing] Inheriting parent's sampled decision for executing api route (pages) /api/[...ts-rest]: true
Sentry Logger [log]: [Tracing] Starting sampled span
  op: < unknown op >
  name: executing api route (pages) /api/[...ts-rest]
  ID: 598d7e0ae3755e20
  parent ID: 2a48f3bebc6e347c
  root ID: 2a48f3bebc6e347c
  root description: next server handler
Sentry Logger [info]: Starting a new trace with id f828b89e9fea4d0ca018badeab1652df
Sentry Logger [log]: [Tracing] Inheriting remote parent's sampled decision for GET /api/[..-rest].ts: undefined
Sentry Logger [log]: [Tracing] Starting sampled root span
  op: http.server
  name: GET /api/[..-rest].ts
  ID: 0055732cc36c156c
  parent ID: 9f4236f96913e1c9
Sentry Logger [log]: [Profiling] started profiling transaction: GET /api/[..-rest].ts
Sentry Logger [log]: [Tracing] Inheriting parent's sampled decision for GET: true
Sentry Logger [log]: [Tracing] Starting sampled span
  op: < unknown op >
  name: GET
  ID: 1709b7f9865006d5
  parent ID: 0055732cc36c156c
  root ID: 0055732cc36c156c
  root op: http.server
  root description: GET /api/1.0/users/me
Sentry Logger [log]: [Tracing] Finishing "< unknown op >" span "GET" with ID 1709b7f9865006d5
Sentry Logger [log]: SpanExporter has 1 unsent spans remaining
Sentry Logger [log]: [Tracing] Finishing "http.server" root span "GET /api/1.0/users/me" with ID 0055732cc36c156c
Sentry Logger [log]: [Profiling] stopped profiling of transaction: GET /api/1.0/users/me
Sentry Logger [log]: Flushing events...
Sentry Logger [log]: SpanExporter exported 2 spans, 0 unsent spans remaining
Sentry Logger [log]: Flushing outcomes...
Sentry Logger [log]: No outcomes to send
Sentry Logger [log]: Done flushing events
Sentry Logger [log]: [Tracing] Finishing "< unknown op >" span "executing api route (pages) /api/[...ts-rest]" with ID 598d7e0ae3755e20
Sentry Logger [log]: SpanExporter has 1 unsent spans remaining
Sentry Logger [log]: [Tracing] Finishing "< unknown op >" root span "GET /api/[...ts-rest]" with ID 2a48f3bebc6e347c
Sentry Logger [log]: [Profiling] stopped profiling of transaction: GET /api/[...ts-rest]
 GET /api/1.0/users/me?accountId=123 200 in 2230ms
Sentry Logger [log]: SpanExporter exported 2 spans, 0 unsent spans remaining
Sentry Logger [log]: Event processor "NextLowQualityTransactionsFilter" dropped event
Sentry Logger [log]: Recording outcome: "event_processor:transaction"
Sentry Logger [log]: An event processor returned `null`, will not send event.
Sentry Logger [debug]: @sentry/instrumentation-http http instrumentation for outgoing requests
Sentry Logger [log]: [Tracing] Inheriting parent's sampled decision for POST: true
Sentry Logger [log]: [Tracing] Starting sampled span
  op: < unknown op >
  name: POST
  ID: 72544dbffed9dd4e
  parent ID: 0055732cc36c156c
  root ID: 0055732cc36c156c
  root op: http.server
  root description: GET /api/1.0/users/me
Sentry Logger [debug]: @opentelemetry_sentry-patched/instrumentation-http http instrumentation outgoingRequest
Sentry Logger [debug]: @opentelemetry_sentry-patched/instrumentation-http http.ClientRequest return request
Sentry Logger [error]: Transport disabled
Sentry Logger [debug]: @opentelemetry_sentry-patched/instrumentation-http outgoingRequest on response()
Sentry Logger [debug]: @opentelemetry_sentry-patched/instrumentation-http outgoingRequest on end()
Sentry Logger [log]: [Tracing] Finishing "< unknown op >" span "POST" with ID 72544dbffed9dd4e
Sentry Logger [log]: SpanExporter has 1 unsent spans remaining
Sentry Logger [debug]: @opentelemetry_sentry-patched/instrumentation-http outgoingRequest on request close()
sbushell92 commented 4 days ago

Also have the same problem running Next.js 14.2.17

jdarnok commented 1 day ago

issue still exists

kamilogorek commented 1 day ago

It does, as I had no time to take a look at it yet. There's a reason why this package lives under supabase-community org. Contributions are always welcome :)

jdarnok commented 19 hours ago

@kamilogorek Sorry, you are right - I was in the rush (researching monitoring solutions for new app) just came in straight from the supabase doc and I missed the community prefix 🤦 Sorry for my pretensional comment, you are doing a great job!

To add any value to it, it's also not working on 14.2.4, so I assume it's just whole 14.2 release for the server config.

kamilogorek commented 18 hours ago

No worries. It's just futile to chase every Next.js and Sentry SDK version all the time and make sure that they won't break on any random release.