Skip to content

Conversation

timfish
Copy link
Collaborator

@timfish timfish commented Sep 10, 2025

This PR:

  • Adds @apm-js-collab/tracing-hooks as a dependency
  • Integrations can register instrumentations which causes the @apm-js-collab/tracing-hooks ESM hook and require patching to be initialised later
  • The @apm-js-collab/* dependencies only get included in a bundle when they are used by an integration
  • Adds a pinoIntegration that:
    • Is not enabled by default (see below)
    • Registers where it needs code injecting into the pino library
    • Hooks the tracing channel events, including the channel added to pino@9.10.0
    • Captures Sentry logs for pino logs
    • Captures in the correct tracing context because this is all sync!
    • Captures exception/message events for the configured eventLevels

Supported Node versions

We can't enable this integration by default because TracingChannel, injected by @apm-js-collab/code-transformer requires Node >= v19.9.0 or v18.19.0.

Copy link
Contributor

github-actions bot commented Sep 10, 2025

size-limit report 📦

Path Size % Change Change
@sentry/browser 24.23 kB - -
@sentry/browser - with treeshaking flags 22.74 kB - -
@sentry/browser (incl. Tracing) 40.34 kB - -
@sentry/browser (incl. Tracing, Replay) 78.72 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 68.38 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 83.39 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 95.59 kB - -
@sentry/browser (incl. Feedback) 40.95 kB - -
@sentry/browser (incl. sendFeedback) 28.88 kB - -
@sentry/browser (incl. FeedbackAsync) 33.8 kB - -
@sentry/react 25.94 kB - -
@sentry/react (incl. Tracing) 42.32 kB - -
@sentry/vue 28.72 kB - -
@sentry/vue (incl. Tracing) 42.14 kB - -
@sentry/svelte 24.25 kB - -
CDN Bundle 25.74 kB - -
CDN Bundle (incl. Tracing) 40.16 kB - -
CDN Bundle (incl. Tracing, Replay) 76.38 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 81.88 kB - -
CDN Bundle - uncompressed 75.23 kB - -
CDN Bundle (incl. Tracing) - uncompressed 118.89 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 234.01 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 246.78 kB - -
@sentry/nextjs (client) 44.34 kB - -
@sentry/sveltekit (client) 40.76 kB - -
@sentry/node-core 50.03 kB +0.15% +72 B 🔺
@sentry/node 152.24 kB +0.05% +73 B 🔺
@sentry/node - without tracing 91.94 kB +0.09% +80 B 🔺
@sentry/aws-serverless 105.39 kB +0.09% +88 B 🔺

View base workflow run

Copy link
Contributor

github-actions bot commented Sep 10, 2025

node-overhead report 🧳

Note: This is a synthetic benchmark with a minimal express app and does not necessarily reflect the real-world performance impact in an application.

Scenario Requests/s % of Baseline Prev. Requests/s Change %
GET Baseline 8,915 - 8,714 +2%
GET With Sentry 1,383 16% 1,412 -2%
GET With Sentry (error only) 6,069 68% 6,096 -0%
POST Baseline 1,208 - 1,205 +0%
POST With Sentry 508 42% 537 -5%
POST With Sentry (error only) 1,080 89% 1,042 +4%
MYSQL Baseline 3,329 - 3,297 +1%
MYSQL With Sentry 451 14% 437 +3%
MYSQL With Sentry (error only) 2,678 80% 2,709 -1%

View base workflow run

@timfish
Copy link
Collaborator Author

timfish commented Sep 10, 2025

@timfish
Copy link
Collaborator Author

timfish commented Sep 15, 2025

I think these both need to be merged and released before we can use the hooks in production:

@timfish timfish mentioned this pull request Sep 18, 2025
@timfish timfish marked this pull request as ready for review September 19, 2025 20:46
@timfish timfish requested a review from AbhiPrasad September 19, 2025 20:46
cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

Copy link
Member

@AbhiPrasad AbhiPrasad left a comment

Choose a reason for hiding this comment

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

Really happy with this. Once we lock down the options surface, we should be good to merge!


type PinoHookArgs = [MergeObject, string, number];

type Options = {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we want to expose an options API surface that looks like this?

interface PinoOptions {
  error: {
    /**
     * Levels that trigger capturing of events.
     *
     * @default ["error", "fatal"]
     */
    levels?: LogSeverityLevel[];
    /**
     * By default, Sentry will mark captured errors as handled.
     * Set this to `false` if you want to mark them as unhandled instead.
     *
     * @default true
     */
    handled?: boolean;
  };
  log: {
    /**
     * Levels that trigger capturing of logs. Logs are only captured if
     * `enableLogs` is enabled.
     *
     * @default ["trace", "debug", "info", "warn", "error", "fatal"]
     */
    levels?: LogSeverityLevel[];
  };
}

What do you think?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep, like this!

Copy link
Member

Choose a reason for hiding this comment

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

Also, I think we don't want the pino integration to capture errors by default, that should be opt-in (similar to how captureConsole works in the SDK)

@timfish
Copy link
Collaborator Author

timfish commented Sep 24, 2025

Just realised we probably also want an integration test for the latest Pino that includes the tracing channel!

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.

2 participants