Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better document how to gracefully shutdown on SIGTERM #13448

Closed
3 tasks done
danilofuchs opened this issue Aug 22, 2024 · 2 comments
Closed
3 tasks done

Better document how to gracefully shutdown on SIGTERM #13448

danilofuchs opened this issue Aug 22, 2024 · 2 comments
Labels
Package: browser Issues related to the Sentry Browser SDK

Comments

@danilofuchs
Copy link

danilofuchs commented Aug 22, 2024

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/browser

SDK Version

8.26.0

Framework Version

No response

Link to Sentry event

No response

Reproduction Example/SDK Setup

import {
  getNodeAutoInstrumentations,
  getResourceDetectors,
} from "@opentelemetry/auto-instrumentations-node";
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-proto";
import * as opentelemetry from "@opentelemetry/sdk-node";
import * as Sentry from "@sentry/node";
import { SentryPropagator, SentrySpanProcessor } from "@sentry/opentelemetry";
import { nodeProfilingIntegration } from "@sentry/profiling-node";

const sdk = new opentelemetry.NodeSDK({
  instrumentations: getNodeAutoInstrumentations(),
  resourceDetectors: getResourceDetectors(),
  spanProcessors: [
    new SentrySpanProcessor(), // Export spans to Sentry
    new opentelemetry.tracing.BatchSpanProcessor(new OTLPTraceExporter()), // Export spans to CloudWatch OLTP sidecar
  ],
  // This conflicts with Sentry's sampling.
  // If we want to enable Sentry tracing, we must
  // use SentrySampler instead of AlwaysOnSampler
  sampler: new opentelemetry.tracing.AlwaysOnSampler(),
  textMapPropagator: new SentryPropagator(),
  contextManager: new Sentry.SentryContextManager(),
});

Sentry.init({
  dsn: "https://dsn",

  // Set tracesSampleRate to 1.0 to capture 100%
  // of transactions for performance monitoring.
  // We recommend adjusting this value in production
  tracesSampleRate: 0,
  profilesSampleRate: 1, // Relative to tracesSampleRate

  environment: process.env.NODE_ENV,
  enabled: process.env.NODE_ENV === "prod",

  integrations: [nodeProfilingIntegration(), Sentry.prismaIntegration()],

  skipOpenTelemetrySetup: true,

  registerEsmLoaderHooks: { exclude: [/openai/] },
});

Sentry.validateOpenTelemetrySetup();

sdk.start();

process.on("SIGTERM", () => {
  sdk
    .shutdown()
    .then(() => console.log("OpenTelemetry SDK terminated"))
    .catch((error) =>
      console.error("Error terminating OpenTelemetry SDK", error),
    );
});

Steps to Reproduce

We are configuring Sentry + OpenTelemetry manually in an ECS container

Our containers were failing to shutdown gracefully on SIGTERM

Expected Result

Document that we should handle shutting down Sentry on SIGTERM, or add a listener in Sentry itself

Something like this solves:

process.on("SIGTERM", () => {
  Sentry.close().then(() => console.log("Sentry stopped"));

  sdk
    .shutdown()
    .then(() => console.log("OpenTelemetry SDK terminated"))
    .catch((error) =>
      console.error("Error terminating OpenTelemetry SDK", error),
    );
});

Actual Result

Application does not exit on SIGTERM, debugging this issue is hard

@github-actions github-actions bot added the Package: browser Issues related to the Sentry Browser SDK label Aug 22, 2024
@andreiborza
Copy link
Member

Hello, thanks for writing in. We are on company-wide hackweek and thus on limited support this week. We'll take a look at this next week.

@chargome
Copy link
Member

@danilofuchs thanks for pointing that out, I have added a note on our node docs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: browser Issues related to the Sentry Browser SDK
Projects
Archived in project
Development

No branches or pull requests

3 participants