@extn/segi-nextjs
v0.2.12
Published
Next.js integration for the segi error monitoring service
Readme
@extn/segi-nextjs
Install
pnpm add @extn/segi-nextjsClient setup
In app/segi-init.tsx (a client component):
"use client";
import { initSegiBrowser } from "@extn/segi-nextjs/client";
initSegiBrowser({
projectKey: process.env.NEXT_PUBLIC_SEGI_PROJECT_KEY!,
environment: process.env.NODE_ENV,
release: process.env.NEXT_PUBLIC_APP_VERSION,
});
export default function SegiInit() {
return null;
}Mount once in your root layout.tsx:
import SegiInit from "./segi-init";
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html><body><SegiInit />{children}</body></html>
);
}The component setup works with Next.js 13+. Place instrumentation.ts
beside app/ (src/instrumentation.ts when using src/app/). Next.js 13/14
requires experimental: { instrumentationHook: true } merged into the
existing next.config; Next.js 15+ does not need that flag.
Next.js 15.3+ optionally supports browser initialization in
instrumentation-client.ts beside app/ instead of the component. Choose
one browser initializer. For Next.js 13–15.2, use the component above.
initSegiNext handles unhandled Node.js errors. Next.js can handle route and
server-action errors itself; use await captureException(error) explicitly
for those. Do not assume throwing in a route tests ingestion.
Server setup
In instrumentation.ts:
export async function register() {
if (process.env.NEXT_RUNTIME === "nodejs") {
const { initSegiNext } = await import("@extn/segi-nextjs");
initSegiNext({
projectKey: process.env.SEGI_PROJECT_KEY!,
environment: process.env.NODE_ENV,
});
}
}Anywhere on the server, the same package re-exports captureException and
captureMessage for explicit reporting:
import { captureException } from "@extn/segi-nextjs";
try {
// …
} catch (err) {
captureException(err);
throw err;
}Session recording
Use <SegiReplayProvider> once in your root layout for browser errors and DOM replay. Replace the error-only SegiInit above (and any initSegiBrowser/Segi.init in instrumentation-client.ts). The first browser init wins; adding the provider after an error-only initializer does not enable replay. Keep server instrumentation. The provider tracks App Router navigation and loads rrweb dynamically.
// app/layout.tsx
import { SegiReplayProvider } from "@extn/segi-nextjs/replay";
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html><body>
<SegiReplayProvider
publicKey={process.env.NEXT_PUBLIC_SEGI_PROJECT_KEY!}
environment={process.env.NODE_ENV}
release={process.env.NEXT_PUBLIC_APP_VERSION}
sample={100}
mask={{ inputs: "all", class: "segi-mask" }}
/>
{children}
</body></html>
);
}An OWNER or ADMIN must enable recording in Project → Settings → Recording.
Optional user={{ id: String(user.id) }} attributes errors and recordings;
pass null on logout. blockRoutes excludes SDK path prefixes; the console deny-list additionally requires segi-js 0.2.16 / segi-nextjs 0.2.11 and the updated server. Default input masking
is all; sensitive masks password/email/tel/number, none only passwords.
Use segi-mask on sensitive DOM regions.
Quotas: Free 30 / Team 100 / Enterprise unlimited per organization/month (KST).
Interact for at least 30 seconds, check successful /api/trace/replay uploads,
and open Project → Recordings to play the session.
Recording option reference
| Option | Default / behavior | | --- | --- | | enabled | withReplay only; true by default. false skips replay activation, not errors. Project recording must also be enabled by OWNER/ADMIN. | | sample | 100; probability from 0 to 100 percent. 20 selects approximately 20%. Initialization rolls again, including reloads; this is not error sampling. | | blockRoutes | Empty array; pathname prefix match. /auth also matches /author. Configure before sensitive routes. | | mask.inputs | all by default; sensitive masks password/email/tel/number; none still masks passwords. | | mask.class | segi-mask; blocks the matching DOM region and descendants. | | user | Next.js provider: { id, email? }; null clears identity; undefined leaves manual Segi.setUser management unchanged. |
SegiReplayProvider does not expose beforeSend/maxBreadcrumbs props. Use a single Segi.init with withReplay if you need these browser options and replay. SegiReplayProvider applies configuration at initial mount. Changes to user are synchronized, but changing other props does not reinitialize the SDK.
// Add these options to the existing withReplay call, not another initializer.
replay: withReplay({ sample: 20, blockRoutes: ["/auth", "/account/payment"],
mask: { inputs: "all", class: "segi-mask" } })
Segi.replay.pause();
Segi.replay.resume();
Segi.replay.event("checkout_started", { itemCount: 2 });
Segi.replay.notifyRouteChange(); // after non-Next.js SPA navigationpause/resume control DOM recording, not all error capture, and do not delete previously collected data. Use blockRoutes for persistent route exclusions. Custom event names are limited to 64 characters; meta must not contain passwords or payment details. Events send only while replay is active and unpaused. The Next.js provider reports pathname changes automatically. Other SPAs must notify the SDK after the URL changes for page tracking and exclusions. Starting on a blocked route defers replay. After rendering an allowed SPA page, notifyRouteChange starts it. Manual pause persists across navigation.
<SegiReplayProvider publicKey={process.env.NEXT_PUBLIC_SEGI_PROJECT_KEY!}
user={user ? { id: String(user.id) } : null} />Server option support
Server initialization uses projectKey, environment and release. The shared option type also includes beforeSend and maxBreadcrumbs, but the current server implementation does not process them. Filter/sanitize data before capture calls. The second argument to captureException/captureMessage is stored as extra; it does not override level or user. captureMessage uses info. setUser, setTag and addBreadcrumb belong to the browser SDK.
Docs
Licence
Copyright (c) 2026 Extension Co., Ltd. All rights reserved. Use of this package is governed by the LICENSE file in this package and the segi service Terms of Service at https://segi.extn.ai/tnc — it is not open source.
Console exclusion policy compatibility
The source versions introducing console path exclusions are segi-js 0.2.16 and segi-nextjs 0.2.11; this does not certify npm publication. Deploy the updated server before upgrading the SDK. The SDK reads policy before collection, retries failures every 30 seconds, and records nothing until a valid response arrives. Error monitoring is independent.
Console paths and SDK blockRoutes are combined. Policy changes take effect on the next full page load, not immediately in open tabs. Prefix matching is case-sensitive: /auth also matches /author. Saved data is not deleted. On SPA navigation, change the URL before rendering excluded DOM; after rendering an allowed page call notifyRouteChange (automatic in the Next.js Provider). For routers rendering sensitive content before updating the URL, pause before transition or mask the content. Saving settings does not confirm SDK adoption.
