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 7 commits into
base: develop
Choose a base branch
from
Open

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

wants to merge 7 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__',
  // ...
});

// 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: sentryClient ? new SentrySampler(sentryClient) : undefined,
  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());

Sentry.validateOpenTelemetrySetup();

Copy link
Contributor

github-actions bot commented Jun 26, 2025

size-limit report 📦

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% -189 B 🔽
@sentry/node - without tracing 98.78 kB +0.16% +150 B 🔺
@sentry/aws-serverless 124.6 kB +0.17% +201 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 4 times, most recently from dfab0e0 to 3d127cf Compare July 2, 2025 21:23
@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.

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.

1 participant