@launchdarkly/observability-next 0.0.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/README.md +152 -0
  3. package/client.d.ts +1 -0
  4. package/config.d.ts +1 -0
  5. package/dist/config.cjs +2 -0
  6. package/dist/config.cjs.map +1 -0
  7. package/dist/config.d.ts +2 -0
  8. package/dist/config.d.ts.map +1 -0
  9. package/dist/config.js +2 -0
  10. package/dist/config.js.map +1 -0
  11. package/dist/error-boundary-CSJNDDPj.js +2 -0
  12. package/dist/error-boundary-CSJNDDPj.js.map +1 -0
  13. package/dist/error-boundary-CUcyBTHj.js +2 -0
  14. package/dist/error-boundary-CUcyBTHj.js.map +1 -0
  15. package/dist/error-boundary.d.ts +15 -0
  16. package/dist/error-boundary.d.ts.map +1 -0
  17. package/dist/next-client.cjs +3 -0
  18. package/dist/next-client.cjs.map +1 -0
  19. package/dist/next-client.d.ts +13 -0
  20. package/dist/next-client.d.ts.map +1 -0
  21. package/dist/next-client.js +3 -0
  22. package/dist/next-client.js.map +1 -0
  23. package/dist/observability-middleware-CH0Vm0ev.js +2 -0
  24. package/dist/observability-middleware-CH0Vm0ev.js.map +1 -0
  25. package/dist/observability-middleware-D4dJiJoK.js +2 -0
  26. package/dist/observability-middleware-D4dJiJoK.js.map +1 -0
  27. package/dist/proxy-B6yiPOEG.js +2 -0
  28. package/dist/proxy-B6yiPOEG.js.map +1 -0
  29. package/dist/proxy-DccSYatN.js +2 -0
  30. package/dist/proxy-DccSYatN.js.map +1 -0
  31. package/dist/server.cjs +2 -0
  32. package/dist/server.cjs.map +1 -0
  33. package/dist/server.d.ts +17 -0
  34. package/dist/server.d.ts.map +1 -0
  35. package/dist/server.edge.cjs +2 -0
  36. package/dist/server.edge.cjs.map +1 -0
  37. package/dist/server.edge.d.ts +13 -0
  38. package/dist/server.edge.d.ts.map +1 -0
  39. package/dist/server.edge.js +2 -0
  40. package/dist/server.edge.js.map +1 -0
  41. package/dist/server.js +2 -0
  42. package/dist/server.js.map +1 -0
  43. package/dist/ssr.cjs +2 -0
  44. package/dist/ssr.cjs.map +1 -0
  45. package/dist/ssr.d.ts +28 -0
  46. package/dist/ssr.d.ts.map +1 -0
  47. package/dist/ssr.js +2 -0
  48. package/dist/ssr.js.map +1 -0
  49. package/dist/standalone-CQH9Vh11.js +2 -0
  50. package/dist/standalone-CQH9Vh11.js.map +1 -0
  51. package/dist/standalone-CkwD29IP.js +2 -0
  52. package/dist/standalone-CkwD29IP.js.map +1 -0
  53. package/dist/util/is-node-js-runtime.d.ts +2 -0
  54. package/dist/util/is-node-js-runtime.d.ts.map +1 -0
  55. package/dist/util/observability-middleware.d.ts +3 -0
  56. package/dist/util/observability-middleware.d.ts.map +1 -0
  57. package/dist/util/proxy.d.ts +5 -0
  58. package/dist/util/proxy.d.ts.map +1 -0
  59. package/dist/util/register-observability.d.ts +3 -0
  60. package/dist/util/register-observability.d.ts.map +1 -0
  61. package/dist/util/sanitize-url.d.ts +2 -0
  62. package/dist/util/sanitize-url.d.ts.map +1 -0
  63. package/dist/util/standalone.d.ts +19 -0
  64. package/dist/util/standalone.d.ts.map +1 -0
  65. package/dist/util/types.d.ts +5 -0
  66. package/dist/util/types.d.ts.map +1 -0
  67. package/dist/util/version.d.ts +3 -0
  68. package/dist/util/version.d.ts.map +1 -0
  69. package/dist/util/with-launchdarkly-config.d.ts +15 -0
  70. package/dist/util/with-launchdarkly-config.d.ts.map +1 -0
  71. package/dist/util/with-observability-app-router.d.ts +8 -0
  72. package/dist/util/with-observability-app-router.d.ts.map +1 -0
  73. package/dist/util/with-observability-page-router.d.ts +16 -0
  74. package/dist/util/with-observability-page-router.d.ts.map +1 -0
  75. package/package.json +93 -3
  76. package/server.d.ts +1 -0
  77. package/ssr.d.ts +1 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ # Changelog
