8000 feat(node-core): Add node-core SDK by andreiborza · Pull Request #16745 · getsentry/sentry-javascript · GitHub
[go: up one dir, main page]

Skip to content

feat(node-core): Add node-core SDK #16745

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

Open
wants to merge 12 commits into
base: develop
Choose a base branch
from
Open

feat(node-core): Add node-core SDK #16745

wants to merge 12 commits into from

Conversation

andreiborza
Copy link
Member
@andreiborza andreiborza commented Jun 26, 2025

This PR adds a new @sentry/node-core SDK and refactors @sentry/node to build on it. It provides the core functionality of the Node SDK with a few key differences

  • it ships without any OpenTelemetry core dependencies
  • it ships without any OpenTelemetry instrumentation (@opentelemetry/instrumentation-X)
  • it does not automatically set up OpenTelemetry
  • it widens the OpenTelemetry dependencies version ranges and marks them as peer dependencies, allowing setup with OpenTelemetry v1 and v2
  • preserves all existing @sentry/node APIs (minus the OpenTelemetry instrumentations)

When to Use Each

This SDK is not intended to be used by most users directly (similarly to @sentry/core). It provides core functionality and makes it possible to be used in setups where OpenTelemetry dependencies that do not match those we set up in the more opinionated @sentry/node SDK.

Use @sentry/node-core when:

  • You already have OpenTelemetry set up
  • You need custom OpenTelemetry configuration
  • You want minimal dependencies
  • You need fine-grained control over instrumentation

Use @sentry/node when:

  • You want automatic setup
  • You're new to OpenTelemetry
  • You want sensible defaults
  • You prefer convenience over control

Example setup

  1. Installation
npm install @sentry/node-core \
    @opentelemetry/api \
    @opentelemetry/context-async-hooks \
    @opentelemetry/core \
    @opentelemetry/instrumentation \
    @opentelemetry/resources \
    @opentelemetry/sdk-trace-base \
    @opentelemetry/semantic-conventions
  1. Setup
    Sentry should be initialized as early in your app as possible. It is essential that you call Sentry.init before you
    require any other modules in your application, otherwise any auto-instrumentation will not work.
    You also need to set up OpenTelemetry, if you prefer not to, consider using the @sentry/node SDK instead.

You need to create a file named instrument.js that imports and initializes Sentry:

// CJS Syntax
const { trace, propagation, context } = require('@opentelemetry/api');
const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node');
const Sentry = require('@sentry/node-core');
const { SentrySpanProcessor, SentryPropagator, SentrySampler } = require('@sentry/opentelemetry');
// ESM Syntax
import { context, propagation, trace } from '@opentelemetry/api';
import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node';
import * as Sentry from '@sentry/node-core';
import { SentrySpanProcessor, SentryPropagator, SentrySampler } from '@sentry/opentelemetry';

const sentryClient = Sentry.init({
  dsn: '__DSN__',
  // ...
});

if (sentryClient) {
  // Note: This could be BasicTracerProvider or any other provider depending on how you want to use the
  // OpenTelemetry SDK
  const provider = new NodeTracerProvider({
    // Ensure the correct subset of traces is sent to Sentry
    // This also ensures trace propagation works as expected
    sampler: new SentrySampler(sentryClient),
    spanProcessors: [
      // Ensure spans are correctly linked & sent to Sentry
      new SentrySpanProcessor(),
      // Add additional processors here
    ],
  });

  trace.setGlobalTracerProvider(provider);
  propagation.setGlobalPropagator(new SentryPropagator());
  context.setGlobalContextManager(new Sentry.SentryContextManager());
}

// Set up the OpenTelemetry logger to use Sentry's logger
Sentry.setupOpenTelemetryLogger();

// validate your setup
Sentry.validateOpenTelemetrySetup();

Copy link
Contributor
github-actions bot commented Jun 26, 2025

size-limit report 📦

8000
Path Size % Change Change
@sentry/browser 23.99 kB - -
@sentry/browser - with treeshaking flags 23.76 kB - -
@sentry/browser (incl. Tracing) 39.59 kB - -
@sentry/browser (incl. Tracing, Replay) 77.69 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 70.78 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 82.45 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 94.57 kB - -
@sentry/browser (incl. Feedback) 40.75 kB - -
@sentry/browser (incl. sendFeedback) 28.7 kB - -
@sentry/browser (incl. FeedbackAsync) 33.59 kB - -
@sentry/react 25.76 kB - -
@sentry/react (incl. Tracing) 41.58 kB - -
@sentry/vue 28.37 kB - -
@sentry/vue (incl. Tracing) 41.4 kB - -
@sentry/svelte 24.01 kB - -
CDN Bundle 25.5 kB - -
CDN Bundle (incl. Tracing) 39.6 kB - -
CDN Bundle (incl. Tracing, Replay) 75.5 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 80.96 kB - -
CDN Bundle - uncompressed 74.5 kB - -
CDN Bundle (incl. Tracing) - uncompressed 117.63 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 231.68 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 244.5 kB - -
@sentry/nextjs (client) 43.22 kB - -
@sentry/sveltekit (client) 40.04 kB - -
@sentry/node 161.84 kB -0.12% -180 B 🔽
@sentry/node - without tracing 98.8 kB +0.17% +160 B 🔺
@sentry/aws-serverless 124.62 kB +0.18% +223 B 🔺

View base workflow run

@andreiborza andreiborza force-pushed the ab/node-core branch 4 times, most recently from 610c5cc to 8b31e19 Compare June 27, 2025 13:34

This comment was marked as outdated.

@andreiborza andreiborza force-pushed the ab/node-core branch 5 times, most recently from 3d127cf to b97edd4 Compare July 2, 2025 21:32
@andreiborza andreiborza marked this pull request as ready for review July 2, 2025 21:59

setTimeout(() => {
process.exit();
}, 20000);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@timfish I had to increase the timeout here to get these to pass. Could you have a look why that might be?

I'm wondering if the OTel init outside of Sentry.init has something to do with this.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems unlikely this has anything to do with otel because the anr events are sent from another thread without the full SDK running. I wouldn't worry too much about this change!

@timfish
Copy link
Collaborator
timfish commented Jul 3, 2025

Can you use @sentry/node-core without any otel dependencies and if so, what features will not work?


## Usage

Sentry should be initialized as early in your app as possible. It is essential that you call `Sentry.init` before you
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we emphasize that OTEL setup is required? What happens if users don't set up OTEL?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the README. If users don't setup OTel they basically get only basic error logging, no scope isolation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

follow up: Maybe we can get to a place where we can have basic scope isolation for errors without otel 🤔 but that's a bigger topic 😅

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why isn't this file also just moved from @sentry/node?

Copy link
Member Author
@andreiborza andreiborza Jul 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The one in @sentry/node uses @opentelemetry/instrumentation-http, while the one in node-core does not.

];
const nodeCoreIntegrations = getNodeCoreDefaultIntegrations();

// Filter out the node-core HTTP and NodeFetch integrations and replace them with Node SDK's composite versions
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we'll have issues where people import node-core and use those integrations with the node sdk. Maybe we need a way to detect those scenarios?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be an issue, but most people won't use @sentry/node-core. Same as most people don't use @sentry/core. Not sure we need to guard against this at this point?

Do you have some specific approach in mind?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we already have a similar thing for e.g. browserTracingIntegration where many SDKs export a different implementation of this than the browser one 🤔 so I think this should be fine...?

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0