getsentry / sentry-javascript

Official Sentry SDKs for JavaScript
https://sentry.io
MIT License
7.98k stars 1.57k forks source link

Transport disabled error when flushing custom metrics #12630

Closed tolivturnstile closed 4 months ago

tolivturnstile commented 4 months ago

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.11.0

Framework Version

Node v20.9.0

Link to Sentry event

n/a

SDK Setup

import * as Sentry from "@sentry/node";
Sentry.init({
  dsn: MY_DSN, // Not pasting in here, but it is correct
  debug: true,
});

Steps to Reproduce

I am running a one-off TS script in which I want to manually report some custom metrics to Sentry.

  1. Increment some metric counters, i.e.
  Sentry.metrics.increment("flaky_test", 1, {
    tags: { name: testName, env, testFileName },
  });
  1. Explicitly flush metrics
await Sentry.flush(2000);
  1. Close Sentry connection
Sentry.close(3000);

Expected Result

I should see metrics in Sentry and no error logs

Actual Result

When executed locally, I see some "correct" logs, but always an error log at the end which I believe is indicative of the root cause. Here are my debug logs

Sentry Logger [log]: Initializing Sentry: process: 59009, thread: main.
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]: 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 [debug]: @opentelemetry/instrumentation-http Applying instrumentation patch for nodejs core module on require hook { module: 'http' }
Sentry Logger [debug]: @opentelemetry/instrumentation-http Applying instrumentation patch for nodejs core module on require hook { module: 'https' }
Sentry Logger [log]: Adding value of 1 to c metric successful_test
Sentry Logger [log]: Adding value of 1 to c metric successful_test
Sentry Logger [log]: Adding value of 1 to c metric successful_test
Sentry Logger [log]: Adding value of 1 to c metric timed_out_test
Sentry Logger [log]: Adding value of 1 to c metric successful_test
Sentry Logger [log]: Adding value of 1 to c metric successful_test
Sentry Logger [log]: Adding value of 1 to c metric timed_out_test
Sentry Logger [log]: Adding value of 1 to c metric successful_test
Sentry Logger [log]: Adding value of 1 to c metric successful_test
Sentry Logger [log]: Adding value of 1 to c metric successful_test
Sentry Logger [log]: Adding value of 1 to c metric successful_test
Sentry Logger [log]: Adding value of 1 to c metric successful_test
Sentry Logger [log]: Adding value of 1 to c metric successful_test
Sentry Logger [log]: Adding value of 1 to c metric successful_test
Sentry Logger [log]: Adding value of 1 to c metric successful_test
Sentry Logger [log]: Adding value of 1 to c metric successful_test
Sentry Logger [log]: Adding value of 1 to c metric successful_test
Sentry Logger [log]: Adding value of 1 to c metric successful_test
Sentry Logger [log]: Adding value of 1 to c metric successful_test
Sentry Logger [log]: Adding value of 1 to c metric successful_test
Sentry Logger [log]: Adding value of 1 to c metric successful_test
Sentry Logger [log]: Adding value of 1 to c metric successful_test
Sentry Logger [log]: Adding value of 1 to c metric successful_test
Sentry Logger [log]: Adding value of 1 to c metric successful_test
Sentry Logger [log]: Adding value of 1 to c metric successful_test
Sentry Logger [log]: Adding value of 1 to c metric successful_test
Sentry Logger [log]: Adding value of 1 to c metric successful_test
Sentry Logger [log]: Adding value of 1 to c metric successful_test
Sentry Logger [log]: Adding value of 1 to c metric successful_test
Sentry Logger [log]: Adding value of 1 to c metric successful_test
Sentry Logger [log]: Adding value of 1 to c metric successful_test
Sentry Logger [log]: Adding value of 1 to c metric successful_test
Sentry Logger [log]: Adding value of 1 to c metric successful_test
Sentry Logger [log]: Adding value of 1 to c metric successful_test
Sentry Logger [log]: Adding value of 1 to c metric successful_test
Sentry Logger [log]: Adding value of 1 to c metric successful_test
Sentry Logger [log]: Adding value of 1 to c metric successful_test
Sentry Logger [log]: Adding value of 1 to c metric successful_test
Sentry Logger [log]: Adding value of 1 to c metric successful_test
Sentry Logger [log]: Adding value of 1 to c metric successful_test
Sentry Logger [log]: Adding value of 1 to c metric successful_test
Sentry Logger [log]: Adding value of 1 to c metric successful_test
Sentry Logger [log]: Adding value of 1 to c metric successful_test
Sentry Logger [log]: Adding value of 1 to c metric successful_test
Sentry Logger [log]: Adding value of 1 to c metric successful_test
Sentry Logger [log]: Adding value of 1 to c metric successful_test
Sentry Logger [log]: Adding value of 1 to c metric successful_test
Sentry Logger [log]: Adding value of 1 to c metric successful_test
Sentry Logger [log]: Adding value of 1 to c metric successful_test
Sentry Logger [log]: Adding value of 1 to c metric timed_out_test
Sentry Logger [log]: Adding value of 1 to c metric successful_test
Sentry Logger [log]: Adding value of 1 to c metric successful_test
Sentry Logger [log]: Adding value of 1 to c metric successful_test
Sentry Logger [log]: Adding value of 1 to c metric successful_test
Sentry Logger [log]: Adding value of 1 to c metric successful_test
Sentry Logger [log]: Adding value of 1 to c metric timed_out_test
Sentry Logger [log]: Adding value of 1 to c metric successful_test
Sentry Logger [log]: Adding value of 1 to c metric failed_test
Sentry Logger [log]: Adding value of 1 to c metric successful_test
Sentry Logger [log]: Adding value of 1 to c metric successful_test
Sentry Logger [log]: Adding value of 1 to c metric successful_test
Sentry Logger [log]: Adding value of 1 to c metric successful_test
Sentry Logger [log]: Flushing aggregated metrics, number of metrics: 59
Sentry Logger [error]: Transport disabled

Any idea what could be causing this Transport disabled issue ? I'm not behind a VPN, and not seeing any similar issues nor documentation for similar issues. Apologies in advance if I've missed a configuration or something here!

Thanks!

AbhiPrasad commented 4 months ago

You don't need to call Sentry.close, having the Sentry.flush call should be good enough that everything gets flushed.

tolivturnstile commented 4 months ago

You don't need to call Sentry.close, having the Sentry.flush call should be good enough that everything gets flushed.

@AbhiPrasad Removed the .close and seems the issue has gone away. Thanks for the quick help!