2
+
3
+ ## [0.2.0](https://github.com/launchdarkly/observability-sdk/compare/observability-next-0.1.0...observability-next-0.2.0) (2026-06-18)
4
+
5
+
6
+ ### Features
7
+
8
+ * **@launchdarkly/session-replay-react-native:** use cocoapods for native session replay ([#434](https://github.com/launchdarkly/observability-sdk/issues/434)) ([41988e1](https://github.com/launchdarkly/observability-sdk/commit/41988e196b02901964efdad0e25f892d5ba55fc4))
9
+ * **observability-next:** add LaunchDarkly Next.js SDK ([#630](https://github.com/launchdarkly/observability-sdk/issues/630)) ([08cb95b](https://github.com/launchdarkly/observability-sdk/commit/08cb95b88cdd58351f5f2aaad87710836b177e2e))
package/README.md ADDED
@@ -0,0 +1,152 @@
1
+ # LaunchDarkly Observability SDK for Next.js
2
+
3
+ [![NPM][o11y-next-npm-badge]][o11y-next-npm-link]
4
+
5
+ **NB: APIs are subject to change until a 1.x version is released.**
6
+
7
+ LaunchDarkly observability and session replay for Next.js apps — frontend and
8
+ backend errors, logs, traces, metrics, and session replays.
9
+
10
+ ## Standalone mode
11
+
12
+ There is no LaunchDarkly feature-flag SDK for Next.js, so this package runs the
13
+ LaunchDarkly observability and session replay plugins in **standalone mode**:
14
+ they are initialized directly from your LaunchDarkly SDK key (client-side ID)
15
+ rather than being registered with a LaunchDarkly client. No feature-flag SDK is
16
+ required.
17
+
18
+ ## Install
19
+
20
+ ```shell
21
+ # npm
22
+ npm i @launchdarkly/observability-next
23
+
24
+ # yarn
25
+ yarn add @launchdarkly/observability-next
26
+ ```
27
+
28
+ ## Usage
29
+
30
+ ### 1. Client (App Router) — `app/layout.tsx`
31
+
32
+ ```tsx
33
+ import { LDObservabilityInit, ErrorBoundary } from '@launchdarkly/observability-next/client'
34
+
35
+ export default function RootLayout({ children }: { children: React.ReactNode }) {
36
+ return (
37
+ <ErrorBoundary>
38
+ <LDObservabilityInit
39
+ sdkKey={process.env.NEXT_PUBLIC_LAUNCHDARKLY_SDK_KEY}
40
+ serviceName="my-nextjs-frontend"
41
+ environment="production"
42
+ tracingOrigins
43
+ networkRecording={{ enabled: true, recordHeadersAndBody: true }}
44
+ />
45
+ <html lang="en">
46
+ <body>{children}</body>
47
+ </html>
48
+ </ErrorBoundary>
49
+ )
50
+ }
51
+ ```
52
+
53
+ For the Pages Router, render `<LDObservabilityInit />` in `pages/_app.tsx`.
54
+
55
+ ### 2. Server instrumentation — `instrumentation.ts`
56
+
57
+ ```ts
58
+ export async function register() {
59
+ const { registerObservability } = await import('@launchdarkly/observability-next/server')
60
+ await registerObservability({
61
+ sdkKey: process.env.LAUNCHDARKLY_SDK_KEY!,
62
+ serviceName: 'my-nextjs-backend',
63
+ environment: 'production',
64
+ })
65
+ }
66
+ ```
67
+
68
+ ### 3. Wrap route handlers
69
+
70
+ App Router:
71
+
72
+ ```ts
73
+ import { AppRouterObservability } from '@launchdarkly/observability-next/server'
74
+
75
+ const withObservability = AppRouterObservability({ sdkKey: process.env.LAUNCHDARKLY_SDK_KEY! })
76
+
77
+ export const GET = withObservability(async (request) => {
78
+ return Response.json({ ok: true })
79
+ })
80
+ ```
81
+
82
+ Pages Router:
83
+
84
+ ```ts
85
+ import { PageRouterObservability } from '@launchdarkly/observability-next/server'
86
+
87
+ export default PageRouterObservability({ sdkKey: process.env.LAUNCHDARKLY_SDK_KEY! })(
88
+ async (req, res) => {
89
+ res.status(200).send('ok')
90
+ },
91
+ )
92
+ ```
93
+
94
+ ### 4. Link backend traces to sessions — `middleware.ts`
95
+
96
+ ```ts
97
+ import { observabilityMiddleware } from '@launchdarkly/observability-next/server'
98
+
99
+ export async function middleware(request: Request) {
100
+ // Return the response so the forwarded x-highlight-request header reaches
101
+ // downstream route handlers.
102
+ return observabilityMiddleware(request)
103
+ }
104
+ ```
105
+
106
+ ### 5. (Optional) Proxy + config — `next.config.mjs`
107
+
108
+ ```js
109
+ import { withLaunchDarklyConfig } from '@launchdarkly/observability-next/config'
110
+
111
+ /** @type {import('next').NextConfig} */
112
+ const nextConfig = {}
113
+
114
+ export default withLaunchDarklyConfig(nextConfig)
115
+ ```
116
+
117
+ This sets up same-origin rewrites that proxy browser telemetry through your
118
+ domain to LaunchDarkly (enabled by default). Disable with
119
+ `{ configureLaunchDarklyProxy: false }`.
120
+
121
+ ### 6. (Optional) SSR error pages
122
+
123
+ ```tsx
124
+ // App Router: app/error.tsx
125
+ 'use client'
126
+ import { appRouterSsrErrorHandler } from '@launchdarkly/observability-next/ssr'
127
+
128
+ export default appRouterSsrErrorHandler(({ error, reset }) => (
129
+ <button onClick={reset}>Try again</button>
130
+ ))
131
+ ```
132
+
133
+ ```tsx
134
+ // Pages Router: pages/_error.tsx
135
+ import { pageRouterCustomErrorHandler } from '@launchdarkly/observability-next/ssr'
136
+
137
+ export default pageRouterCustomErrorHandler({
138
+ sdkKey: process.env.NEXT_PUBLIC_LAUNCHDARKLY_SDK_KEY,
139
+ })
140
+ ```
141
+
142
+ ## Manual recording
143
+
144
+ Use `LDObserve` / `LDRecord` directly:
145
+
146
+ ```ts
147
+ import { LDObserve } from '@launchdarkly/observability-next/server' // or /client
148
+ LDObserve.recordError(new Error('boom'))
149
+ ```
150
+
151
+ [o11y-next-npm-badge]: https://img.shields.io/npm/v/@launchdarkly/observability-next.svg?style=flat-square
152
+ [o11y-next-npm-link]: https://www.npmjs.com/package/@launchdarkly/observability-next
package/client.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './dist/next-client'
package/config.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './dist/config'
@@ -0,0 +1,2 @@
1
+ "use strict";var e=require("./proxy-B6yiPOEG.js");const r=["@launchdarkly/observability-node","@launchdarkly/node-server-sdk-otel","@prisma/instrumentation","require-in-the-middle","import-in-the-middle"],t=(t,n)=>{const a=(e=>({configureLaunchDarklyProxy:e?.configureLaunchDarklyProxy??!0}))(n);let i=t.rewrites;if(a.configureLaunchDarklyProxy){const r=[{source:e.PROXY_BACKEND_PATH,destination:e.LD_PUBLIC_BACKEND_URL},{source:"/v1/traces",destination:`${e.LD_OTLP_ENDPOINT}/v1/traces`},{source:"/v1/metrics",destination:`${e.LD_OTLP_ENDPOINT}/v1/metrics`},{source:"/v1/logs",destination:`${e.LD_OTLP_ENDPOINT}/v1/logs`}];i=async()=>{let e;return e=t.rewrites?await t.rewrites():new Array,!e||Array.isArray(e)?(e=e??[],e.concat(...r)):{beforeFiles:e.beforeFiles??[],afterFiles:(e.afterFiles??[]).concat(...r),fallback:e.fallback??[]}}}const s=Array.from(new Set([...t.serverExternalPackages??[],...r]));return{...t,env:{...t.env,[e.PROXY_ENV_FLAG]:a.configureLaunchDarklyProxy?"true":""},rewrites:i,serverExternalPackages:s}};exports.withLaunchDarklyConfig=function(e,r){if("function"==typeof e){return async(n,{defaultConfig:a})=>{const i=e(n,{defaultConfig:a}),s=await i;return t(s,r)}}return t(e,r)};
2
+ //# sourceMappingURL=config.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.cjs","sources":["../src/util/with-launchdarkly-config.ts"],"sourcesContent":["import { NextConfig } from 'next'\nimport { Rewrite } from 'next/dist/lib/load-custom-routes'\n\nimport {\n\tLD_OTLP_ENDPOINT,\n\tLD_PUBLIC_BACKEND_URL,\n\tPROXY_BACKEND_PATH,\n\tPROXY_ENV_FLAG,\n} from './proxy'\n\n/**\n * Packages that the LaunchDarkly observability node SDK relies on and that must\n * be loaded natively at runtime rather than webpack-bundled. Bundling them\n * breaks `require-in-the-middle`-based instrumentation (and therefore\n * server-side tracing initialized via {@link registerObservability}).\n */\nconst LD_SERVER_EXTERNAL_PACKAGES = [\n\t'@launchdarkly/observability-node',\n\t'@launchdarkly/node-server-sdk-otel',\n\t'@prisma/instrumentation',\n\t'require-in-the-middle',\n\t'import-in-the-middle',\n]\n\nexport interface LaunchDarklyConfigOptions {\n\t/**\n\t * Configures same-origin rewrites that proxy browser telemetry through your\n\t * own domain to LaunchDarkly. This avoids ad-blockers and keeps requests on\n\t * your origin. When enabled, {@link LDObservabilityInit} automatically routes\n\t * its requests through the proxy.\n\t * @default true\n\t */\n\tconfigureLaunchDarklyProxy?: boolean\n}\n\ninterface LaunchDarklyConfigOptionsDefault {\n\tconfigureLaunchDarklyProxy: boolean\n}\n\nconst getDefaultOpts = (\n\topts?: LaunchDarklyConfigOptions,\n): LaunchDarklyConfigOptionsDefault => ({\n\tconfigureLaunchDarklyProxy: opts?.configureLaunchDarklyProxy ?? true,\n})\n\ntype NextConfigObject = NextConfig\ntype NextConfigFunction = (\n\tphase: string,\n\t{ defaultConfig }: { defaultConfig: any },\n) => NextConfig\ntype NextConfigAsyncFunction = (\n\tphase: string,\n\t{ defaultConfig }: { defaultConfig: any },\n) => Promise<NextConfig>\ntype NextConfigInput =\n\t| NextConfigObject\n\t| NextConfigFunction\n\t| NextConfigAsyncFunction\n\nconst getLaunchDarklyConfig = (\n\tconfig: NextConfig,\n\topts?: LaunchDarklyConfigOptions,\n): NextConfig => {\n\tconst defaultOpts = getDefaultOpts(opts)\n\n\tlet newRewrites = config.rewrites\n\tif (defaultOpts.configureLaunchDarklyProxy) {\n\t\tconst proxyRewrites: Rewrite[] = [\n\t\t\t{\n\t\t\t\tsource: PROXY_BACKEND_PATH,\n\t\t\t\tdestination: LD_PUBLIC_BACKEND_URL,\n\t\t\t},\n\t\t\t{\n\t\t\t\tsource: '/v1/traces',\n\t\t\t\tdestination: `${LD_OTLP_ENDPOINT}/v1/traces`,\n\t\t\t},\n\t\t\t{\n\t\t\t\tsource: '/v1/metrics',\n\t\t\t\tdestination: `${LD_OTLP_ENDPOINT}/v1/metrics`,\n\t\t\t},\n\t\t\t{\n\t\t\t\tsource: '/v1/logs',\n\t\t\t\tdestination: `${LD_OTLP_ENDPOINT}/v1/logs`,\n\t\t\t},\n\t\t]\n\n\t\tnewRewrites = async () => {\n\t\t\tlet re:\n\t\t\t\t| Rewrite[]\n\t\t\t\t| {\n\t\t\t\t\t\tbeforeFiles?: Rewrite[]\n\t\t\t\t\t\tafterFiles?: Rewrite[]\n\t\t\t\t\t\tfallback?: Rewrite[]\n\t\t\t\t }\n\t\t\tif (!config.rewrites) {\n\t\t\t\tre = new Array<Rewrite>()\n\t\t\t} else {\n\t\t\t\tre = await config.rewrites()\n\t\t\t}\n\n\t\t\tif (!re || Array.isArray(re)) {\n\t\t\t\tre = re ?? []\n\t\t\t\treturn re.concat(...proxyRewrites)\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tbeforeFiles: re.beforeFiles ?? [],\n\t\t\t\tafterFiles: (re.afterFiles ?? []).concat(...proxyRewrites),\n\t\t\t\tfallback: re.fallback ?? [],\n\t\t\t}\n\t\t}\n\t}\n\n\tconst serverExternalPackages = Array.from(\n\t\tnew Set([\n\t\t\t...(config.serverExternalPackages ?? []),\n\t\t\t...LD_SERVER_EXTERNAL_PACKAGES,\n\t\t]),\n\t)\n\n\treturn {\n\t\t...config,\n\t\tenv: {\n\t\t\t...config.env,\n\t\t\t[PROXY_ENV_FLAG]: defaultOpts.configureLaunchDarklyProxy\n\t\t\t\t? 'true'\n\t\t\t\t: '',\n\t\t},\n\t\trewrites: newRewrites,\n\t\tserverExternalPackages,\n\t}\n}\n\nexport function withLaunchDarklyConfig(\n\tconfig: NextConfigObject,\n\topts?: LaunchDarklyConfigOptions,\n): NextConfig\nexport function withLaunchDarklyConfig(\n\tconfig: NextConfigFunction | NextConfigAsyncFunction,\n\topts?: LaunchDarklyConfigOptions,\n): NextConfigAsyncFunction\nexport function withLaunchDarklyConfig(\n\tconfig: NextConfigInput,\n\topts?: LaunchDarklyConfigOptions,\n): NextConfig | NextConfigAsyncFunction {\n\tif (typeof config === 'function') {\n\t\tconst phaseHandler: NextConfigAsyncFunction = async (\n\t\t\tphase: string,\n\t\t\t{ defaultConfig }: { defaultConfig: any },\n\t\t): Promise<NextConfig> => {\n\t\t\tconst userNextConfigObject: NextConfig | Promise<NextConfig> =\n\t\t\t\tconfig(phase, { defaultConfig })\n\t\t\tconst nc = await userNextConfigObject\n\t\t\treturn getLaunchDarklyConfig(nc, opts)\n\t\t}\n\t\treturn phaseHandler\n\t}\n\treturn getLaunchDarklyConfig(config, opts)\n}\n"],"names":["LD_SERVER_EXTERNAL_PACKAGES","getLaunchDarklyConfig","config","opts","defaultOpts","configureLaunchDarklyProxy","getDefaultOpts","newRewrites","rewrites","proxyRewrites","source","PROXY_BACKEND_PATH","destination","LD_PUBLIC_BACKEND_URL","LD_OTLP_ENDPOINT","async","re","Array","isArray","concat","beforeFiles","afterFiles","fallback","serverExternalPackages","from","Set","env","PROXY_ENV_FLAG","phase","defaultConfig","userNextConfigObject","nc"],"mappings":"kDAgBA,MAAMA,EAA8B,CACnC,mCACA,qCACA,0BACA,wBACA,wBAsCKC,EAAwB,CAC7BC,EACAC,KAEA,MAAMC,EAxBgB,CACtBD,IAAgC,CAEhCE,2BAA4BF,GAAME,6BAA8B,IAqB5CC,CAAeH,GAEnC,IAAII,EAAcL,EAAOM,SACzB,GAAIJ,EAAYC,2BAA4B,CAC3C,MAAMI,EAA2B,CAChC,CACCC,OAAQC,EAAAA,mBACRC,YAAaC,EAAAA,uBAEd,CACCH,OAAQ,aACRE,YAAa,GAAGE,EAAAA,8BAEjB,CACCJ,OAAQ,cACRE,YAAa,GAAGE,EAAAA,+BAEjB,CACCJ,OAAQ,WACRE,YAAa,GAAGE,EAAAA,6BAIlBP,EAAcQ,UACb,IAAIC,EAaJ,OAHCA,EAHId,EAAOM,eAGAN,EAAOM,WAFb,IAAIS,OAKLD,GAAMC,MAAMC,QAAQF,IACxBA,EAAKA,GAAM,GACJA,EAAGG,UAAUV,IAEd,CACNW,YAAaJ,EAAGI,aAAe,GAC/BC,YAAaL,EAAGK,YAAc,IAAIF,UAAUV,GAC5Ca,SAAUN,EAAGM,UAAY,IAG5B,CAEA,MAAMC,EAAyBN,MAAMO,KACpC,IAAIC,IAAI,IACHvB,EAAOqB,wBAA0B,MAClCvB,KAIL,MAAO,IACHE,EACHwB,IAAK,IACDxB,EAAOwB,IACV,CAACC,EAAAA,gBAAiBvB,EAAYC,2BAC3B,OACA,IAEJG,SAAUD,EACVgB,0DAYI,SACLrB,EACAC,GAEA,GAAsB,mBAAXD,EAAuB,CAUjC,OAT8Ca,MAC7Ca,GACEC,oBAEF,MAAMC,EACL5B,EAAO0B,EAAO,CAAEC,kBACXE,QAAWD,EACjB,OAAO7B,EAAsB8B,EAAI5B,GAGnC,CACA,OAAOF,EAAsBC,EAAQC,EACtC"}
@@ -0,0 +1,2 @@
1
+ export { withLaunchDarklyConfig, type LaunchDarklyConfigOptions, } from './util/with-launchdarkly-config';
2
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,sBAAsB,EACtB,KAAK,yBAAyB,GAC9B,MAAM,iCAAiC,CAAA"}
package/dist/config.js ADDED
@@ -0,0 +1,2 @@
1
+ import{a as e,L as r,P as t,b as a}from"./proxy-DccSYatN.js";const n=["@launchdarkly/observability-node","@launchdarkly/node-server-sdk-otel","@prisma/instrumentation","require-in-the-middle","import-in-the-middle"],s=(s,i)=>{const o=(e=>({configureLaunchDarklyProxy:e?.configureLaunchDarklyProxy??!0}))(i);let c=s.rewrites;if(o.configureLaunchDarklyProxy){const e=[{source:t,destination:r},{source:"/v1/traces",destination:`${a}/v1/traces`},{source:"/v1/metrics",destination:`${a}/v1/metrics`},{source:"/v1/logs",destination:`${a}/v1/logs`}];c=async()=>{let r;return r=s.rewrites?await s.rewrites():new Array,!r||Array.isArray(r)?(r=r??[],r.concat(...e)):{beforeFiles:r.beforeFiles??[],afterFiles:(r.afterFiles??[]).concat(...e),fallback:r.fallback??[]}}}const l=Array.from(new Set([...s.serverExternalPackages??[],...n]));return{...s,env:{...s.env,[e]:o.configureLaunchDarklyProxy?"true":""},rewrites:c,serverExternalPackages:l}};function i(e,r){if("function"==typeof e){return async(t,{defaultConfig:a})=>{const n=e(t,{defaultConfig:a}),i=await n;return s(i,r)}}return s(e,r)}export{i as withLaunchDarklyConfig};
2
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sources":["../src/util/with-launchdarkly-config.ts"],"sourcesContent":["import { NextConfig } from 'next'\nimport { Rewrite } from 'next/dist/lib/load-custom-routes'\n\nimport {\n\tLD_OTLP_ENDPOINT,\n\tLD_PUBLIC_BACKEND_URL,\n\tPROXY_BACKEND_PATH,\n\tPROXY_ENV_FLAG,\n} from './proxy'\n\n/**\n * Packages that the LaunchDarkly observability node SDK relies on and that must\n * be loaded natively at runtime rather than webpack-bundled. Bundling them\n * breaks `require-in-the-middle`-based instrumentation (and therefore\n * server-side tracing initialized via {@link registerObservability}).\n */\nconst LD_SERVER_EXTERNAL_PACKAGES = [\n\t'@launchdarkly/observability-node',\n\t'@launchdarkly/node-server-sdk-otel',\n\t'@prisma/instrumentation',\n\t'require-in-the-middle',\n\t'import-in-the-middle',\n]\n\nexport interface LaunchDarklyConfigOptions {\n\t/**\n\t * Configures same-origin rewrites that proxy browser telemetry through your\n\t * own domain to LaunchDarkly. This avoids ad-blockers and keeps requests on\n\t * your origin. When enabled, {@link LDObservabilityInit} automatically routes\n\t * its requests through the proxy.\n\t * @default true\n\t */\n\tconfigureLaunchDarklyProxy?: boolean\n}\n\ninterface LaunchDarklyConfigOptionsDefault {\n\tconfigureLaunchDarklyProxy: boolean\n}\n\nconst getDefaultOpts = (\n\topts?: LaunchDarklyConfigOptions,\n): LaunchDarklyConfigOptionsDefault => ({\n\tconfigureLaunchDarklyProxy: opts?.configureLaunchDarklyProxy ?? true,\n})\n\ntype NextConfigObject = NextConfig\ntype NextConfigFunction = (\n\tphase: string,\n\t{ defaultConfig }: { defaultConfig: any },\n) => NextConfig\ntype NextConfigAsyncFunction = (\n\tphase: string,\n\t{ defaultConfig }: { defaultConfig: any },\n) => Promise<NextConfig>\ntype NextConfigInput =\n\t| NextConfigObject\n\t| NextConfigFunction\n\t| NextConfigAsyncFunction\n\nconst getLaunchDarklyConfig = (\n\tconfig: NextConfig,\n\topts?: LaunchDarklyConfigOptions,\n): NextConfig => {\n\tconst defaultOpts = getDefaultOpts(opts)\n\n\tlet newRewrites = config.rewrites\n\tif (defaultOpts.configureLaunchDarklyProxy) {\n\t\tconst proxyRewrites: Rewrite[] = [\n\t\t\t{\n\t\t\t\tsource: PROXY_BACKEND_PATH,\n\t\t\t\tdestination: LD_PUBLIC_BACKEND_URL,\n\t\t\t},\n\t\t\t{\n\t\t\t\tsource: '/v1/traces',\n\t\t\t\tdestination: `${LD_OTLP_ENDPOINT}/v1/traces`,\n\t\t\t},\n\t\t\t{\n\t\t\t\tsource: '/v1/metrics',\n\t\t\t\tdestination: `${LD_OTLP_ENDPOINT}/v1/metrics`,\n\t\t\t},\n\t\t\t{\n\t\t\t\tsource: '/v1/logs',\n\t\t\t\tdestination: `${LD_OTLP_ENDPOINT}/v1/logs`,\n\t\t\t},\n\t\t]\n\n\t\tnewRewrites = async () => {\n\t\t\tlet re:\n\t\t\t\t| Rewrite[]\n\t\t\t\t| {\n\t\t\t\t\t\tbeforeFiles?: Rewrite[]\n\t\t\t\t\t\tafterFiles?: Rewrite[]\n\t\t\t\t\t\tfallback?: Rewrite[]\n\t\t\t\t }\n\t\t\tif (!config.rewrites) {\n\t\t\t\tre = new Array<Rewrite>()\n\t\t\t} else {\n\t\t\t\tre = await config.rewrites()\n\t\t\t}\n\n\t\t\tif (!re || Array.isArray(re)) {\n\t\t\t\tre = re ?? []\n\t\t\t\treturn re.concat(...proxyRewrites)\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tbeforeFiles: re.beforeFiles ?? [],\n\t\t\t\tafterFiles: (re.afterFiles ?? []).concat(...proxyRewrites),\n\t\t\t\tfallback: re.fallback ?? [],\n\t\t\t}\n\t\t}\n\t}\n\n\tconst serverExternalPackages = Array.from(\n\t\tnew Set([\n\t\t\t...(config.serverExternalPackages ?? []),\n\t\t\t...LD_SERVER_EXTERNAL_PACKAGES,\n\t\t]),\n\t)\n\n\treturn {\n\t\t...config,\n\t\tenv: {\n\t\t\t...config.env,\n\t\t\t[PROXY_ENV_FLAG]: defaultOpts.configureLaunchDarklyProxy\n\t\t\t\t? 'true'\n\t\t\t\t: '',\n\t\t},\n\t\trewrites: newRewrites,\n\t\tserverExternalPackages,\n\t}\n}\n\nexport function withLaunchDarklyConfig(\n\tconfig: NextConfigObject,\n\topts?: LaunchDarklyConfigOptions,\n): NextConfig\nexport function withLaunchDarklyConfig(\n\tconfig: NextConfigFunction | NextConfigAsyncFunction,\n\topts?: LaunchDarklyConfigOptions,\n): NextConfigAsyncFunction\nexport function withLaunchDarklyConfig(\n\tconfig: NextConfigInput,\n\topts?: LaunchDarklyConfigOptions,\n): NextConfig | NextConfigAsyncFunction {\n\tif (typeof config === 'function') {\n\t\tconst phaseHandler: NextConfigAsyncFunction = async (\n\t\t\tphase: string,\n\t\t\t{ defaultConfig }: { defaultConfig: any },\n\t\t): Promise<NextConfig> => {\n\t\t\tconst userNextConfigObject: NextConfig | Promise<NextConfig> =\n\t\t\t\tconfig(phase, { defaultConfig })\n\t\t\tconst nc = await userNextConfigObject\n\t\t\treturn getLaunchDarklyConfig(nc, opts)\n\t\t}\n\t\treturn phaseHandler\n\t}\n\treturn getLaunchDarklyConfig(config, opts)\n}\n"],"names":["LD_SERVER_EXTERNAL_PACKAGES","getLaunchDarklyConfig","config","opts","defaultOpts","configureLaunchDarklyProxy","getDefaultOpts","newRewrites","rewrites","proxyRewrites","source","PROXY_BACKEND_PATH","destination","LD_PUBLIC_BACKEND_URL","LD_OTLP_ENDPOINT","async","re","Array","isArray","concat","beforeFiles","afterFiles","fallback","serverExternalPackages","from","Set","env","PROXY_ENV_FLAG","withLaunchDarklyConfig","phase","defaultConfig","userNextConfigObject","nc"],"mappings":"6DAgBA,MAAMA,EAA8B,CACnC,mCACA,qCACA,0BACA,wBACA,wBAsCKC,EAAwB,CAC7BC,EACAC,KAEA,MAAMC,EAxBgB,CACtBD,IAAgC,CAEhCE,2BAA4BF,GAAME,6BAA8B,IAqB5CC,CAAeH,GAEnC,IAAII,EAAcL,EAAOM,SACzB,GAAIJ,EAAYC,2BAA4B,CAC3C,MAAMI,EAA2B,CAChC,CACCC,OAAQC,EACRC,YAAaC,GAEd,CACCH,OAAQ,aACRE,YAAa,GAAGE,eAEjB,CACCJ,OAAQ,cACRE,YAAa,GAAGE,gBAEjB,CACCJ,OAAQ,WACRE,YAAa,GAAGE,cAIlBP,EAAcQ,UACb,IAAIC,EAaJ,OAHCA,EAHId,EAAOM,eAGAN,EAAOM,WAFb,IAAIS,OAKLD,GAAMC,MAAMC,QAAQF,IACxBA,EAAKA,GAAM,GACJA,EAAGG,UAAUV,IAEd,CACNW,YAAaJ,EAAGI,aAAe,GAC/BC,YAAaL,EAAGK,YAAc,IAAIF,UAAUV,GAC5Ca,SAAUN,EAAGM,UAAY,IAG5B,CAEA,MAAMC,EAAyBN,MAAMO,KACpC,IAAIC,IAAI,IACHvB,EAAOqB,wBAA0B,MAClCvB,KAIL,MAAO,IACHE,EACHwB,IAAK,IACDxB,EAAOwB,IACVC,CAACA,GAAiBvB,EAAYC,2BAC3B,OACA,IAEJG,SAAUD,EACVgB,2BAYI,SAAUK,EACf1B,EACAC,GAEA,GAAsB,mBAAXD,EAAuB,CAUjC,OAT8Ca,MAC7Cc,GACEC,oBAEF,MAAMC,EACL7B,EAAO2B,EAAO,CAAEC,kBACXE,QAAWD,EACjB,OAAO9B,EAAsB+B,EAAI7B,GAGnC,CACA,OAAOF,EAAsBC,EAAQC,EACtC"}
@@ -0,0 +1,2 @@
1
+ import{jsx as r,Fragment as t}from"react/jsx-runtime";import{LDObserve as e}from"@launchdarkly/observability";import*as o from"react";class n extends o.Component{state={error:null};static getDerivedStateFromError(r){return{error:r}}componentDidCatch(r,t){e.recordError(r,r.message,{"react.componentStack":t.componentStack??""})}render(){const{error:e}=this.state;if(e){const{fallback:o}=this.props;return r(t,"function"==typeof o?{children:o(e)}:{children:o??null})}return r(t,{children:this.props.children})}}export{n as E};
2
+ //# sourceMappingURL=error-boundary-CSJNDDPj.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-boundary-CSJNDDPj.js","sources":["../src/error-boundary.tsx"],"sourcesContent":["import { LDObserve } from '@launchdarkly/observability'\nimport * as React from 'react'\n\nexport interface ErrorBoundaryProps {\n\tchildren?: React.ReactNode\n\t/**\n\t * Rendered when a descendant throws. Either a node or a render function that\n\t * receives the captured error.\n\t */\n\tfallback?: React.ReactNode | ((error: Error) => React.ReactNode)\n}\n\nexport interface ErrorBoundaryState {\n\terror: Error | null\n}\n\n/**\n * A React error boundary that reports caught errors to LaunchDarkly via\n * {@link LDObserve}. Unlike the Highlight error boundary, it does not depend on\n * a global `window.H`; it talks to the standalone-initialized observability\n * plugin directly.\n */\nexport class ErrorBoundary extends React.Component<\n\tErrorBoundaryProps,\n\tErrorBoundaryState\n> {\n\tstate: ErrorBoundaryState = { error: null }\n\n\tstatic getDerivedStateFromError(error: Error): ErrorBoundaryState {\n\t\treturn { error }\n\t}\n\n\tcomponentDidCatch(error: Error, info: React.ErrorInfo) {\n\t\tLDObserve.recordError(error, error.message, {\n\t\t\t'react.componentStack': info.componentStack ?? '',\n\t\t})\n\t}\n\n\trender() {\n\t\tconst { error } = this.state\n\t\tif (error) {\n\t\t\tconst { fallback } = this.props\n\t\t\tif (typeof fallback === 'function') {\n\t\t\t\treturn <>{fallback(error)}</>\n\t\t\t}\n\t\t\treturn <>{fallback ?? null}</>\n\t\t}\n\t\treturn <>{this.props.children}</>\n\t}\n}\n"],"names":["ErrorBoundary","React","Component","state","error","getDerivedStateFromError","componentDidCatch","info","LDObserve","recordError","message","componentStack","render","this","fallback","props","_jsx","children"],"mappings":"sIAsBM,MAAOA,UAAsBC,EAAMC,UAIxCC,MAA4B,CAAEC,MAAO,MAErC,+BAAOC,CAAyBD,GAC/B,MAAO,CAAEA,QACV,CAEA,iBAAAE,CAAkBF,EAAcG,GAC/BC,EAAUC,YAAYL,EAAOA,EAAMM,QAAS,CAC3C,uBAAwBH,EAAKI,gBAAkB,IAEjD,CAEA,MAAAC,GACC,MAAMR,MAAEA,GAAUS,KAAKV,MACvB,GAAIC,EAAO,CACV,MAAMU,SAAEA,GAAaD,KAAKE,MAC1B,OACQC,IADgB,mBAAbF,YACAA,EAASV,IAEb,CAAAa,SAAGH,GAAY,MACvB,CACA,OAAOE,cAAGH,KAAKE,MAAME,UACtB"}
@@ -0,0 +1,2 @@
1
+ "use strict";var r=require("react/jsx-runtime"),e=require("@launchdarkly/observability");function t(r){var e=Object.create(null);return r&&Object.keys(r).forEach(function(t){if("default"!==t){var n=Object.getOwnPropertyDescriptor(r,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:function(){return r[t]}})}}),e.default=r,Object.freeze(e)}var n=t(require("react"));class c extends n.Component{state={error:null};static getDerivedStateFromError(r){return{error:r}}componentDidCatch(r,t){e.LDObserve.recordError(r,r.message,{"react.componentStack":t.componentStack??""})}render(){const{error:e}=this.state;if(e){const{fallback:t}=this.props;return"function"==typeof t?r.jsx(r.Fragment,{children:t(e)}):r.jsx(r.Fragment,{children:t??null})}return r.jsx(r.Fragment,{children:this.props.children})}}exports.ErrorBoundary=c;
2
+ //# sourceMappingURL=error-boundary-CUcyBTHj.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-boundary-CUcyBTHj.js","sources":["../src/error-boundary.tsx"],"sourcesContent":["import { LDObserve } from '@launchdarkly/observability'\nimport * as React from 'react'\n\nexport interface ErrorBoundaryProps {\n\tchildren?: React.ReactNode\n\t/**\n\t * Rendered when a descendant throws. Either a node or a render function that\n\t * receives the captured error.\n\t */\n\tfallback?: React.ReactNode | ((error: Error) => React.ReactNode)\n}\n\nexport interface ErrorBoundaryState {\n\terror: Error | null\n}\n\n/**\n * A React error boundary that reports caught errors to LaunchDarkly via\n * {@link LDObserve}. Unlike the Highlight error boundary, it does not depend on\n * a global `window.H`; it talks to the standalone-initialized observability\n * plugin directly.\n */\nexport class ErrorBoundary extends React.Component<\n\tErrorBoundaryProps,\n\tErrorBoundaryState\n> {\n\tstate: ErrorBoundaryState = { error: null }\n\n\tstatic getDerivedStateFromError(error: Error): ErrorBoundaryState {\n\t\treturn { error }\n\t}\n\n\tcomponentDidCatch(error: Error, info: React.ErrorInfo) {\n\t\tLDObserve.recordError(error, error.message, {\n\t\t\t'react.componentStack': info.componentStack ?? '',\n\t\t})\n\t}\n\n\trender() {\n\t\tconst { error } = this.state\n\t\tif (error) {\n\t\t\tconst { fallback } = this.props\n\t\t\tif (typeof fallback === 'function') {\n\t\t\t\treturn <>{fallback(error)}</>\n\t\t\t}\n\t\t\treturn <>{fallback ?? null}</>\n\t\t}\n\t\treturn <>{this.props.children}</>\n\t}\n}\n"],"names":["ErrorBoundary","React","Component","state","error","getDerivedStateFromError","componentDidCatch","info","LDObserve","recordError","message","componentStack","render","this","fallback","props","_jsx","_Fragment","children"],"mappings":"oXAsBM,MAAOA,UAAsBC,EAAMC,UAIxCC,MAA4B,CAAEC,MAAO,MAErC,+BAAOC,CAAyBD,GAC/B,MAAO,CAAEA,QACV,CAEA,iBAAAE,CAAkBF,EAAcG,GAC/BC,EAAAA,UAAUC,YAAYL,EAAOA,EAAMM,QAAS,CAC3C,uBAAwBH,EAAKI,gBAAkB,IAEjD,CAEA,MAAAC,GACC,MAAMR,MAAEA,GAAUS,KAAKV,MACvB,GAAIC,EAAO,CACV,MAAMU,SAAEA,GAAaD,KAAKE,MAC1B,MAAwB,mBAAbD,EACHE,EAAAA,yBAAGF,EAASV,KAEbY,EAAAA,IAAAC,EAAAA,SAAA,CAAAC,SAAGJ,GAAY,MACvB,CACA,OAAOE,EAAAA,yBAAGH,KAAKE,MAAMG,UACtB"}
@@ -0,0 +1,15 @@
1
+ import * as React from 'react';
2
+ export interface ErrorBoundaryProps {
3
+ children?: React.ReactNode;
4
+ fallback?: React.ReactNode | ((error: Error) => React.ReactNode);
5
+ }
6
+ export interface ErrorBoundaryState {
7
+ error: Error | null;
8
+ }
9
+ export declare class ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundaryState> {
10
+ state: ErrorBoundaryState;
11
+ static getDerivedStateFromError(error: Error): ErrorBoundaryState;
12
+ componentDidCatch(error: Error, info: React.ErrorInfo): void;
13
+ render(): import("react/jsx-runtime").JSX.Element;
14
+ }
15
+ //# sourceMappingURL=error-boundary.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-boundary.d.ts","sourceRoot":"","sources":["../src/error-boundary.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,MAAM,WAAW,kBAAkB;IAClC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAK1B,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,KAAK,KAAK,CAAC,SAAS,CAAC,CAAA;CAChE;AAED,MAAM,WAAW,kBAAkB;IAClC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAA;CACnB;AAQD,qBAAa,aAAc,SAAQ,KAAK,CAAC,SAAS,CACjD,kBAAkB,EAClB,kBAAkB,CAClB;IACA,KAAK,EAAE,kBAAkB,CAAkB;IAE3C,MAAM,CAAC,wBAAwB,CAAC,KAAK,EAAE,KAAK,GAAG,kBAAkB;IAIjE,iBAAiB,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC,SAAS;IAMrD,MAAM;CAWN"}
@@ -0,0 +1,3 @@
1
+ "use client";
2
+ "use strict";var e=require("@launchdarkly/observability"),r=require("@launchdarkly/session-replay"),n=require("js-cookie"),t=require("react"),o=require("./proxy-B6yiPOEG.js"),s=require("./standalone-CQH9Vh11.js"),i=require("./error-boundary-CUcyBTHj.js");require("react/jsx-runtime"),Object.defineProperty(exports,"LDObserve",{enumerable:!0,get:function(){return e.LDObserve}}),Object.defineProperty(exports,"LDRecord",{enumerable:!0,get:function(){return r.LDRecord}}),exports.ErrorBoundary=i.ErrorBoundary,exports.LDObservabilityInit=function({sdkKey:i,application:u,excludedHostnames:a=[],...c}){return t.useEffect(()=>{if(!(!!i&&a.every(e=>!window.location.hostname.includes(e))))return;let t={...c};"true"===process.env[o.PROXY_ENV_FLAG]&&(t={...t,backendUrl:o.PROXY_BACKEND_PATH,otel:{...t.otel,otlpEndpoint:window.location.origin}}),s.ensureStandaloneInit("observe",()=>new e(t),i,u),s.ensureStandaloneInit("record",()=>new r(t),i,u);const l=()=>{const e=r.LDRecord.getSession()?.sessionSecureID;return!!e&&(n.set("sessionSecureID",e),!0)};if(l())return;let d=0;const b=setInterval(()=>{(l()||++d>=50)&&clearInterval(b)},100);return()=>clearInterval(b)},[]),null};
3
+ //# sourceMappingURL=next-client.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"next-client.cjs","sources":["../src/next-client.tsx"],"sourcesContent":["import Observability, {\n\tLDObserve,\n\ttype ObserveOptions,\n} from '@launchdarkly/observability'\nimport SessionReplay, {\n\tLDRecord,\n\ttype RecordOptions,\n} from '@launchdarkly/session-replay'\nimport Cookies from 'js-cookie'\nimport { useEffect } from 'react'\n\nimport { PROXY_BACKEND_PATH, PROXY_ENV_FLAG } from './util/proxy'\nimport { ensureStandaloneInit, type LDApplicationInfo } from './util/standalone'\n\nexport { ErrorBoundary } from './error-boundary'\nexport type { ErrorBoundaryProps, ErrorBoundaryState } from './error-boundary'\nexport { LDObserve, LDRecord }\n\n/**\n * Options for {@link LDObservabilityInit}. Combines the browser observability and\n * session replay options, plus the LaunchDarkly SDK key used to initialize them\n * in standalone mode.\n */\nexport type LDObservabilityInitProps = ObserveOptions &\n\tRecordOptions & {\n\t\t/**\n\t\t * The LaunchDarkly client-side ID (SDK key) for the environment to send\n\t\t * telemetry to. Required for the SDK to initialize.\n\t\t */\n\t\tsdkKey?: string\n\t\t/**\n\t\t * Application metadata (id / version) tagged onto telemetry, mirroring\n\t\t * the `application` field of a LaunchDarkly client configuration.\n\t\t */\n\t\tapplication?: LDApplicationInfo\n\t\t/**\n\t\t * Hostnames on which the SDK should not initialize (e.g. local\n\t\t * development domains). If the current hostname includes any of these\n\t\t * substrings the SDK is skipped.\n\t\t */\n\t\texcludedHostnames?: string[]\n\t}\n\n/**\n * Drop-in client component that boots LaunchDarkly observability and session\n * replay for a Next.js app. Render it once near the root of your app (e.g. in\n * `app/layout.tsx` or `pages/_app.tsx`).\n *\n * It runs the plugins in standalone mode — there is no LaunchDarkly feature-flag\n * SDK for Next.js, so the plugins are initialized directly from the LaunchDarkly\n * SDK key rather than registered with an LD client.\n */\nexport function LDObservabilityInit({\n\tsdkKey,\n\tapplication,\n\texcludedHostnames = [],\n\t...options\n}: LDObservabilityInitProps) {\n\tuseEffect(() => {\n\t\tconst shouldRender =\n\t\t\t!!sdkKey &&\n\t\t\texcludedHostnames.every(\n\t\t\t\t(hostname) => !window.location.hostname.includes(hostname),\n\t\t\t)\n\n\t\tif (!shouldRender) {\n\t\t\treturn\n\t\t}\n\n\t\tlet initOptions: LDObservabilityInitProps = { ...options }\n\n\t\tconst configureProxy = process.env[PROXY_ENV_FLAG] === 'true'\n\t\tif (configureProxy) {\n\t\t\tinitOptions = {\n\t\t\t\t...initOptions,\n\t\t\t\tbackendUrl: PROXY_BACKEND_PATH,\n\t\t\t\totel: {\n\t\t\t\t\t...initOptions.otel,\n\t\t\t\t\totlpEndpoint: window.location.origin,\n\t\t\t\t},\n\t\t\t}\n\t\t}\n\n\t\t// Standalone init loads the LDObserve / LDRecord singletons. The shared\n\t\t// guard keeps this idempotent across re-renders and bundles.\n\t\tensureStandaloneInit(\n\t\t\t'observe',\n\t\t\t() => new Observability(initOptions),\n\t\t\tsdkKey,\n\t\t\tapplication,\n\t\t)\n\t\tensureStandaloneInit(\n\t\t\t'record',\n\t\t\t() => new SessionReplay(initOptions),\n\t\t\tsdkKey,\n\t\t\tapplication,\n\t\t)\n\n\t\t// The session secure id only becomes available once the session replay\n\t\t// SDK has finished loading, so LDRecord.getSession() returns null right\n\t\t// after init. Poll briefly until it resolves, then persist it for\n\t\t// observabilityMiddleware to forward as x-highlight-request. If replay\n\t\t// never loads, there is no session to link and the cookie is left unset.\n\t\tconst persistSessionCookie = () => {\n\t\t\tconst sessionSecureID = LDRecord.getSession()?.sessionSecureID\n\t\t\tif (sessionSecureID) {\n\t\t\t\tCookies.set('sessionSecureID', sessionSecureID)\n\t\t\t\treturn true\n\t\t\t}\n\t\t\treturn false\n\t\t}\n\t\tif (persistSessionCookie()) {\n\t\t\treturn\n\t\t}\n\t\tlet attempts = 0\n\t\tconst interval = setInterval(() => {\n\t\t\tif (persistSessionCookie() || ++attempts >= 50) {\n\t\t\t\tclearInterval(interval)\n\t\t\t}\n\t\t}, 100)\n\t\treturn () => clearInterval(interval)\n\t}, []) // eslint-disable-line react-hooks/exhaustive-deps\n\n\treturn null\n}\n"],"names":["sdkKey","application","excludedHostnames","options","useEffect","every","hostname","window","location","includes","initOptions","process","env","PROXY_ENV_FLAG","backendUrl","PROXY_BACKEND_PATH","otel","otlpEndpoint","origin","ensureStandaloneInit","Observability","SessionReplay","persistSessionCookie","sessionSecureID","LDRecord","getSession","Cookies","set","attempts","interval","setInterval","clearInterval"],"mappings":"whBAoDM,UAA8BA,OACnCA,EAAMC,YACNA,EAAWC,kBACXA,EAAoB,MACjBC,IAmEH,OAjEAC,EAAAA,UAAU,KAOT,OALGJ,GACFE,EAAkBG,MAChBC,IAAcC,OAAOC,SAASF,SAASG,SAASH,KAIlD,OAGD,IAAII,EAAwC,IAAKP,GAEM,SAAhCQ,QAAQC,IAAIC,EAAAA,kBAElCH,EAAc,IACVA,EACHI,WAAYC,EAAAA,mBACZC,KAAM,IACFN,EAAYM,KACfC,aAAcV,OAAOC,SAASU,UAOjCC,EAAAA,qBACC,UACA,IAAM,IAAIC,EAAcV,GACxBV,EACAC,GAEDkB,EAAAA,qBACC,SACA,IAAM,IAAIE,EAAcX,GACxBV,EACAC,GAQD,MAAMqB,EAAuB,KAC5B,MAAMC,EAAkBC,EAAAA,SAASC,cAAcF,gBAC/C,QAAIA,IACHG,EAAQC,IAAI,kBAAmBJ,IACxB,IAIT,GAAID,IACH,OAED,IAAIM,EAAW,EACf,MAAMC,EAAWC,YAAY,MACxBR,OAA4BM,GAAY,KAC3CG,cAAcF,IAEb,KACH,MAAO,IAAME,cAAcF,IACzB,IAEI,IACR"}
@@ -0,0 +1,13 @@
1
+ import { LDObserve, type ObserveOptions } from '@launchdarkly/observability';
2
+ import { LDRecord, type RecordOptions } from '@launchdarkly/session-replay';
3
+ import { type LDApplicationInfo } from './util/standalone';
4
+ export { ErrorBoundary } from './error-boundary';
5
+ export type { ErrorBoundaryProps, ErrorBoundaryState } from './error-boundary';
6
+ export { LDObserve, LDRecord };
7
+ export type LDObservabilityInitProps = ObserveOptions & RecordOptions & {
8
+ sdkKey?: string;
9
+ application?: LDApplicationInfo;
10
+ excludedHostnames?: string[];
11
+ };
12
+ export declare function LDObservabilityInit({ sdkKey, application, excludedHostnames, ...options }: LDObservabilityInitProps): null;
13
+ //# sourceMappingURL=next-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"next-client.d.ts","sourceRoot":"","sources":["../src/next-client.tsx"],"names":[],"mappings":"AAAA,OAAsB,EACrB,SAAS,EACT,KAAK,cAAc,EACnB,MAAM,6BAA6B,CAAA;AACpC,OAAsB,EACrB,QAAQ,EACR,KAAK,aAAa,EAClB,MAAM,8BAA8B,CAAA;AAKrC,OAAO,EAAwB,KAAK,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AAEhF,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAChD,YAAY,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAC9E,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAA;AAO9B,MAAM,MAAM,wBAAwB,GAAG,cAAc,GACpD,aAAa,GAAG;IAKf,MAAM,CAAC,EAAE,MAAM,CAAA;IAKf,WAAW,CAAC,EAAE,iBAAiB,CAAA;IAM/B,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAA;CAC5B,CAAA;AAWF,wBAAgB,mBAAmB,CAAC,EACnC,MAAM,EACN,WAAW,EACX,iBAAsB,EACtB,GAAG,OAAO,EACV,EAAE,wBAAwB,QAmE1B"}
@@ -0,0 +1,3 @@
1
+ "use client";
2
+ import r from"@launchdarkly/observability";export{LDObserve}from"@launchdarkly/observability";import e,{LDRecord as o}from"@launchdarkly/session-replay";export{LDRecord}from"@launchdarkly/session-replay";import t from"js-cookie";import{useEffect as n}from"react";import{P as s,a}from"./proxy-DccSYatN.js";import{e as i}from"./standalone-CkwD29IP.js";export{E as ErrorBoundary}from"./error-boundary-CSJNDDPj.js";import"react/jsx-runtime";function l({sdkKey:l,application:c,excludedHostnames:m=[],...p}){return n(()=>{if(!(!!l&&m.every(r=>!window.location.hostname.includes(r))))return;let n={...p};"true"===process.env[a]&&(n={...n,backendUrl:s,otel:{...n.otel,otlpEndpoint:window.location.origin}}),i("observe",()=>new r(n),l,c),i("record",()=>new e(n),l,c);const u=()=>{const r=o.getSession()?.sessionSecureID;return!!r&&(t.set("sessionSecureID",r),!0)};if(u())return;let d=0;const y=setInterval(()=>{(u()||++d>=50)&&clearInterval(y)},100);return()=>clearInterval(y)},[]),null}export{l as LDObservabilityInit};
3
+ //# sourceMappingURL=next-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"next-client.js","sources":["../src/next-client.tsx"],"sourcesContent":["import Observability, {\n\tLDObserve,\n\ttype ObserveOptions,\n} from '@launchdarkly/observability'\nimport SessionReplay, {\n\tLDRecord,\n\ttype RecordOptions,\n} from '@launchdarkly/session-replay'\nimport Cookies from 'js-cookie'\nimport { useEffect } from 'react'\n\nimport { PROXY_BACKEND_PATH, PROXY_ENV_FLAG } from './util/proxy'\nimport { ensureStandaloneInit, type LDApplicationInfo } from './util/standalone'\n\nexport { ErrorBoundary } from './error-boundary'\nexport type { ErrorBoundaryProps, ErrorBoundaryState } from './error-boundary'\nexport { LDObserve, LDRecord }\n\n/**\n * Options for {@link LDObservabilityInit}. Combines the browser observability and\n * session replay options, plus the LaunchDarkly SDK key used to initialize them\n * in standalone mode.\n */\nexport type LDObservabilityInitProps = ObserveOptions &\n\tRecordOptions & {\n\t\t/**\n\t\t * The LaunchDarkly client-side ID (SDK key) for the environment to send\n\t\t * telemetry to. Required for the SDK to initialize.\n\t\t */\n\t\tsdkKey?: string\n\t\t/**\n\t\t * Application metadata (id / version) tagged onto telemetry, mirroring\n\t\t * the `application` field of a LaunchDarkly client configuration.\n\t\t */\n\t\tapplication?: LDApplicationInfo\n\t\t/**\n\t\t * Hostnames on which the SDK should not initialize (e.g. local\n\t\t * development domains). If the current hostname includes any of these\n\t\t * substrings the SDK is skipped.\n\t\t */\n\t\texcludedHostnames?: string[]\n\t}\n\n/**\n * Drop-in client component that boots LaunchDarkly observability and session\n * replay for a Next.js app. Render it once near the root of your app (e.g. in\n * `app/layout.tsx` or `pages/_app.tsx`).\n *\n * It runs the plugins in standalone mode — there is no LaunchDarkly feature-flag\n * SDK for Next.js, so the plugins are initialized directly from the LaunchDarkly\n * SDK key rather than registered with an LD client.\n */\nexport function LDObservabilityInit({\n\tsdkKey,\n\tapplication,\n\texcludedHostnames = [],\n\t...options\n}: LDObservabilityInitProps) {\n\tuseEffect(() => {\n\t\tconst shouldRender =\n\t\t\t!!sdkKey &&\n\t\t\texcludedHostnames.every(\n\t\t\t\t(hostname) => !window.location.hostname.includes(hostname),\n\t\t\t)\n\n\t\tif (!shouldRender) {\n\t\t\treturn\n\t\t}\n\n\t\tlet initOptions: LDObservabilityInitProps = { ...options }\n\n\t\tconst configureProxy = process.env[PROXY_ENV_FLAG] === 'true'\n\t\tif (configureProxy) {\n\t\t\tinitOptions = {\n\t\t\t\t...initOptions,\n\t\t\t\tbackendUrl: PROXY_BACKEND_PATH,\n\t\t\t\totel: {\n\t\t\t\t\t...initOptions.otel,\n\t\t\t\t\totlpEndpoint: window.location.origin,\n\t\t\t\t},\n\t\t\t}\n\t\t}\n\n\t\t// Standalone init loads the LDObserve / LDRecord singletons. The shared\n\t\t// guard keeps this idempotent across re-renders and bundles.\n\t\tensureStandaloneInit(\n\t\t\t'observe',\n\t\t\t() => new Observability(initOptions),\n\t\t\tsdkKey,\n\t\t\tapplication,\n\t\t)\n\t\tensureStandaloneInit(\n\t\t\t'record',\n\t\t\t() => new SessionReplay(initOptions),\n\t\t\tsdkKey,\n\t\t\tapplication,\n\t\t)\n\n\t\t// The session secure id only becomes available once the session replay\n\t\t// SDK has finished loading, so LDRecord.getSession() returns null right\n\t\t// after init. Poll briefly until it resolves, then persist it for\n\t\t// observabilityMiddleware to forward as x-highlight-request. If replay\n\t\t// never loads, there is no session to link and the cookie is left unset.\n\t\tconst persistSessionCookie = () => {\n\t\t\tconst sessionSecureID = LDRecord.getSession()?.sessionSecureID\n\t\t\tif (sessionSecureID) {\n\t\t\t\tCookies.set('sessionSecureID', sessionSecureID)\n\t\t\t\treturn true\n\t\t\t}\n\t\t\treturn false\n\t\t}\n\t\tif (persistSessionCookie()) {\n\t\t\treturn\n\t\t}\n\t\tlet attempts = 0\n\t\tconst interval = setInterval(() => {\n\t\t\tif (persistSessionCookie() || ++attempts >= 50) {\n\t\t\t\tclearInterval(interval)\n\t\t\t}\n\t\t}, 100)\n\t\treturn () => clearInterval(interval)\n\t}, []) // eslint-disable-line react-hooks/exhaustive-deps\n\n\treturn null\n}\n"],"names":["LDObservabilityInit","sdkKey","application","excludedHostnames","options","useEffect","every","hostname","window","location","includes","initOptions","process","env","PROXY_ENV_FLAG","backendUrl","PROXY_BACKEND_PATH","otel","otlpEndpoint","origin","ensureStandaloneInit","Observability","SessionReplay","persistSessionCookie","sessionSecureID","LDRecord","getSession","Cookies","set","attempts","interval","setInterval","clearInterval"],"mappings":"qbAoDM,SAAUA,GAAoBC,OACnCA,EAAMC,YACNA,EAAWC,kBACXA,EAAoB,MACjBC,IAmEH,OAjEAC,EAAU,KAOT,OALGJ,GACFE,EAAkBG,MAChBC,IAAcC,OAAOC,SAASF,SAASG,SAASH,KAIlD,OAGD,IAAII,EAAwC,IAAKP,GAEM,SAAhCQ,QAAQC,IAAIC,KAElCH,EAAc,IACVA,EACHI,WAAYC,EACZC,KAAM,IACFN,EAAYM,KACfC,aAAcV,OAAOC,SAASU,UAOjCC,EACC,UACA,IAAM,IAAIC,EAAcV,GACxBV,EACAC,GAEDkB,EACC,SACA,IAAM,IAAIE,EAAcX,GACxBV,EACAC,GAQD,MAAMqB,EAAuB,KAC5B,MAAMC,EAAkBC,EAASC,cAAcF,gBAC/C,QAAIA,IACHG,EAAQC,IAAI,kBAAmBJ,IACxB,IAIT,GAAID,IACH,OAED,IAAIM,EAAW,EACf,MAAMC,EAAWC,YAAY,MACxBR,OAA4BM,GAAY,KAC3CG,cAAcF,IAEb,KACH,MAAO,IAAME,cAAcF,IACzB,IAEI,IACR"}
@@ -0,0 +1,2 @@
1
+ "use strict";var e=require("next/headers"),s=require("next/server");exports.isNodeJsRuntime=function(){return void 0===process.env.NEXT_RUNTIME||"nodejs"===process.env.NEXT_RUNTIME},exports.observabilityMiddleware=async function(r){const t=new Headers(r.headers),i=(await e.cookies()).get("sessionSecureID")?.value;return!t.get("x-highlight-request")&&i&&t.set("x-highlight-request",`${i}/`),s.NextResponse.next({request:{headers:t}})};
2
+ //# sourceMappingURL=observability-middleware-CH0Vm0ev.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"observability-middleware-CH0Vm0ev.js","sources":["../src/util/is-node-js-runtime.ts","../src/util/observability-middleware.ts"],"sourcesContent":["export function isNodeJsRuntime() {\n\treturn (\n\t\ttypeof process.env.NEXT_RUNTIME === 'undefined' ||\n\t\tprocess.env.NEXT_RUNTIME === 'nodejs'\n\t)\n}\n","import { cookies } from 'next/headers'\nimport { NextResponse } from 'next/server'\n\n/**\n * Next.js middleware helper that forwards the browser session id (stored in the\n * `sessionSecureID` cookie by {@link LDObservabilityInit}) to your server as the\n * `x-highlight-request` header, so backend traces can be linked to the session.\n *\n * Returns a {@link NextResponse} that carries the forwarded header through to\n * downstream route handlers — Next.js only propagates request-header mutations\n * when they are passed via `NextResponse.next({ request: { headers } })`, so\n * your `middleware` must return this response:\n *\n * ```ts\n * export async function middleware(request: Request) {\n * \treturn observabilityMiddleware(request)\n * }\n * ```\n *\n * Safe to run in the edge runtime — it only touches cookies and headers.\n */\nexport async function observabilityMiddleware(request: Request) {\n\tconst requestHeaders = new Headers(request.headers)\n\tconst sessionSecureID = (await cookies()).get('sessionSecureID')?.value\n\tconst xHighlightRequest = requestHeaders.get('x-highlight-request')\n\tif (!xHighlightRequest && sessionSecureID) {\n\t\trequestHeaders.set('x-highlight-request', `${sessionSecureID}/`)\n\t}\n\treturn NextResponse.next({ request: { headers: requestHeaders } })\n}\n"],"names":["process","env","NEXT_RUNTIME","async","request","requestHeaders","Headers","headers","sessionSecureID","cookies","get","value","set","NextResponse","next"],"mappings":"uGACC,YACqC,IAA7BA,QAAQC,IAAIC,cACU,WAA7BF,QAAQC,IAAIC,YAEd,kCCgBOC,eAAuCC,GAC7C,MAAMC,EAAiB,IAAIC,QAAQF,EAAQG,SACrCC,SAAyBC,EAAAA,WAAWC,IAAI,oBAAoBC,MAKlE,OAJ0BN,EAAeK,IAAI,wBACnBF,GACzBH,EAAeO,IAAI,sBAAuB,GAAGJ,MAEvCK,EAAAA,aAAaC,KAAK,CAAEV,QAAS,CAAEG,QAASF,IAChD"}
@@ -0,0 +1,2 @@
1
+ import{cookies as e}from"next/headers";import{NextResponse as r}from"next/server";function s(){return void 0===process.env.NEXT_RUNTIME||"nodejs"===process.env.NEXT_RUNTIME}async function t(s){const t=new Headers(s.headers),n=(await e()).get("sessionSecureID")?.value;return!t.get("x-highlight-request")&&n&&t.set("x-highlight-request",`${n}/`),r.next({request:{headers:t}})}export{s as i,t as o};
2
+ //# sourceMappingURL=observability-middleware-D4dJiJoK.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"observability-middleware-D4dJiJoK.js","sources":["../src/util/is-node-js-runtime.ts","../src/util/observability-middleware.ts"],"sourcesContent":["export function isNodeJsRuntime() {\n\treturn (\n\t\ttypeof process.env.NEXT_RUNTIME === 'undefined' ||\n\t\tprocess.env.NEXT_RUNTIME === 'nodejs'\n\t)\n}\n","import { cookies } from 'next/headers'\nimport { NextResponse } from 'next/server'\n\n/**\n * Next.js middleware helper that forwards the browser session id (stored in the\n * `sessionSecureID` cookie by {@link LDObservabilityInit}) to your server as the\n * `x-highlight-request` header, so backend traces can be linked to the session.\n *\n * Returns a {@link NextResponse} that carries the forwarded header through to\n * downstream route handlers — Next.js only propagates request-header mutations\n * when they are passed via `NextResponse.next({ request: { headers } })`, so\n * your `middleware` must return this response:\n *\n * ```ts\n * export async function middleware(request: Request) {\n * \treturn observabilityMiddleware(request)\n * }\n * ```\n *\n * Safe to run in the edge runtime — it only touches cookies and headers.\n */\nexport async function observabilityMiddleware(request: Request) {\n\tconst requestHeaders = new Headers(request.headers)\n\tconst sessionSecureID = (await cookies()).get('sessionSecureID')?.value\n\tconst xHighlightRequest = requestHeaders.get('x-highlight-request')\n\tif (!xHighlightRequest && sessionSecureID) {\n\t\trequestHeaders.set('x-highlight-request', `${sessionSecureID}/`)\n\t}\n\treturn NextResponse.next({ request: { headers: requestHeaders } })\n}\n"],"names":["isNodeJsRuntime","process","env","NEXT_RUNTIME","async","observabilityMiddleware","request","requestHeaders","Headers","headers","sessionSecureID","cookies","get","value","set","NextResponse","next"],"mappings":"2FAAgBA,IACf,YACqC,IAA7BC,QAAQC,IAAIC,cACU,WAA7BF,QAAQC,IAAIC,YAEd,CCgBOC,eAAeC,EAAwBC,GAC7C,MAAMC,EAAiB,IAAIC,QAAQF,EAAQG,SACrCC,SAAyBC,KAAWC,IAAI,oBAAoBC,MAKlE,OAJ0BN,EAAeK,IAAI,wBACnBF,GACzBH,EAAeO,IAAI,sBAAuB,GAAGJ,MAEvCK,EAAaC,KAAK,CAAEV,QAAS,CAAEG,QAASF,IAChD"}
@@ -0,0 +1,2 @@
1
+ "use strict";exports.LD_OTLP_ENDPOINT="https://otel.observability.app.launchdarkly.com",exports.LD_PUBLIC_BACKEND_URL="https://pub.observability.app.launchdarkly.com",exports.PROXY_BACKEND_PATH="/highlight-events",exports.PROXY_ENV_FLAG="configureLaunchDarklyProxy";
2
+ //# sourceMappingURL=proxy-B6yiPOEG.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"proxy-B6yiPOEG.js","sources":["../src/util/proxy.ts"],"sourcesContent":["/**\n * Shared constants describing the optional same-origin proxy that\n * {@link withLaunchDarklyConfig} sets up and that the client reads. Proxying\n * routes browser telemetry through your own domain so it is not blocked by ad\n * blockers and so that requests share the page's origin.\n */\n\n/** Env var (inlined by Next) signalling that the proxy rewrites are configured. */\nexport const PROXY_ENV_FLAG = 'configureLaunchDarklyProxy'\n\n/** Same-origin path that proxies to the LaunchDarkly events ingest endpoint. */\nexport const PROXY_BACKEND_PATH = '/highlight-events'\n\n/** Public LaunchDarkly endpoints that the proxy rewrites forward to. */\nexport const LD_PUBLIC_BACKEND_URL =\n\t'https://pub.observability.app.launchdarkly.com'\nexport const LD_OTLP_ENDPOINT =\n\t'https://otel.observability.app.launchdarkly.com'\n"],"names":[],"mappings":"sCAiBC,gFAFA,4EAJiC,2CAHJ"}
@@ -0,0 +1,2 @@
1
+ const a="configureLaunchDarklyProxy",t="/highlight-events",s="https://pub.observability.app.launchdarkly.com",l="https://otel.observability.app.launchdarkly.com";export{s as L,t as P,a,l as b};
2
+ //# sourceMappingURL=proxy-DccSYatN.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"proxy-DccSYatN.js","sources":["../src/util/proxy.ts"],"sourcesContent":["/**\n * Shared constants describing the optional same-origin proxy that\n * {@link withLaunchDarklyConfig} sets up and that the client reads. Proxying\n * routes browser telemetry through your own domain so it is not blocked by ad\n * blockers and so that requests share the page's origin.\n */\n\n/** Env var (inlined by Next) signalling that the proxy rewrites are configured. */\nexport const PROXY_ENV_FLAG = 'configureLaunchDarklyProxy'\n\n/** Same-origin path that proxies to the LaunchDarkly events ingest endpoint. */\nexport const PROXY_BACKEND_PATH = '/highlight-events'\n\n/** Public LaunchDarkly endpoints that the proxy rewrites forward to. */\nexport const LD_PUBLIC_BACKEND_URL =\n\t'https://pub.observability.app.launchdarkly.com'\nexport const LD_OTLP_ENDPOINT =\n\t'https://otel.observability.app.launchdarkly.com'\n"],"names":["PROXY_ENV_FLAG","PROXY_BACKEND_PATH","LD_PUBLIC_BACKEND_URL","LD_OTLP_ENDPOINT"],"mappings":"AAQO,MAAMA,EAAiB,6BAGjBC,EAAqB,oBAGrBC,EACZ,iDACYC,EACZ"}
@@ -0,0 +1,2 @@
1
+ "use strict";var e=require("@launchdarkly/observability-node"),r=require("./observability-middleware-CH0Vm0ev.js"),t=require("./standalone-CQH9Vh11.js");let i;async function s(e){if(r.isNodeJsRuntime())return i??=async function(e){const{Observability:r}=await import("@launchdarkly/observability-node"),{sdkKey:i,...s}=e,n=new r(s);n.register?.({},t.standaloneMetadata(i))}(e).catch(e=>{throw i=void 0,e}),i;console.info(`LaunchDarkly observability not registered: NEXT_RUNTIME=${process.env.NEXT_RUNTIME}`)}function n(e){return e?e.split("#")[0].split("?")[0]:""}require("next/headers"),require("next/server");const o=a;function a(t){if(r.isNodeJsRuntime())return(r=>t=>async(i,o)=>(await s(r),await e.LDObserve.runWithHeaders(`${i.method?.toUpperCase()} - ${n(i.url)}`,i.headers,async()=>await t(i,o))))(t);throw new Error(`unidentified NEXT_RUNTIME: ${process.env.NEXT_RUNTIME}`)}Object.defineProperty(exports,"Handlers",{enumerable:!0,get:function(){return e.Handlers}}),Object.defineProperty(exports,"LDObserve",{enumerable:!0,get:function(){return e.LDObserve}}),exports.isNodeJsRuntime=r.isNodeJsRuntime,exports.observabilityMiddleware=r.observabilityMiddleware,exports.AppRouterObservability=function(t){if(r.isNodeJsRuntime())return function(r){return t=>async(i,o)=>(await s(r),await e.LDObserve.runWithHeaders(`${i.method?.toUpperCase()} - ${n(i.url)}`,i.headers,async()=>t(i,o)))}(t);throw new Error(`unidentified NEXT_RUNTIME: ${process.env.NEXT_RUNTIME}`)},exports.EdgeObservability=function(e){throw new Error(`unsupported NEXT_RUNTIME: ${process.env.NEXT_RUNTIME}`)},exports.Observability=o,exports.PageRouterObservability=a,exports.registerObservability=s;
2
+ //# sourceMappingURL=server.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.cjs","sources":["../src/util/register-observability.ts","../src/util/sanitize-url.ts","../src/util/with-observability-page-router.ts","../src/server.ts","../src/util/with-observability-app-router.ts"],"sourcesContent":["import { isNodeJsRuntime } from './is-node-js-runtime'\nimport { standaloneMetadata, type StandalonePlugin } from './standalone'\nimport type { ObservabilityEnv } from './types'\n\nlet initPromise: Promise<void> | undefined\n\nasync function init(env: ObservabilityEnv) {\n\t// Import lazily so the OpenTelemetry/node dependencies are never pulled into\n\t// an edge bundle.\n\tconst { Observability } = await import('@launchdarkly/observability-node')\n\n\tconst { sdkKey, ...options } = env\n\tconst plugin = new Observability(options) as unknown as StandalonePlugin\n\t// `register` ignores the client argument and initializes LDObserve from the\n\t// SDK key in the metadata. See util/standalone.ts.\n\tplugin.register?.({}, standaloneMetadata(sdkKey))\n}\n\n/**\n * Initialize the server-side LaunchDarkly observability plugin in standalone\n * mode. Call this from your Next.js `instrumentation.ts` `register()` hook.\n *\n * Initialization only happens in the Node.js runtime; in the edge runtime this\n * is a no-op (the OpenTelemetry-based node SDK is not edge-compatible). It is\n * idempotent and concurrency-safe, so route-handler wrappers can safely await\n * it on every request.\n *\n * `LDObserve` is a process-global singleton that can only be initialized once,\n * so the first successful call wins and later calls reuse it. All callers\n * (`instrumentation.ts` and any route wrappers) should therefore pass the same\n * `env` — initialize once in `instrumentation.ts` for the canonical config.\n */\nexport async function registerObservability(env: ObservabilityEnv) {\n\tif (!isNodeJsRuntime()) {\n\t\tconsole.info(\n\t\t\t`LaunchDarkly observability not registered: NEXT_RUNTIME=${process.env.NEXT_RUNTIME}`,\n\t\t)\n\t\treturn\n\t}\n\n\t// Cache the in-flight/successful init, but drop the cached promise if it\n\t// rejects so a failed import or registration can be retried on a later\n\t// call rather than poisoning every subsequent request.\n\tinitPromise ??= init(env).catch((err) => {\n\t\tinitPromise = undefined\n\t\tthrow err\n\t})\n\treturn initPromise\n}\n","/**\n * Strip the query string and fragment from a URL before it is used as an\n * OpenTelemetry span name. Query params and hash fragments can carry secrets\n * (OAuth tokens, auth codes, signed URLs); span names are exported to the\n * tracing backend, so the high-cardinality, potentially-sensitive tail must be\n * dropped. Works for both absolute URLs (`request.url`) and request-relative\n * paths (`req.url` in the Pages Router).\n */\nexport function sanitizeSpanUrl(url: string | undefined): string {\n\tif (!url) {\n\t\treturn ''\n\t}\n\treturn url.split('#')[0].split('?')[0]\n}\n","import { LDObserve } from '@launchdarkly/observability-node'\n\nimport { registerObservability } from './register-observability'\nimport { sanitizeSpanUrl } from './sanitize-url'\nimport type { ObservabilityEnv } from './types'\n\nimport type { IncomingHttpHeaders } from 'http'\n\nexport declare type HasHeaders = {\n\theaders: IncomingHttpHeaders\n\tmethod?: string\n\turl?: string\n}\nexport declare type HasStatus = {\n\treadonly statusCode: number\n\treadonly statusMessage: string\n\tstatus: (statusCode: number) => HasStatus\n\tsend: (body: string) => void\n}\nexport declare type ApiHandler<T extends HasHeaders, S extends HasStatus> = (\n\treq: T,\n\tres: S,\n) => unknown | Promise<unknown>\n\n/**\n * Wraps a Pages Router API handler so that its execution runs inside a\n * LaunchDarkly trace, with the session and request linked via incoming headers.\n */\nexport const Highlight =\n\t(env: ObservabilityEnv) =>\n\t<T extends HasHeaders, S extends HasStatus>(\n\t\toriginalHandler: ApiHandler<T, S>,\n\t): ApiHandler<T, S> => {\n\t\treturn async (req, res) => {\n\t\t\tawait registerObservability(env)\n\n\t\t\treturn await LDObserve.runWithHeaders(\n\t\t\t\t`${req.method?.toUpperCase()} - ${sanitizeSpanUrl(req.url)}`,\n\t\t\t\treq.headers,\n\t\t\t\tasync () => {\n\t\t\t\t\treturn await originalHandler(req, res)\n\t\t\t\t},\n\t\t\t)\n\t\t}\n\t}\n","import * as withObservabilityAppRouter from './util/with-observability-app-router'\nimport * as withObservabilityPageRouter from './util/with-observability-page-router'\n\nimport { isNodeJsRuntime } from './util/is-node-js-runtime'\nimport type { ObservabilityEnv } from './util/types'\n\nexport { Handlers, LDObserve } from '@launchdarkly/observability-node'\nexport { observabilityMiddleware } from './util/observability-middleware'\nexport { isNodeJsRuntime } from './util/is-node-js-runtime'\nexport { registerObservability } from './util/register-observability'\nexport type { ObservabilityEnv } from './util/types'\n\ntype PageRouterObservabilityHandler = ReturnType<\n\ttypeof withObservabilityPageRouter.Highlight\n>\n\n/**\n * Default Pages Router wrapper. Alias for {@link PageRouterObservability}.\n */\nexport const Observability = PageRouterObservability\n\n/**\n * Wrap a Pages Router API handler to record LaunchDarkly traces. Only supported\n * in the Node.js runtime.\n */\nexport function PageRouterObservability(\n\tenv: ObservabilityEnv,\n): PageRouterObservabilityHandler {\n\tif (isNodeJsRuntime()) {\n\t\treturn withObservabilityPageRouter.Highlight(env)\n\t}\n\tthrow new Error(`unidentified NEXT_RUNTIME: ${process.env.NEXT_RUNTIME}`)\n}\n\n/**\n * Wrap an App Router route handler to record LaunchDarkly traces. Only supported\n * in the Node.js runtime.\n */\nexport function AppRouterObservability(env: ObservabilityEnv) {\n\tif (isNodeJsRuntime()) {\n\t\treturn withObservabilityAppRouter.Highlight(env)\n\t}\n\tthrow new Error(`unidentified NEXT_RUNTIME: ${process.env.NEXT_RUNTIME}`)\n}\n\n/**\n * Edge runtime is not yet supported by the LaunchDarkly observability node SDK.\n */\nexport function EdgeObservability(_: ObservabilityEnv): never {\n\tthrow new Error(`unsupported NEXT_RUNTIME: ${process.env.NEXT_RUNTIME}`)\n}\n","import { LDObserve } from '@launchdarkly/observability-node'\n\nimport { registerObservability } from './register-observability'\nimport { sanitizeSpanUrl } from './sanitize-url'\nimport type { ObservabilityEnv } from './types'\n\ntype NextContext = {\n\tparams: Promise<Record<string, string>>\n}\ntype NextHandler = (request: Request, context: NextContext) => Promise<Response>\n\n/**\n * Wraps an App Router route handler so that its execution runs inside a\n * LaunchDarkly trace, with the session and request linked via incoming headers.\n */\nexport function Highlight(env: ObservabilityEnv) {\n\treturn (originalHandler: NextHandler) =>\n\t\tasync (request: Request, context: NextContext): Promise<Response> => {\n\t\t\tawait registerObservability(env)\n\n\t\t\treturn await LDObserve.runWithHeaders(\n\t\t\t\t`${request.method?.toUpperCase()} - ${sanitizeSpanUrl(request.url)}`,\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\t\t\trequest.headers as any,\n\t\t\t\tasync () => originalHandler(request, context),\n\t\t\t)\n\t\t}\n}\n"],"names":["initPromise","async","registerObservability","env","isNodeJsRuntime","Observability","import","sdkKey","options","plugin","register","standaloneMetadata","init","catch","err","undefined","console","info","process","NEXT_RUNTIME","sanitizeSpanUrl","url","split","PageRouterObservability","originalHandler","req","res","LDObserve","runWithHeaders","method","toUpperCase","headers","withObservabilityPageRouter.Highlight","Error","request","context","withObservabilityAppRouter.Highlight","_"],"mappings":"yJAIA,IAAIA,EA4BGC,eAAeC,EAAsBC,GAC3C,GAAKC,EAAAA,kBAcL,OAJAJ,IArCDC,eAAoBE,GAGnB,MAAME,cAAEA,SAAwBC,OAAO,qCAEjCC,OAAEA,KAAWC,GAAYL,EACzBM,EAAS,IAAIJ,EAAcG,GAGjCC,EAAOC,WAAW,CAAA,EAAIC,EAAAA,mBAAmBJ,GAC1C,CA2BiBK,CAAKT,GAAKU,MAAOC,IAEhC,MADAd,OAAce,EACRD,IAEAd,EAbNgB,QAAQC,KACP,2DAA2DC,QAAQf,IAAIgB,eAa1E,CCxCM,SAAUC,EAAgBC,GAC/B,OAAKA,EAGEA,EAAIC,MAAM,KAAK,GAAGA,MAAM,KAAK,GAF5B,EAGT,gDCeO,MCTMjB,EAAgBkB,EAMvB,SAAUA,EACfpB,GAEA,GAAIC,EAAAA,kBACH,MDAD,CAACD,GAEAqB,GAEOvB,MAAOwB,EAAKC,WACZxB,EAAsBC,SAEfwB,EAAAA,UAAUC,eACtB,GAAGH,EAAII,QAAQC,mBAAmBV,EAAgBK,EAAIJ,OACtDI,EAAIM,QACJ9B,eACcuB,EAAgBC,EAAKC,KCX9BM,CAAsC7B,GAE9C,MAAM,IAAI8B,MAAM,8BAA8Bf,QAAQf,IAAIgB,eAC3D,8TAMM,SAAiChB,GACtC,GAAIC,EAAAA,kBACH,OCzBI,SAAoBD,GACzB,OAAQqB,GACPvB,MAAOiC,EAAkBC,WAClBjC,EAAsBC,SAEfwB,EAAAA,UAAUC,eACtB,GAAGM,EAAQL,QAAQC,mBAAmBV,EAAgBc,EAAQb,OAE9Da,EAAQH,QACR9B,SAAYuB,EAAgBU,EAASC,IAGzC,CDaSC,CAAqCjC,GAE7C,MAAM,IAAI8B,MAAM,8BAA8Bf,QAAQf,IAAIgB,eAC3D,4BAKM,SAA4BkB,GACjC,MAAM,IAAIJ,MAAM,6BAA6Bf,QAAQf,IAAIgB,eAC1D"}
@@ -0,0 +1,17 @@
1
+ import * as withObservabilityPageRouter from './util/with-observability-page-router';
2
+ import type { ObservabilityEnv } from './util/types';
3
+ export { Handlers, LDObserve } from '@launchdarkly/observability-node';
4
+ export { observabilityMiddleware } from './util/observability-middleware';
5
+ export { isNodeJsRuntime } from './util/is-node-js-runtime';
6
+ export { registerObservability } from './util/register-observability';
7
+ export type { ObservabilityEnv } from './util/types';
8
+ type PageRouterObservabilityHandler = ReturnType<typeof withObservabilityPageRouter.Highlight>;
9
+ export declare const Observability: typeof PageRouterObservability;
10
+ export declare function PageRouterObservability(env: ObservabilityEnv): PageRouterObservabilityHandler;
11
+ export declare function AppRouterObservability(env: ObservabilityEnv): (originalHandler: (request: Request, context: {
12
+ params: Promise<Record<string, string>>;
13
+ }) => Promise<Response>) => (request: Request, context: {
14
+ params: Promise<Record<string, string>>;
15
+ }) => Promise<Response>;
16
+ export declare function EdgeObservability(_: ObservabilityEnv): never;
17
+ //# sourceMappingURL=server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,2BAA2B,MAAM,uCAAuC,CAAA;AAGpF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAEpD,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAA;AACtE,OAAO,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAA;AACzE,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAC3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAA;AACrE,YAAY,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAEpD,KAAK,8BAA8B,GAAG,UAAU,CAC/C,OAAO,2BAA2B,CAAC,SAAS,CAC5C,CAAA;AAKD,eAAO,MAAM,aAAa,gCAA0B,CAAA;AAMpD,wBAAgB,uBAAuB,CACtC,GAAG,EAAE,gBAAgB,GACnB,8BAA8B,CAKhC;AAMD,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,gBAAgB;;6BA1BrC,gBAAgB,EAAC;;CAC7B,uBA8BV;AAKD,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,gBAAgB,GAAG,KAAK,CAE5D"}
@@ -0,0 +1,2 @@
1
+ "use strict";var e=require("./observability-middleware-CH0Vm0ev.js");require("next/headers"),require("next/server");const r=e=>{throw new Error(`${e} is not supported in the edge runtime. The OpenTelemetry-based node SDK that powers server-side observability is not edge-compatible.`)},t=new Proxy({},{get:()=>r("LDObserve")}),i=new Proxy({},{get:()=>r("Handlers")});exports.isNodeJsRuntime=e.isNodeJsRuntime,exports.observabilityMiddleware=e.observabilityMiddleware,exports.AppRouterObservability=function(e){throw new Error("Do not use AppRouterObservability() in the edge runtime.")},exports.EdgeObservability=function(e){throw new Error(`unsupported NEXT_RUNTIME: ${process.env.NEXT_RUNTIME}`)},exports.Handlers=i,exports.LDObserve=t,exports.PageRouterObservability=function(e){throw new Error("Do not use PageRouterObservability() in the edge runtime.")},exports.registerObservability=async function(e){};
2
+ //# sourceMappingURL=server.edge.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.edge.cjs","sources":["../src/server.edge.ts"],"sourcesContent":["import type { ObservabilityEnv } from './util/types'\n\nexport { observabilityMiddleware } from './util/observability-middleware'\nexport { isNodeJsRuntime } from './util/is-node-js-runtime'\nexport type { ObservabilityEnv } from './util/types'\n\n// `import type` is erased at build time, so referencing the node SDK here keeps\n// `server.edge.js` free of any runtime `@launchdarkly/observability-node`\n// import while letting the edge build expose the same `/server` surface as the\n// Node build.\ntype Observe = import('@launchdarkly/observability-node').Observe\ntype HandlersNamespace =\n\ttypeof import('@launchdarkly/observability-node').Handlers\n\nconst edgeUnsupported = (name: string): never => {\n\tthrow new Error(\n\t\t`${name} is not supported in the edge runtime. The OpenTelemetry-based ` +\n\t\t\t`node SDK that powers server-side observability is not edge-compatible.`,\n\t)\n}\n\n/**\n * Edge-runtime stub for the manual-tracking singleton. Re-exported so importing\n * `LDObserve` from `@launchdarkly/observability-next/server` in edge code\n * resolves at bundle time (matching the Node build and `server.d.ts`); any\n * access throws a clear error instead of failing as a missing export.\n */\nexport const LDObserve: Observe = new Proxy({} as Observe, {\n\tget() {\n\t\treturn edgeUnsupported('LDObserve')\n\t},\n})\n\n/**\n * Edge-runtime stub for the request handlers. See {@link LDObserve} for why this\n * is re-exported rather than omitted.\n */\nexport const Handlers: HandlersNamespace = new Proxy({} as HandlersNamespace, {\n\tget() {\n\t\treturn edgeUnsupported('Handlers')\n\t},\n})\n\n/**\n * No-op in the edge runtime. The OpenTelemetry-based node SDK that powers\n * server-side observability is not edge-compatible, so initialization only\n * happens in the Node.js runtime.\n */\nexport async function registerObservability(_: ObservabilityEnv) {}\n\nexport function PageRouterObservability(_: ObservabilityEnv): never {\n\tthrow new Error('Do not use PageRouterObservability() in the edge runtime.')\n}\n\nexport function AppRouterObservability(_: ObservabilityEnv): never {\n\tthrow new Error('Do not use AppRouterObservability() in the edge runtime.')\n}\n\nexport function EdgeObservability(_: ObservabilityEnv): never {\n\tthrow new Error(`unsupported NEXT_RUNTIME: ${process.env.NEXT_RUNTIME}`)\n}\n"],"names":["edgeUnsupported","name","Error","LDObserve","Proxy","get","Handlers","_","process","env","NEXT_RUNTIME","async"],"mappings":"oHAcA,MAAMA,EAAmBC,IACxB,MAAM,IAAIC,MACT,GAAGD,2IAWQE,EAAqB,IAAIC,MAAM,GAAe,CAC1DC,IAAG,IACKL,EAAgB,eAQZM,EAA8B,IAAIF,MAAM,GAAyB,CAC7EC,IAAG,IACKL,EAAgB,iJAenB,SAAiCO,GACtC,MAAM,IAAIL,MAAM,2DACjB,4BAEM,SAA4BK,GACjC,MAAM,IAAIL,MAAM,6BAA6BM,QAAQC,IAAIC,eAC1D,yEAVM,SAAkCH,GACvC,MAAM,IAAIL,MAAM,4DACjB,gCAJOS,eAAqCJ,GAAsB"}
@@ -0,0 +1,13 @@
1
+ import type { ObservabilityEnv } from './util/types';
2
+ export { observabilityMiddleware } from './util/observability-middleware';
3
+ export { isNodeJsRuntime } from './util/is-node-js-runtime';
4
+ export type { ObservabilityEnv } from './util/types';
5
+ type Observe = import('@launchdarkly/observability-node').Observe;
6
+ type HandlersNamespace = typeof import('@launchdarkly/observability-node').Handlers;
7
+ export declare const LDObserve: Observe;
8
+ export declare const Handlers: HandlersNamespace;
9
+ export declare function registerObservability(_: ObservabilityEnv): Promise<void>;
10
+ export declare function PageRouterObservability(_: ObservabilityEnv): never;
11
+ export declare function AppRouterObservability(_: ObservabilityEnv): never;
12
+ export declare function EdgeObservability(_: ObservabilityEnv): never;
13
+ //# sourceMappingURL=server.edge.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.edge.d.ts","sourceRoot":"","sources":["../src/server.edge.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAEpD,OAAO,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAA;AACzE,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAC3D,YAAY,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAMpD,KAAK,OAAO,GAAG,OAAO,kCAAkC,EAAE,OAAO,CAAA;AACjE,KAAK,iBAAiB,GACrB,cAAc,kCAAkC,EAAE,QAAQ,CAAA;AAe3D,eAAO,MAAM,SAAS,EAAE,OAItB,CAAA;AAMF,eAAO,MAAM,QAAQ,EAAE,iBAIrB,CAAA;AAOF,wBAAsB,qBAAqB,CAAC,CAAC,EAAE,gBAAgB,iBAAI;AAEnE,wBAAgB,uBAAuB,CAAC,CAAC,EAAE,gBAAgB,GAAG,KAAK,CAElE;AAED,wBAAgB,sBAAsB,CAAC,CAAC,EAAE,gBAAgB,GAAG,KAAK,CAEjE;AAED,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,gBAAgB,GAAG,KAAK,CAE5D"}
@@ -0,0 +1,2 @@
1
+ export{i as isNodeJsRuntime,o as observabilityMiddleware}from"./observability-middleware-D4dJiJoK.js";import"next/headers";import"next/server";const e=e=>{throw new Error(`${e} is not supported in the edge runtime. The OpenTelemetry-based node SDK that powers server-side observability is not edge-compatible.`)},r=new Proxy({},{get:()=>e("LDObserve")}),t=new Proxy({},{get:()=>e("Handlers")});async function n(e){}function s(e){throw new Error("Do not use PageRouterObservability() in the edge runtime.")}function a(e){throw new Error("Do not use AppRouterObservability() in the edge runtime.")}function d(e){throw new Error(`unsupported NEXT_RUNTIME: ${process.env.NEXT_RUNTIME}`)}export{a as AppRouterObservability,d as EdgeObservability,t as Handlers,r as LDObserve,s as PageRouterObservability,n as registerObservability};
2
+ //# sourceMappingURL=server.edge.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.edge.js","sources":["../src/server.edge.ts"],"sourcesContent":["import type { ObservabilityEnv } from './util/types'\n\nexport { observabilityMiddleware } from './util/observability-middleware'\nexport { isNodeJsRuntime } from './util/is-node-js-runtime'\nexport type { ObservabilityEnv } from './util/types'\n\n// `import type` is erased at build time, so referencing the node SDK here keeps\n// `server.edge.js` free of any runtime `@launchdarkly/observability-node`\n// import while letting the edge build expose the same `/server` surface as the\n// Node build.\ntype Observe = import('@launchdarkly/observability-node').Observe\ntype HandlersNamespace =\n\ttypeof import('@launchdarkly/observability-node').Handlers\n\nconst edgeUnsupported = (name: string): never => {\n\tthrow new Error(\n\t\t`${name} is not supported in the edge runtime. The OpenTelemetry-based ` +\n\t\t\t`node SDK that powers server-side observability is not edge-compatible.`,\n\t)\n}\n\n/**\n * Edge-runtime stub for the manual-tracking singleton. Re-exported so importing\n * `LDObserve` from `@launchdarkly/observability-next/server` in edge code\n * resolves at bundle time (matching the Node build and `server.d.ts`); any\n * access throws a clear error instead of failing as a missing export.\n */\nexport const LDObserve: Observe = new Proxy({} as Observe, {\n\tget() {\n\t\treturn edgeUnsupported('LDObserve')\n\t},\n})\n\n/**\n * Edge-runtime stub for the request handlers. See {@link LDObserve} for why this\n * is re-exported rather than omitted.\n */\nexport const Handlers: HandlersNamespace = new Proxy({} as HandlersNamespace, {\n\tget() {\n\t\treturn edgeUnsupported('Handlers')\n\t},\n})\n\n/**\n * No-op in the edge runtime. The OpenTelemetry-based node SDK that powers\n * server-side observability is not edge-compatible, so initialization only\n * happens in the Node.js runtime.\n */\nexport async function registerObservability(_: ObservabilityEnv) {}\n\nexport function PageRouterObservability(_: ObservabilityEnv): never {\n\tthrow new Error('Do not use PageRouterObservability() in the edge runtime.')\n}\n\nexport function AppRouterObservability(_: ObservabilityEnv): never {\n\tthrow new Error('Do not use AppRouterObservability() in the edge runtime.')\n}\n\nexport function EdgeObservability(_: ObservabilityEnv): never {\n\tthrow new Error(`unsupported NEXT_RUNTIME: ${process.env.NEXT_RUNTIME}`)\n}\n"],"names":["edgeUnsupported","name","Error","LDObserve","Proxy","get","Handlers","async","registerObservability","_","PageRouterObservability","AppRouterObservability","EdgeObservability","process","env","NEXT_RUNTIME"],"mappings":"+IAcA,MAAMA,EAAmBC,IACxB,MAAM,IAAIC,MACT,GAAGD,2IAWQE,EAAqB,IAAIC,MAAM,GAAe,CAC1DC,IAAG,IACKL,EAAgB,eAQZM,EAA8B,IAAIF,MAAM,GAAyB,CAC7EC,IAAG,IACKL,EAAgB,cASlBO,eAAeC,EAAsBC,GAAsB,CAE5D,SAAUC,EAAwBD,GACvC,MAAM,IAAIP,MAAM,4DACjB,CAEM,SAAUS,EAAuBF,GACtC,MAAM,IAAIP,MAAM,2DACjB,CAEM,SAAUU,EAAkBH,GACjC,MAAM,IAAIP,MAAM,6BAA6BW,QAAQC,IAAIC,eAC1D"}
package/dist/server.js ADDED
@@ -0,0 +1,2 @@
1
+ import{LDObserve as r}from"@launchdarkly/observability-node";export{Handlers,LDObserve}from"@launchdarkly/observability-node";import{i as e}from"./observability-middleware-D4dJiJoK.js";export{o as observabilityMiddleware}from"./observability-middleware-D4dJiJoK.js";import{s as t}from"./standalone-CkwD29IP.js";import"next/headers";import"next/server";let n;async function i(r){if(e())return n??=async function(r){const{Observability:e}=await import("@launchdarkly/observability-node"),{sdkKey:n,...i}=r,o=new e(i);o.register?.({},t(n))}(r).catch(r=>{throw n=void 0,r}),n;console.info(`LaunchDarkly observability not registered: NEXT_RUNTIME=${process.env.NEXT_RUNTIME}`)}function a(r){return r?r.split("#")[0].split("?")[0]:""}const s=d;function d(t){if(e())return(e=>t=>async(n,o)=>(await i(e),await r.runWithHeaders(`${n.method?.toUpperCase()} - ${a(n.url)}`,n.headers,async()=>await t(n,o))))(t);throw new Error(`unidentified NEXT_RUNTIME: ${process.env.NEXT_RUNTIME}`)}function c(t){if(e())return function(e){return t=>async(n,o)=>(await i(e),await r.runWithHeaders(`${n.method?.toUpperCase()} - ${a(n.url)}`,n.headers,async()=>t(n,o)))}(t);throw new Error(`unidentified NEXT_RUNTIME: ${process.env.NEXT_RUNTIME}`)}function l(r){throw new Error(`unsupported NEXT_RUNTIME: ${process.env.NEXT_RUNTIME}`)}export{c as AppRouterObservability,l as EdgeObservability,s as Observability,d as PageRouterObservability,e as isNodeJsRuntime,i as registerObservability};
2
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.js","sources":["../src/util/register-observability.ts","../src/util/sanitize-url.ts","../src/util/with-observability-page-router.ts","../src/server.ts","../src/util/with-observability-app-router.ts"],"sourcesContent":["import { isNodeJsRuntime } from './is-node-js-runtime'\nimport { standaloneMetadata, type StandalonePlugin } from './standalone'\nimport type { ObservabilityEnv } from './types'\n\nlet initPromise: Promise<void> | undefined\n\nasync function init(env: ObservabilityEnv) {\n\t// Import lazily so the OpenTelemetry/node dependencies are never pulled into\n\t// an edge bundle.\n\tconst { Observability } = await import('@launchdarkly/observability-node')\n\n\tconst { sdkKey, ...options } = env\n\tconst plugin = new Observability(options) as unknown as StandalonePlugin\n\t// `register` ignores the client argument and initializes LDObserve from the\n\t// SDK key in the metadata. See util/standalone.ts.\n\tplugin.register?.({}, standaloneMetadata(sdkKey))\n}\n\n/**\n * Initialize the server-side LaunchDarkly observability plugin in standalone\n * mode. Call this from your Next.js `instrumentation.ts` `register()` hook.\n *\n * Initialization only happens in the Node.js runtime; in the edge runtime this\n * is a no-op (the OpenTelemetry-based node SDK is not edge-compatible). It is\n * idempotent and concurrency-safe, so route-handler wrappers can safely await\n * it on every request.\n *\n * `LDObserve` is a process-global singleton that can only be initialized once,\n * so the first successful call wins and later calls reuse it. All callers\n * (`instrumentation.ts` and any route wrappers) should therefore pass the same\n * `env` — initialize once in `instrumentation.ts` for the canonical config.\n */\nexport async function registerObservability(env: ObservabilityEnv) {\n\tif (!isNodeJsRuntime()) {\n\t\tconsole.info(\n\t\t\t`LaunchDarkly observability not registered: NEXT_RUNTIME=${process.env.NEXT_RUNTIME}`,\n\t\t)\n\t\treturn\n\t}\n\n\t// Cache the in-flight/successful init, but drop the cached promise if it\n\t// rejects so a failed import or registration can be retried on a later\n\t// call rather than poisoning every subsequent request.\n\tinitPromise ??= init(env).catch((err) => {\n\t\tinitPromise = undefined\n\t\tthrow err\n\t})\n\treturn initPromise\n}\n","/**\n * Strip the query string and fragment from a URL before it is used as an\n * OpenTelemetry span name. Query params and hash fragments can carry secrets\n * (OAuth tokens, auth codes, signed URLs); span names are exported to the\n * tracing backend, so the high-cardinality, potentially-sensitive tail must be\n * dropped. Works for both absolute URLs (`request.url`) and request-relative\n * paths (`req.url` in the Pages Router).\n */\nexport function sanitizeSpanUrl(url: string | undefined): string {\n\tif (!url) {\n\t\treturn ''\n\t}\n\treturn url.split('#')[0].split('?')[0]\n}\n","import { LDObserve } from '@launchdarkly/observability-node'\n\nimport { registerObservability } from './register-observability'\nimport { sanitizeSpanUrl } from './sanitize-url'\nimport type { ObservabilityEnv } from './types'\n\nimport type { IncomingHttpHeaders } from 'http'\n\nexport declare type HasHeaders = {\n\theaders: IncomingHttpHeaders\n\tmethod?: string\n\turl?: string\n}\nexport declare type HasStatus = {\n\treadonly statusCode: number\n\treadonly statusMessage: string\n\tstatus: (statusCode: number) => HasStatus\n\tsend: (body: string) => void\n}\nexport declare type ApiHandler<T extends HasHeaders, S extends HasStatus> = (\n\treq: T,\n\tres: S,\n) => unknown | Promise<unknown>\n\n/**\n * Wraps a Pages Router API handler so that its execution runs inside a\n * LaunchDarkly trace, with the session and request linked via incoming headers.\n */\nexport const Highlight =\n\t(env: ObservabilityEnv) =>\n\t<T extends HasHeaders, S extends HasStatus>(\n\t\toriginalHandler: ApiHandler<T, S>,\n\t): ApiHandler<T, S> => {\n\t\treturn async (req, res) => {\n\t\t\tawait registerObservability(env)\n\n\t\t\treturn await LDObserve.runWithHeaders(\n\t\t\t\t`${req.method?.toUpperCase()} - ${sanitizeSpanUrl(req.url)}`,\n\t\t\t\treq.headers,\n\t\t\t\tasync () => {\n\t\t\t\t\treturn await originalHandler(req, res)\n\t\t\t\t},\n\t\t\t)\n\t\t}\n\t}\n","import * as withObservabilityAppRouter from './util/with-observability-app-router'\nimport * as withObservabilityPageRouter from './util/with-observability-page-router'\n\nimport { isNodeJsRuntime } from './util/is-node-js-runtime'\nimport type { ObservabilityEnv } from './util/types'\n\nexport { Handlers, LDObserve } from '@launchdarkly/observability-node'\nexport { observabilityMiddleware } from './util/observability-middleware'\nexport { isNodeJsRuntime } from './util/is-node-js-runtime'\nexport { registerObservability } from './util/register-observability'\nexport type { ObservabilityEnv } from './util/types'\n\ntype PageRouterObservabilityHandler = ReturnType<\n\ttypeof withObservabilityPageRouter.Highlight\n>\n\n/**\n * Default Pages Router wrapper. Alias for {@link PageRouterObservability}.\n */\nexport const Observability = PageRouterObservability\n\n/**\n * Wrap a Pages Router API handler to record LaunchDarkly traces. Only supported\n * in the Node.js runtime.\n */\nexport function PageRouterObservability(\n\tenv: ObservabilityEnv,\n): PageRouterObservabilityHandler {\n\tif (isNodeJsRuntime()) {\n\t\treturn withObservabilityPageRouter.Highlight(env)\n\t}\n\tthrow new Error(`unidentified NEXT_RUNTIME: ${process.env.NEXT_RUNTIME}`)\n}\n\n/**\n * Wrap an App Router route handler to record LaunchDarkly traces. Only supported\n * in the Node.js runtime.\n */\nexport function AppRouterObservability(env: ObservabilityEnv) {\n\tif (isNodeJsRuntime()) {\n\t\treturn withObservabilityAppRouter.Highlight(env)\n\t}\n\tthrow new Error(`unidentified NEXT_RUNTIME: ${process.env.NEXT_RUNTIME}`)\n}\n\n/**\n * Edge runtime is not yet supported by the LaunchDarkly observability node SDK.\n */\nexport function EdgeObservability(_: ObservabilityEnv): never {\n\tthrow new Error(`unsupported NEXT_RUNTIME: ${process.env.NEXT_RUNTIME}`)\n}\n","import { LDObserve } from '@launchdarkly/observability-node'\n\nimport { registerObservability } from './register-observability'\nimport { sanitizeSpanUrl } from './sanitize-url'\nimport type { ObservabilityEnv } from './types'\n\ntype NextContext = {\n\tparams: Promise<Record<string, string>>\n}\ntype NextHandler = (request: Request, context: NextContext) => Promise<Response>\n\n/**\n * Wraps an App Router route handler so that its execution runs inside a\n * LaunchDarkly trace, with the session and request linked via incoming headers.\n */\nexport function Highlight(env: ObservabilityEnv) {\n\treturn (originalHandler: NextHandler) =>\n\t\tasync (request: Request, context: NextContext): Promise<Response> => {\n\t\t\tawait registerObservability(env)\n\n\t\t\treturn await LDObserve.runWithHeaders(\n\t\t\t\t`${request.method?.toUpperCase()} - ${sanitizeSpanUrl(request.url)}`,\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\t\t\trequest.headers as any,\n\t\t\t\tasync () => originalHandler(request, context),\n\t\t\t)\n\t\t}\n}\n"],"names":["initPromise","async","registerObservability","env","isNodeJsRuntime","Observability","import","sdkKey","options","plugin","register","standaloneMetadata","init","catch","err","undefined","console","info","process","NEXT_RUNTIME","sanitizeSpanUrl","url","split","PageRouterObservability","originalHandler","req","res","LDObserve","runWithHeaders","method","toUpperCase","headers","withObservabilityPageRouter.Highlight","Error","AppRouterObservability","request","context","withObservabilityAppRouter.Highlight","EdgeObservability","_"],"mappings":"gWAIA,IAAIA,EA4BGC,eAAeC,EAAsBC,GAC3C,GAAKC,IAcL,OAJAJ,IArCDC,eAAoBE,GAGnB,MAAME,cAAEA,SAAwBC,OAAO,qCAEjCC,OAAEA,KAAWC,GAAYL,EACzBM,EAAS,IAAIJ,EAAcG,GAGjCC,EAAOC,WAAW,CAAA,EAAIC,EAAmBJ,GAC1C,CA2BiBK,CAAKT,GAAKU,MAAOC,IAEhC,MADAd,OAAce,EACRD,IAEAd,EAbNgB,QAAQC,KACP,2DAA2DC,QAAQf,IAAIgB,eAa1E,CCxCM,SAAUC,EAAgBC,GAC/B,OAAKA,EAGEA,EAAIC,MAAM,KAAK,GAAGA,MAAM,KAAK,GAF5B,EAGT,CCeO,MCTMjB,EAAgBkB,EAMvB,SAAUA,EACfpB,GAEA,GAAIC,IACH,MDAD,CAACD,GAEAqB,GAEOvB,MAAOwB,EAAKC,WACZxB,EAAsBC,SAEfwB,EAAUC,eACtB,GAAGH,EAAII,QAAQC,mBAAmBV,EAAgBK,EAAIJ,OACtDI,EAAIM,QACJ9B,eACcuB,EAAgBC,EAAKC,KCX9BM,CAAsC7B,GAE9C,MAAM,IAAI8B,MAAM,8BAA8Bf,QAAQf,IAAIgB,eAC3D,CAMM,SAAUe,EAAuB/B,GACtC,GAAIC,IACH,OCzBI,SAAoBD,GACzB,OAAQqB,GACPvB,MAAOkC,EAAkBC,WAClBlC,EAAsBC,SAEfwB,EAAUC,eACtB,GAAGO,EAAQN,QAAQC,mBAAmBV,EAAgBe,EAAQd,OAE9Dc,EAAQJ,QACR9B,SAAYuB,EAAgBW,EAASC,IAGzC,CDaSC,CAAqClC,GAE7C,MAAM,IAAI8B,MAAM,8BAA8Bf,QAAQf,IAAIgB,eAC3D,CAKM,SAAUmB,EAAkBC,GACjC,MAAM,IAAIN,MAAM,6BAA6Bf,QAAQf,IAAIgB,eAC1D"}
package/dist/ssr.cjs ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";var r=require("react/jsx-runtime"),e=require("@launchdarkly/observability"),s=require("next/error.js"),t=require("react"),o=require("./standalone-CQH9Vh11.js"),n=require("./error-boundary-CUcyBTHj.js");function u({res:r,err:e}){const s=r?.statusCode??e?.statusCode??500;return{errorMessage:r?.statusMessage??e?.message??"An error occurred",statusCode:s}}Object.defineProperty(exports,"LDObserve",{enumerable:!0,get:function(){return e.LDObserve}}),exports.ErrorBoundary=n.ErrorBoundary,exports.appRouterSsrErrorHandler=function(s){return({error:o,reset:n})=>(t.useEffect(()=>{e.LDObserve.recordError(o)},[o]),r.jsx(s,{error:o,reset:n}))},exports.getLDErrorInitialProps=u,exports.pageRouterCustomErrorHandler=function(n,a){const{sdkKey:i,application:c,...d}=n,p=n=>(t.useEffect(()=>{i&&o.ensureStandaloneInit("observe",()=>new e(d),i,c),e.LDObserve.recordError(new Error(n.errorMessage))},[n.errorMessage]),a?r.jsx(a,{...n}):r.jsx(s,{...n}));return p.getInitialProps=u,p};
2
+ //# sourceMappingURL=ssr.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ssr.cjs","sources":["../src/ssr.tsx"],"sourcesContent":["import Observability, {\n\tLDObserve,\n\ttype ObserveOptions,\n} from '@launchdarkly/observability'\nimport type { NextPageContext } from 'next'\nimport NextError, { ErrorProps } from 'next/error.js'\nimport React, { useEffect } from 'react'\n\nimport { ensureStandaloneInit, type LDApplicationInfo } from './util/standalone'\n\nexport { ErrorBoundary } from './error-boundary'\nexport { LDObserve }\n\nexport interface LDObservabilityInitProps extends ObserveOptions {\n\t/** The LaunchDarkly client-side ID (SDK key). */\n\tsdkKey?: string\n\t/** Application metadata (id / version) tagged onto telemetry. */\n\tapplication?: LDApplicationInfo\n}\n\nexport type LDErrorProps = { errorMessage: string } & ErrorProps\n\nexport function getLDErrorInitialProps({\n\tres,\n\terr,\n}: NextPageContext): LDErrorProps {\n\tconst statusCode = res?.statusCode ?? err?.statusCode ?? 500\n\tconst errorMessage =\n\t\tres?.statusMessage ?? err?.message ?? 'An error occurred'\n\n\treturn { errorMessage, statusCode }\n}\n\nexport type PageRouterErrorProps = LDErrorProps\n\n/**\n * Pages Router custom `_error` page handler. Initializes observability in\n * standalone mode (if not already running) and records the rendered error.\n */\nexport function pageRouterCustomErrorHandler(\n\tinitProps: LDObservabilityInitProps,\n\tChild?: React.FC<LDErrorProps>,\n) {\n\tconst { sdkKey, application, ...options } = initProps\n\n\tconst handler = (props: LDErrorProps) => {\n\t\t// Record inside an effect (keyed on the message) rather than during\n\t\t// render so a re-render of the `_error` page does not emit duplicate\n\t\t// error events for the same failure. Mirrors appRouterSsrErrorHandler.\n\t\tuseEffect(() => {\n\t\t\tif (sdkKey) {\n\t\t\t\tensureStandaloneInit(\n\t\t\t\t\t'observe',\n\t\t\t\t\t() => new Observability(options),\n\t\t\t\t\tsdkKey,\n\t\t\t\t\tapplication,\n\t\t\t\t)\n\t\t\t}\n\t\t\tLDObserve.recordError(new Error(props.errorMessage))\n\t\t}, [props.errorMessage])\n\n\t\treturn Child ? <Child {...props} /> : <NextError {...props} />\n\t}\n\n\thandler.getInitialProps = getLDErrorInitialProps\n\n\treturn handler\n}\n\nexport type AppRouterErrorProps = {\n\terror: Error & { digest?: string }\n\treset: () => void\n}\n\n/**\n * App Router `error.tsx` wrapper. Records the error to LaunchDarkly (which must\n * already be initialized via {@link LDObservabilityInit}) and renders your error\n * UI.\n */\nexport function appRouterSsrErrorHandler(Child: React.FC<AppRouterErrorProps>) {\n\treturn ({ error, reset }: AppRouterErrorProps) => {\n\t\tuseEffect(() => {\n\t\t\tLDObserve.recordError(error)\n\t\t}, [error])\n\n\t\treturn <Child error={error} reset={reset} />\n\t}\n}\n"],"names":["getLDErrorInitialProps","res","err","statusCode","errorMessage","statusMessage","message","Child","error","reset","useEffect","LDObserve","recordError","_jsx","initProps","sdkKey","application","options","handler","props","ensureStandaloneInit","Observability","Error","NextError","getInitialProps"],"mappings":"gOAsBgBA,GAAuBC,IACtCA,EAAGC,IACHA,IAEA,MAAMC,EAAaF,GAAKE,YAAcD,GAAKC,YAAc,IAIzD,MAAO,CAAEC,aAFRH,GAAKI,eAAiBH,GAAKI,SAAW,oBAEhBH,aACxB,sKAgDM,SAAmCI,GACxC,MAAO,EAAGC,QAAOC,YAChBC,EAAAA,UAAU,KACTC,EAAAA,UAAUC,YAAYJ,IACpB,CAACA,IAEGK,EAAAA,IAACN,EAAK,CAACC,MAAOA,EAAOC,MAAOA,IAErC,wEAhDM,SACLK,EACAP,GAEA,MAAMQ,OAAEA,EAAMC,YAAEA,KAAgBC,GAAYH,EAEtCI,EAAWC,IAIhBT,EAAAA,UAAU,KACLK,GACHK,EAAAA,qBACC,UACA,IAAM,IAAIC,EAAcJ,GACxBF,EACAC,GAGFL,EAAAA,UAAUC,YAAY,IAAIU,MAAMH,EAAMf,gBACpC,CAACe,EAAMf,eAEHG,EAAQM,EAAAA,IAACN,EAAK,IAAKY,IAAYN,MAACU,EAAS,IAAKJ,KAKtD,OAFAD,EAAQM,gBAAkBxB,EAEnBkB,CACR"}
package/dist/ssr.d.ts ADDED
@@ -0,0 +1,28 @@
1
+ import { LDObserve, type ObserveOptions } from '@launchdarkly/observability';
2
+ import type { NextPageContext } from 'next';
3
+ import { ErrorProps } from 'next/error.js';
4
+ import React from 'react';
5
+ import { type LDApplicationInfo } from './util/standalone';
6
+ export { ErrorBoundary } from './error-boundary';
7
+ export { LDObserve };
8
+ export interface LDObservabilityInitProps extends ObserveOptions {
9
+ sdkKey?: string;
10
+ application?: LDApplicationInfo;
11
+ }
12
+ export type LDErrorProps = {
13
+ errorMessage: string;
14
+ } & ErrorProps;
15
+ export declare function getLDErrorInitialProps({ res, err, }: NextPageContext): LDErrorProps;
16
+ export type PageRouterErrorProps = LDErrorProps;
17
+ export declare function pageRouterCustomErrorHandler(initProps: LDObservabilityInitProps, Child?: React.FC<LDErrorProps>): {
18
+ (props: LDErrorProps): import("react/jsx-runtime").JSX.Element;
19
+ getInitialProps: typeof getLDErrorInitialProps;
20
+ };
21
+ export type AppRouterErrorProps = {
22
+ error: Error & {
23
+ digest?: string;
24
+ };
25
+ reset: () => void;
26
+ };
27
+ export declare function appRouterSsrErrorHandler(Child: React.FC<AppRouterErrorProps>): ({ error, reset }: AppRouterErrorProps) => import("react/jsx-runtime").JSX.Element;
28
+ //# sourceMappingURL=ssr.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ssr.d.ts","sourceRoot":"","sources":["../src/ssr.tsx"],"names":[],"mappings":"AAAA,OAAsB,EACrB,SAAS,EACT,KAAK,cAAc,EACnB,MAAM,6BAA6B,CAAA;AACpC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,MAAM,CAAA;AAC3C,OAAkB,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AACrD,OAAO,KAAoB,MAAM,OAAO,CAAA;AAExC,OAAO,EAAwB,KAAK,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AAEhF,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAChD,OAAO,EAAE,SAAS,EAAE,CAAA;AAEpB,MAAM,WAAW,wBAAyB,SAAQ,cAAc;IAE/D,MAAM,CAAC,EAAE,MAAM,CAAA;IAEf,WAAW,CAAC,EAAE,iBAAiB,CAAA;CAC/B;AAED,MAAM,MAAM,YAAY,GAAG;IAAE,YAAY,EAAE,MAAM,CAAA;CAAE,GAAG,UAAU,CAAA;AAEhE,wBAAgB,sBAAsB,CAAC,EACtC,GAAG,EACH,GAAG,GACH,EAAE,eAAe,GAAG,YAAY,CAMhC;AAED,MAAM,MAAM,oBAAoB,GAAG,YAAY,CAAA;AAM/C,wBAAgB,4BAA4B,CAC3C,SAAS,EAAE,wBAAwB,EACnC,KAAK,CAAC,EAAE,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC;YAIN,YAAY;;EAsBpC;AAED,MAAM,MAAM,mBAAmB,GAAG;IACjC,KAAK,EAAE,KAAK,GAAG;QAAE,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;IAClC,KAAK,EAAE,MAAM,IAAI,CAAA;CACjB,CAAA;AAOD,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,KAAK,CAAC,EAAE,CAAC,mBAAmB,CAAC,IACpE,kBAAkB,mBAAmB,6CAO7C"}
package/dist/ssr.js ADDED
@@ -0,0 +1,2 @@
1
+ import{jsx as r}from"react/jsx-runtime";import e,{LDObserve as o}from"@launchdarkly/observability";export{LDObserve}from"@launchdarkly/observability";import s from"next/error.js";import{useEffect as t}from"react";import{e as a}from"./standalone-CkwD29IP.js";export{E as ErrorBoundary}from"./error-boundary-CSJNDDPj.js";function n({res:r,err:e}){const o=r?.statusCode??e?.statusCode??500;return{errorMessage:r?.statusMessage??e?.message??"An error occurred",statusCode:o}}function i(i,u){const{sdkKey:c,application:m,...d}=i,p=n=>(t(()=>{c&&a("observe",()=>new e(d),c,m),o.recordError(new Error(n.errorMessage))},[n.errorMessage]),r(u||s,{...n}));return p.getInitialProps=n,p}function u(e){return({error:s,reset:a})=>(t(()=>{o.recordError(s)},[s]),r(e,{error:s,reset:a}))}export{u as appRouterSsrErrorHandler,n as getLDErrorInitialProps,i as pageRouterCustomErrorHandler};
2
+ //# sourceMappingURL=ssr.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ssr.js","sources":["../src/ssr.tsx"],"sourcesContent":["import Observability, {\n\tLDObserve,\n\ttype ObserveOptions,\n} from '@launchdarkly/observability'\nimport type { NextPageContext } from 'next'\nimport NextError, { ErrorProps } from 'next/error.js'\nimport React, { useEffect } from 'react'\n\nimport { ensureStandaloneInit, type LDApplicationInfo } from './util/standalone'\n\nexport { ErrorBoundary } from './error-boundary'\nexport { LDObserve }\n\nexport interface LDObservabilityInitProps extends ObserveOptions {\n\t/** The LaunchDarkly client-side ID (SDK key). */\n\tsdkKey?: string\n\t/** Application metadata (id / version) tagged onto telemetry. */\n\tapplication?: LDApplicationInfo\n}\n\nexport type LDErrorProps = { errorMessage: string } & ErrorProps\n\nexport function getLDErrorInitialProps({\n\tres,\n\terr,\n}: NextPageContext): LDErrorProps {\n\tconst statusCode = res?.statusCode ?? err?.statusCode ?? 500\n\tconst errorMessage =\n\t\tres?.statusMessage ?? err?.message ?? 'An error occurred'\n\n\treturn { errorMessage, statusCode }\n}\n\nexport type PageRouterErrorProps = LDErrorProps\n\n/**\n * Pages Router custom `_error` page handler. Initializes observability in\n * standalone mode (if not already running) and records the rendered error.\n */\nexport function pageRouterCustomErrorHandler(\n\tinitProps: LDObservabilityInitProps,\n\tChild?: React.FC<LDErrorProps>,\n) {\n\tconst { sdkKey, application, ...options } = initProps\n\n\tconst handler = (props: LDErrorProps) => {\n\t\t// Record inside an effect (keyed on the message) rather than during\n\t\t// render so a re-render of the `_error` page does not emit duplicate\n\t\t// error events for the same failure. Mirrors appRouterSsrErrorHandler.\n\t\tuseEffect(() => {\n\t\t\tif (sdkKey) {\n\t\t\t\tensureStandaloneInit(\n\t\t\t\t\t'observe',\n\t\t\t\t\t() => new Observability(options),\n\t\t\t\t\tsdkKey,\n\t\t\t\t\tapplication,\n\t\t\t\t)\n\t\t\t}\n\t\t\tLDObserve.recordError(new Error(props.errorMessage))\n\t\t}, [props.errorMessage])\n\n\t\treturn Child ? <Child {...props} /> : <NextError {...props} />\n\t}\n\n\thandler.getInitialProps = getLDErrorInitialProps\n\n\treturn handler\n}\n\nexport type AppRouterErrorProps = {\n\terror: Error & { digest?: string }\n\treset: () => void\n}\n\n/**\n * App Router `error.tsx` wrapper. Records the error to LaunchDarkly (which must\n * already be initialized via {@link LDObservabilityInit}) and renders your error\n * UI.\n */\nexport function appRouterSsrErrorHandler(Child: React.FC<AppRouterErrorProps>) {\n\treturn ({ error, reset }: AppRouterErrorProps) => {\n\t\tuseEffect(() => {\n\t\t\tLDObserve.recordError(error)\n\t\t}, [error])\n\n\t\treturn <Child error={error} reset={reset} />\n\t}\n}\n"],"names":["getLDErrorInitialProps","res","err","statusCode","errorMessage","statusMessage","message","pageRouterCustomErrorHandler","initProps","Child","sdkKey","application","options","handler","props","useEffect","ensureStandaloneInit","Observability","LDObserve","recordError","Error","_jsx","NextError","getInitialProps","appRouterSsrErrorHandler","error","reset"],"mappings":"wUAsBgBA,GAAuBC,IACtCA,EAAGC,IACHA,IAEA,MAAMC,EAAaF,GAAKE,YAAcD,GAAKC,YAAc,IAIzD,MAAO,CAAEC,aAFRH,GAAKI,eAAiBH,GAAKI,SAAW,oBAEhBH,aACxB,CAQM,SAAUI,EACfC,EACAC,GAEA,MAAMC,OAAEA,EAAMC,YAAEA,KAAgBC,GAAYJ,EAEtCK,EAAWC,IAIhBC,EAAU,KACLL,GACHM,EACC,UACA,IAAM,IAAIC,EAAcL,GACxBF,EACAC,GAGFO,EAAUC,YAAY,IAAIC,MAAMN,EAAMV,gBACpC,CAACU,EAAMV,eAEKiB,EAARZ,GAAgCa,EAAlB,IAAKR,KAK3B,OAFAD,EAAQU,gBAAkBvB,EAEnBa,CACR,CAYM,SAAUW,EAAyBf,GACxC,MAAO,EAAGgB,QAAOC,YAChBX,EAAU,KACTG,EAAUC,YAAYM,IACpB,CAACA,IAEGJ,EAACZ,EAAK,CAACgB,MAAOA,EAAOC,MAAOA,IAErC"}
@@ -0,0 +1,2 @@
1
+ "use strict";function t(t,e){return{sdk:{name:"@launchdarkly/observability-next",version:"0.1.0"},sdkKey:t,clientSideId:t,application:e}}exports.ensureStandaloneInit=function(e,n,a,i){const s=globalThis.__ldObservabilityNext??={};if(s[e])return;const o=n();o.getHooks?.(t(a,i)),s[e]=!0},exports.standaloneMetadata=t;
2
+ //# sourceMappingURL=standalone-CQH9Vh11.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"standalone-CQH9Vh11.js","sources":["../src/util/standalone.ts","../src/util/version.ts"],"sourcesContent":["import { SDK_NAME, SDK_VERSION } from './version'\n\n/**\n * Application metadata that LaunchDarkly associates with telemetry. Mirrors the\n * `application` field of the LaunchDarkly client configuration so that data sent\n * in standalone mode is tagged identically to data sent through an LD client.\n */\nexport interface LDApplicationInfo {\n\tid?: string\n\tversion?: string\n}\n\n/**\n * The LaunchDarkly observability and session replay plugins are normally\n * registered with a LaunchDarkly feature-flag client, which hands them an\n * `LDPluginEnvironmentMetadata` object describing the environment (and crucially\n * the SDK credential) during `getHooks`. There is no LaunchDarkly feature-flag\n * SDK for Next.js, so this SDK runs the plugins in \"standalone\" mode: we build\n * the same metadata object ourselves from the LaunchDarkly SDK key and invoke\n * the plugin's `getHooks`, which performs the one-time initialization that loads\n * the `LDObserve` / `LDRecord` singletons.\n *\n * The hooks returned by `getHooks` are only used for feature-flag evaluation and\n * identify tracking, which cannot fire without an LD client, so they are\n * discarded in standalone mode.\n */\nexport function standaloneMetadata(\n\tsdkKey: string,\n\tapplication?: LDApplicationInfo,\n) {\n\treturn {\n\t\tsdk: {\n\t\t\tname: SDK_NAME,\n\t\t\tversion: SDK_VERSION,\n\t\t},\n\t\tsdkKey,\n\t\tclientSideId: sdkKey,\n\t\tapplication,\n\t}\n}\n\n/**\n * A minimal structural type for a LaunchDarkly plugin so we can trigger\n * standalone initialization without depending on a specific LD client SDK\n * package. Both the browser plugins (`@launchdarkly/observability`,\n * `@launchdarkly/session-replay`) and the node plugin\n * (`@launchdarkly/observability-node`) satisfy this shape.\n */\nexport interface StandalonePlugin {\n\tgetHooks?(metadata: ReturnType<typeof standaloneMetadata>): unknown\n\tregister?(\n\t\tclient: unknown,\n\t\tmetadata: ReturnType<typeof standaloneMetadata>,\n\t): void\n}\n\ninterface InitRegistry {\n\t[key: string]: boolean\n}\ndeclare var globalThis: { __ldObservabilityNext?: InitRegistry }\n\n/**\n * Initialize a browser plugin in standalone mode exactly once. The guard is\n * keyed on `globalThis` (where the LDObserve / LDRecord singletons also live) so\n * that initialization is idempotent across this SDK's separate client and ssr\n * bundles — e.g. when both `LDObservabilityInit` and a Pages Router `_error`\n * page would otherwise init the same plugin.\n */\nexport function ensureStandaloneInit(\n\tkey: string,\n\tcreatePlugin: () => StandalonePlugin,\n\tsdkKey: string,\n\tapplication?: LDApplicationInfo,\n) {\n\tconst registry = (globalThis.__ldObservabilityNext ??= {})\n\tif (registry[key]) {\n\t\treturn\n\t}\n\n\tconst plugin = createPlugin()\n\tplugin.getHooks?.(standaloneMetadata(sdkKey, application))\n\t// Only mark the key initialized once init succeeds, so a throw from\n\t// createPlugin / getHooks leaves the plugin retryable on the next call.\n\tregistry[key] = true\n}\n","export const SDK_NAME = '@launchdarkly/observability-next'\n\n// Keep in sync with package.json \"version\". Used only as informational\n// telemetry metadata (telemetry.sdk.version), so minor drift is harmless. It is\n// a literal (rather than an import of package.json) so the manifest is not\n// bundled into the browser client.\nexport const SDK_VERSION = '0.1.0'\n"],"names":["standaloneMetadata","sdkKey","application","sdk","name","version","clientSideId","key","createPlugin","registry","globalThis","__ldObservabilityNext","plugin","getHooks"],"mappings":"aA0BM,SAAUA,EACfC,EACAC,GAEA,MAAO,CACNC,IAAK,CACJC,KChCqB,mCDiCrBC,QC3BwB,SD6BzBJ,SACAK,aAAcL,EACdC,cAEF,8BA6BM,SACLK,EACAC,EACAP,EACAC,GAEA,MAAMO,EAAYC,WAAWC,wBAA0B,GACvD,GAAIF,EAASF,GACZ,OAGD,MAAMK,EAASJ,IACfI,EAAOC,WAAWb,EAAmBC,EAAQC,IAG7CO,EAASF,IAAO,CACjB"}
@@ -0,0 +1,2 @@
1
+ function e(e,n){return{sdk:{name:"@launchdarkly/observability-next",version:"0.1.0"},sdkKey:e,clientSideId:e,application:n}}function n(n,t,i,s){const o=globalThis.__ldObservabilityNext??={};if(o[n])return;const a=t();a.getHooks?.(e(i,s)),o[n]=!0}export{n as e,e as s};
2
+ //# sourceMappingURL=standalone-CkwD29IP.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"standalone-CkwD29IP.js","sources":["../src/util/standalone.ts","../src/util/version.ts"],"sourcesContent":["import { SDK_NAME, SDK_VERSION } from './version'\n\n/**\n * Application metadata that LaunchDarkly associates with telemetry. Mirrors the\n * `application` field of the LaunchDarkly client configuration so that data sent\n * in standalone mode is tagged identically to data sent through an LD client.\n */\nexport interface LDApplicationInfo {\n\tid?: string\n\tversion?: string\n}\n\n/**\n * The LaunchDarkly observability and session replay plugins are normally\n * registered with a LaunchDarkly feature-flag client, which hands them an\n * `LDPluginEnvironmentMetadata` object describing the environment (and crucially\n * the SDK credential) during `getHooks`. There is no LaunchDarkly feature-flag\n * SDK for Next.js, so this SDK runs the plugins in \"standalone\" mode: we build\n * the same metadata object ourselves from the LaunchDarkly SDK key and invoke\n * the plugin's `getHooks`, which performs the one-time initialization that loads\n * the `LDObserve` / `LDRecord` singletons.\n *\n * The hooks returned by `getHooks` are only used for feature-flag evaluation and\n * identify tracking, which cannot fire without an LD client, so they are\n * discarded in standalone mode.\n */\nexport function standaloneMetadata(\n\tsdkKey: string,\n\tapplication?: LDApplicationInfo,\n) {\n\treturn {\n\t\tsdk: {\n\t\t\tname: SDK_NAME,\n\t\t\tversion: SDK_VERSION,\n\t\t},\n\t\tsdkKey,\n\t\tclientSideId: sdkKey,\n\t\tapplication,\n\t}\n}\n\n/**\n * A minimal structural type for a LaunchDarkly plugin so we can trigger\n * standalone initialization without depending on a specific LD client SDK\n * package. Both the browser plugins (`@launchdarkly/observability`,\n * `@launchdarkly/session-replay`) and the node plugin\n * (`@launchdarkly/observability-node`) satisfy this shape.\n */\nexport interface StandalonePlugin {\n\tgetHooks?(metadata: ReturnType<typeof standaloneMetadata>): unknown\n\tregister?(\n\t\tclient: unknown,\n\t\tmetadata: ReturnType<typeof standaloneMetadata>,\n\t): void\n}\n\ninterface InitRegistry {\n\t[key: string]: boolean\n}\ndeclare var globalThis: { __ldObservabilityNext?: InitRegistry }\n\n/**\n * Initialize a browser plugin in standalone mode exactly once. The guard is\n * keyed on `globalThis` (where the LDObserve / LDRecord singletons also live) so\n * that initialization is idempotent across this SDK's separate client and ssr\n * bundles — e.g. when both `LDObservabilityInit` and a Pages Router `_error`\n * page would otherwise init the same plugin.\n */\nexport function ensureStandaloneInit(\n\tkey: string,\n\tcreatePlugin: () => StandalonePlugin,\n\tsdkKey: string,\n\tapplication?: LDApplicationInfo,\n) {\n\tconst registry = (globalThis.__ldObservabilityNext ??= {})\n\tif (registry[key]) {\n\t\treturn\n\t}\n\n\tconst plugin = createPlugin()\n\tplugin.getHooks?.(standaloneMetadata(sdkKey, application))\n\t// Only mark the key initialized once init succeeds, so a throw from\n\t// createPlugin / getHooks leaves the plugin retryable on the next call.\n\tregistry[key] = true\n}\n","export const SDK_NAME = '@launchdarkly/observability-next'\n\n// Keep in sync with package.json \"version\". Used only as informational\n// telemetry metadata (telemetry.sdk.version), so minor drift is harmless. It is\n// a literal (rather than an import of package.json) so the manifest is not\n// bundled into the browser client.\nexport const SDK_VERSION = '0.1.0'\n"],"names":["standaloneMetadata","sdkKey","application","sdk","name","version","clientSideId","ensureStandaloneInit","key","createPlugin","registry","globalThis","__ldObservabilityNext","plugin","getHooks"],"mappings":"AA0BM,SAAUA,EACfC,EACAC,GAEA,MAAO,CACNC,IAAK,CACJC,KChCqB,mCDiCrBC,QC3BwB,SD6BzBJ,SACAK,aAAcL,EACdC,cAEF,CA6BM,SAAUK,EACfC,EACAC,EACAR,EACAC,GAEA,MAAMQ,EAAYC,WAAWC,wBAA0B,GACvD,GAAIF,EAASF,GACZ,OAGD,MAAMK,EAASJ,IACfI,EAAOC,WAAWd,EAAmBC,EAAQC,IAG7CQ,EAASF,IAAO,CACjB"}
@@ -0,0 +1,2 @@
1
+ export declare function isNodeJsRuntime(): boolean;
2
+ //# sourceMappingURL=is-node-js-runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-node-js-runtime.d.ts","sourceRoot":"","sources":["../../src/util/is-node-js-runtime.ts"],"names":[],"mappings":"AAAA,wBAAgB,eAAe,YAK9B"}
@@ -0,0 +1,3 @@
1
+ import { NextResponse } from 'next/server';
2
+ export declare function observabilityMiddleware(request: Request): Promise<NextResponse<unknown>>;
3
+ //# sourceMappingURL=observability-middleware.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"observability-middleware.d.ts","sourceRoot":"","sources":["../../src/util/observability-middleware.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAoB1C,wBAAsB,uBAAuB,CAAC,OAAO,EAAE,OAAO,kCAQ7D"}
@@ -0,0 +1,5 @@
1
+ export declare const PROXY_ENV_FLAG = "configureLaunchDarklyProxy";
2
+ export declare const PROXY_BACKEND_PATH = "/highlight-events";
3
+ export declare const LD_PUBLIC_BACKEND_URL = "https://pub.observability.app.launchdarkly.com";
4
+ export declare const LD_OTLP_ENDPOINT = "https://otel.observability.app.launchdarkly.com";
5
+ //# sourceMappingURL=proxy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../../src/util/proxy.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,cAAc,+BAA+B,CAAA;AAG1D,eAAO,MAAM,kBAAkB,sBAAsB,CAAA;AAGrD,eAAO,MAAM,qBAAqB,mDACe,CAAA;AACjD,eAAO,MAAM,gBAAgB,oDACqB,CAAA"}
@@ -0,0 +1,3 @@
1
+ import type { ObservabilityEnv } from './types';
2
+ export declare function registerObservability(env: ObservabilityEnv): Promise<void>;
3
+ //# sourceMappingURL=register-observability.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"register-observability.d.ts","sourceRoot":"","sources":["../../src/util/register-observability.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AA8B/C,wBAAsB,qBAAqB,CAAC,GAAG,EAAE,gBAAgB,iBAgBhE"}
@@ -0,0 +1,2 @@
1
+ export declare function sanitizeSpanUrl(url: string | undefined): string;
2
+ //# sourceMappingURL=sanitize-url.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sanitize-url.d.ts","sourceRoot":"","sources":["../../src/util/sanitize-url.ts"],"names":[],"mappings":"AAQA,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAK/D"}
@@ -0,0 +1,19 @@
1
+ export interface LDApplicationInfo {
2
+ id?: string;
3
+ version?: string;
4
+ }
5
+ export declare function standaloneMetadata(sdkKey: string, application?: LDApplicationInfo): {
6
+ sdk: {
7
+ name: string;
8
+ version: string;
9
+ };
10
+ sdkKey: string;
11
+ clientSideId: string;
12
+ application: LDApplicationInfo | undefined;
13
+ };
14
+ export interface StandalonePlugin {
15
+ getHooks?(metadata: ReturnType<typeof standaloneMetadata>): unknown;
16
+ register?(client: unknown, metadata: ReturnType<typeof standaloneMetadata>): void;
17
+ }
18
+ export declare function ensureStandaloneInit(key: string, createPlugin: () => StandalonePlugin, sdkKey: string, application?: LDApplicationInfo): void;
19
+ //# sourceMappingURL=standalone.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"standalone.d.ts","sourceRoot":"","sources":["../../src/util/standalone.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,iBAAiB;IACjC,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,OAAO,CAAC,EAAE,MAAM,CAAA;CAChB;AAgBD,wBAAgB,kBAAkB,CACjC,MAAM,EAAE,MAAM,EACd,WAAW,CAAC,EAAE,iBAAiB;;;;;;;;EAW/B;AASD,MAAM,WAAW,gBAAgB;IAChC,QAAQ,CAAC,CAAC,QAAQ,EAAE,UAAU,CAAC,OAAO,kBAAkB,CAAC,GAAG,OAAO,CAAA;IACnE,QAAQ,CAAC,CACR,MAAM,EAAE,OAAO,EACf,QAAQ,EAAE,UAAU,CAAC,OAAO,kBAAkB,CAAC,GAC7C,IAAI,CAAA;CACP;AAcD,wBAAgB,oBAAoB,CACnC,GAAG,EAAE,MAAM,EACX,YAAY,EAAE,MAAM,gBAAgB,EACpC,MAAM,EAAE,MAAM,EACd,WAAW,CAAC,EAAE,iBAAiB,QAY/B"}
@@ -0,0 +1,5 @@
1
+ import type { NodeOptions } from '@launchdarkly/observability-node';
2
+ export interface ObservabilityEnv extends NodeOptions {
3
+ sdkKey: string;
4
+ }
5
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/util/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAA;AAOnE,MAAM,WAAW,gBAAiB,SAAQ,WAAW;IAEpD,MAAM,EAAE,MAAM,CAAA;CACd"}
@@ -0,0 +1,3 @@
1
+ export declare const SDK_NAME = "@launchdarkly/observability-next";
2
+ export declare const SDK_VERSION = "0.1.0";
3
+ //# sourceMappingURL=version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/util/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,QAAQ,qCAAqC,CAAA;AAM1D,eAAO,MAAM,WAAW,UAAU,CAAA"}
@@ -0,0 +1,15 @@
1
+ import { NextConfig } from 'next';
2
+ export interface LaunchDarklyConfigOptions {
3
+ configureLaunchDarklyProxy?: boolean;
4
+ }
5
+ type NextConfigObject = NextConfig;
6
+ type NextConfigFunction = (phase: string, { defaultConfig }: {
7
+ defaultConfig: any;
8
+ }) => NextConfig;
9
+ type NextConfigAsyncFunction = (phase: string, { defaultConfig }: {
10
+ defaultConfig: any;
11
+ }) => Promise<NextConfig>;
12
+ export declare function withLaunchDarklyConfig(config: NextConfigObject, opts?: LaunchDarklyConfigOptions): NextConfig;
13
+ export declare function withLaunchDarklyConfig(config: NextConfigFunction | NextConfigAsyncFunction, opts?: LaunchDarklyConfigOptions): NextConfigAsyncFunction;
14
+ export {};
15
+ //# sourceMappingURL=with-launchdarkly-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"with-launchdarkly-config.d.ts","sourceRoot":"","sources":["../../src/util/with-launchdarkly-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAA;AAwBjC,MAAM,WAAW,yBAAyB;IAQzC,0BAA0B,CAAC,EAAE,OAAO,CAAA;CACpC;AAYD,KAAK,gBAAgB,GAAG,UAAU,CAAA;AAClC,KAAK,kBAAkB,GAAG,CACzB,KAAK,EAAE,MAAM,EACb,EAAE,aAAa,EAAE,EAAE;IAAE,aAAa,EAAE,GAAG,CAAA;CAAE,KACrC,UAAU,CAAA;AACf,KAAK,uBAAuB,GAAG,CAC9B,KAAK,EAAE,MAAM,EACb,EAAE,aAAa,EAAE,EAAE;IAAE,aAAa,EAAE,GAAG,CAAA;CAAE,KACrC,OAAO,CAAC,UAAU,CAAC,CAAA;AA+ExB,wBAAgB,sBAAsB,CACrC,MAAM,EAAE,gBAAgB,EACxB,IAAI,CAAC,EAAE,yBAAyB,GAC9B,UAAU,CAAA;AACb,wBAAgB,sBAAsB,CACrC,MAAM,EAAE,kBAAkB,GAAG,uBAAuB,EACpD,IAAI,CAAC,EAAE,yBAAyB,GAC9B,uBAAuB,CAAA"}
@@ -0,0 +1,8 @@
1
+ import type { ObservabilityEnv } from './types';
2
+ type NextContext = {
3
+ params: Promise<Record<string, string>>;
4
+ };
5
+ type NextHandler = (request: Request, context: NextContext) => Promise<Response>;
6
+ export declare function Highlight(env: ObservabilityEnv): (originalHandler: NextHandler) => (request: Request, context: NextContext) => Promise<Response>;
7
+ export {};
8
+ //# sourceMappingURL=with-observability-app-router.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"with-observability-app-router.d.ts","sourceRoot":"","sources":["../../src/util/with-observability-app-router.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE/C,KAAK,WAAW,GAAG;IAClB,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;CACvC,CAAA;AACD,KAAK,WAAW,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAA;AAMhF,wBAAgB,SAAS,CAAC,GAAG,EAAE,gBAAgB,IACtC,iBAAiB,WAAW,MAC5B,SAAS,OAAO,EAAE,SAAS,WAAW,KAAG,OAAO,CAAC,QAAQ,CAAC,CAUlE"}
@@ -0,0 +1,16 @@
1
+ import type { ObservabilityEnv } from './types';
2
+ import type { IncomingHttpHeaders } from 'http';
3
+ export declare type HasHeaders = {
4
+ headers: IncomingHttpHeaders;
5
+ method?: string;
6
+ url?: string;
7
+ };
8
+ export declare type HasStatus = {
9
+ readonly statusCode: number;
10
+ readonly statusMessage: string;
11
+ status: (statusCode: number) => HasStatus;
12
+ send: (body: string) => void;
13
+ };
14
+ export declare type ApiHandler<T extends HasHeaders, S extends HasStatus> = (req: T, res: S) => unknown | Promise<unknown>;
15
+ export declare const Highlight: (env: ObservabilityEnv) => <T extends HasHeaders, S extends HasStatus>(originalHandler: ApiHandler<T, S>) => ApiHandler<T, S>;
16
+ //# sourceMappingURL=with-observability-page-router.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"with-observability-page-router.d.ts","sourceRoot":"","sources":["../../src/util/with-observability-page-router.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE/C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,MAAM,CAAA;AAE/C,MAAM,CAAC,OAAO,MAAM,UAAU,GAAG;IAChC,OAAO,EAAE,mBAAmB,CAAA;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,GAAG,CAAC,EAAE,MAAM,CAAA;CACZ,CAAA;AACD,MAAM,CAAC,OAAO,MAAM,SAAS,GAAG;IAC/B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAA;IAC9B,MAAM,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,SAAS,CAAA;IACzC,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;CAC5B,CAAA;AACD,MAAM,CAAC,OAAO,MAAM,UAAU,CAAC,CAAC,SAAS,UAAU,EAAE,CAAC,SAAS,SAAS,IAAI,CAC3E,GAAG,EAAE,CAAC,EACN,GAAG,EAAE,CAAC,KACF,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;AAM/B,eAAO,MAAM,SAAS,GACpB,KAAK,gBAAgB,MACrB,CAAC,SAAS,UAAU,EAAE,CAAC,SAAS,SAAS,EACzC,iBAAiB,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,KAC/B,UAAU,CAAC,CAAC,EAAE,CAAC,CAYjB,CAAA"}
package/package.json CHANGED
@@ -1,5 +1,95 @@
1
1
  {
2
2
  "name": "@launchdarkly/observability-next",
3
- "version": "0.0.0",
4
- "description": ""
5
- }
3
+ "version": "0.2.0",
4
+ "description": "LaunchDarkly observability and session replay for Next.js. Capture frontend and backend errors, logs, traces, and session replays.",
5
+ "keywords": [
6
+ "launchdarkly",
7
+ "error monitoring",
8
+ "logging",
9
+ "tracing",
10
+ "metrics",
11
+ "debugging",
12
+ "observability",
13
+ "session replay",
14
+ "nextjs",
15
+ "next",
16
+ "library"
17
+ ],
18
+ "homepage": "https://github.com/launchdarkly/observability-sdk/tree/main/sdk/@launchdarkly/observability-next#readme",
19
+ "bugs": {
20
+ "url": "https://github.com/launchdarkly/observability-sdk/issues",
21
+ "email": "support@launchdarkly.com"
22
+ },
23
+ "license": "Apache-2.0",
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "https://github.com/launchdarkly/observability-sdk.git"
27
+ },
28
+ "files": [
29
+ "dist",
30
+ "client.d.ts",
31
+ "config.d.ts",
32
+ "server.d.ts",
33
+ "ssr.d.ts"
34
+ ],
35
+ "exports": {
36
+ "./server": {
37
+ "types": "./dist/server.d.ts",
38
+ "edge": "./dist/server.edge.js",
39
+ "edge-light": "./dist/server.edge.js",
40
+ "worker": "./dist/server.edge.js",
41
+ "workerd": "./dist/server.edge.js",
42
+ "require": "./dist/server.cjs",
43
+ "import": "./dist/server.js"
44
+ },
45
+ "./client": {
46
+ "types": "./dist/next-client.d.ts",
47
+ "import": "./dist/next-client.js",
48
+ "require": "./dist/next-client.cjs"
49
+ },
50
+ "./config": {
51
+ "types": "./dist/config.d.ts",
52
+ "import": "./dist/config.js",
53
+ "require": "./dist/config.cjs"
54
+ },
55
+ "./ssr": {
56
+ "types": "./dist/ssr.d.ts",
57
+ "import": "./dist/ssr.js",
58
+ "require": "./dist/ssr.cjs"
59
+ }
60
+ },
61
+ "type": "module",
62
+ "publishConfig": {
63
+ "access": "public"
64
+ },
65
+ "scripts": {
66
+ "typegen": "tsc -d --emitDeclarationOnly",
67
+ "dev": "yarn build --watch",
68
+ "build": "rollup --config rollup.config.js && sh bin/clean-dist.sh"
69
+ },
70
+ "author": "",
71
+ "peerDependencies": {
72
+ "next": ">=14",
73
+ "react": ">=17"
74
+ },
75
+ "dependencies": {
76
+ "@launchdarkly/observability": "1.1.15",
77
+ "@launchdarkly/observability-node": "1.1.3",
78
+ "@launchdarkly/session-replay": "1.1.15",
79
+ "js-cookie": "^3.0.5"
80
+ },
81
+ "devDependencies": {
82
+ "@opentelemetry/api": "^1.9.0",
83
+ "@opentelemetry/semantic-conventions": "^1.34.0",
84
+ "@rollup/plugin-json": "^6.1.0",
85
+ "@rollup/plugin-terser": "^0.4.4",
86
+ "@rollup/plugin-typescript": "^11.1.5",
87
+ "@types/js-cookie": "^3",
88
+ "@types/node": "^20.14.7",
89
+ "@types/react": "^19.0.10",
90
+ "next": ">=14",
91
+ "react": "^19.0.0",
92
+ "rollup": "^4.4.1",
93
+ "typescript": "^5.0.4"
94
+ }
95
+ }
package/server.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './dist/server'
package/ssr.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './dist/ssr'