feat: add Next.js support#27
Merged
Merged
Conversation
sohil-kshirsagar
approved these changes
Oct 14, 2025
sohil-kshirsagar
left a comment
Contributor
There was a problem hiding this comment.
nice! do we ignore inbound next.js calls that are meant to fetch html/css pages?
|
|
||
| const filteredSpans = spans.filter((span) => { | ||
| // Filter out spans exported from Next.js internal telemetry | ||
| if (span.instrumentationLibrary?.name === "next.js") { |
Contributor
There was a problem hiding this comment.
are there other spans we'd want to ignore? wonder if this should be in a constant somewhere
Contributor
Author
There was a problem hiding this comment.
- we don't ignore next.js calls that are meant to fetch html/css, will add this in a follow up
- there are no other spans currently that we'd want to ignore. + if there were, we might identify them differently. will create a constant once we have a better idea of other types of spans we'd want to ignore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds Next.js support to Tusk Drift Node SDK.
Changes
1. Next.js Instrumentation (
/src/instrumentation/libraries/nextjs/)Key features:
require.cacheto handle early-loading race conditionsWhy needed: Next.js wraps the native Node.js HTTP server with its own abstractions, making HTTP-level instrumentation insufficient. Framework-level interception ensures we capture the complete Next.js request lifecycle with proper routing and middleware context.
2.
withTuskDriftConfiguration Wrapper (/src/nextjs/)New files:
withTuskDrift.ts- Main configuration wrapper functiontypes.ts- TypeScript interfaces for configuration optionsutils.ts- Helper functions for Next.js version detection and semver parsingKey features:
instrumentationHooksetting (only for Next.js < 15.0.0-rc.1)require-in-the-middle,jsonpath)Configuration options:
debug- Enable debug logging for configurationdisableInstrumentationHook- Disable automatic instrumentationHook (not recommended)suppressWarnings- Suppress all warningsWhy externals are needed: Webpack would otherwise bundle instrumentation packages, preventing
require-in-the-middlefrom intercepting module loads.3. Documentation (
/docs/)New file:
nextjs-initialization.md- Comprehensive Next.js setup guide with step-by-step instructionsUpdated file:
initialization.md- Added callout directing Next.js users to dedicated guideUsage Example
Note
Adds first-class Next.js support with framework-level instrumentation and a withTuskDrift config wrapper, plus docs and minor core/export updates.
nextjsinstrumentation interceptsnext/dist/server/base-serverrequests; captures req/res bodies; supports RECORD/REPLAY; patches already-loaded modules viarequire.cache.nextjs/withTuskDrift(exported from root) with options (debug,disableInstrumentationHook,suppressWarnings); auto-detects Next.js version to setexperimental.instrumentationHook; adjusts webpack externals.NextjsInstrumentationinTuskDrift.TdSpanExporter: filters out spans whereinstrumentationLibrary.name === "next.js"; adds guarded transform with error logging.nextexcluded fromTuskDriftInstrumentationModuleNames.docs/nextjs-initialization.mdwith step-by-step setup.docs/initialization.md: adds Next.js callout and minor ESM snippet tweaks.next(and related transient packages) to dev deps.Written by Cursor Bugbot for commit c540d71. This will update automatically on new commits. Configure here.