@od-oneapp/observability 2026.1.1301

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 (107) hide show
  1. package/README.md +523 -0
  2. package/dist/client-next.d.mts +20 -0
  3. package/dist/client-next.d.mts.map +1 -0
  4. package/dist/client-next.mjs +64 -0
  5. package/dist/client-next.mjs.map +1 -0
  6. package/dist/client.d.mts +11 -0
  7. package/dist/client.d.mts.map +1 -0
  8. package/dist/client.mjs +47 -0
  9. package/dist/client.mjs.map +1 -0
  10. package/dist/env.d.mts +15 -0
  11. package/dist/env.d.mts.map +1 -0
  12. package/dist/env.mjs +45 -0
  13. package/dist/env.mjs.map +1 -0
  14. package/dist/factory-DkY353r8.mjs +380 -0
  15. package/dist/factory-DkY353r8.mjs.map +1 -0
  16. package/dist/hooks-useObservability.d.mts +11 -0
  17. package/dist/hooks-useObservability.d.mts.map +1 -0
  18. package/dist/hooks-useObservability.mjs +174 -0
  19. package/dist/hooks-useObservability.mjs.map +1 -0
  20. package/dist/index-CpcdzWrF.d.mts +24 -0
  21. package/dist/index-CpcdzWrF.d.mts.map +1 -0
  22. package/dist/index.d.mts +88 -0
  23. package/dist/index.d.mts.map +1 -0
  24. package/dist/index.mjs +97 -0
  25. package/dist/index.mjs.map +1 -0
  26. package/dist/manager-BxQqOPEg.d.mts +33 -0
  27. package/dist/manager-BxQqOPEg.d.mts.map +1 -0
  28. package/dist/plugin-Bfq-o3nr.d.mts +60 -0
  29. package/dist/plugin-Bfq-o3nr.d.mts.map +1 -0
  30. package/dist/plugin-Bt-ygG1m.d.mts +254 -0
  31. package/dist/plugin-Bt-ygG1m.d.mts.map +1 -0
  32. package/dist/plugin-CLFwRERa.mjs +593 -0
  33. package/dist/plugin-CLFwRERa.mjs.map +1 -0
  34. package/dist/plugin-CP895lBx.mjs +534 -0
  35. package/dist/plugin-CP895lBx.mjs.map +1 -0
  36. package/dist/plugin-CaQxviDs.d.mts +61 -0
  37. package/dist/plugin-CaQxviDs.d.mts.map +1 -0
  38. package/dist/plugin-lPdJirTY.mjs +234 -0
  39. package/dist/plugin-lPdJirTY.mjs.map +1 -0
  40. package/dist/plugins-betterstack-env.d.mts +29 -0
  41. package/dist/plugins-betterstack-env.d.mts.map +1 -0
  42. package/dist/plugins-betterstack-env.mjs +75 -0
  43. package/dist/plugins-betterstack-env.mjs.map +1 -0
  44. package/dist/plugins-betterstack.d.mts +4 -0
  45. package/dist/plugins-betterstack.mjs +4 -0
  46. package/dist/plugins-console.d.mts +37 -0
  47. package/dist/plugins-console.d.mts.map +1 -0
  48. package/dist/plugins-console.mjs +196 -0
  49. package/dist/plugins-console.mjs.map +1 -0
  50. package/dist/plugins-sentry-env.d.mts +37 -0
  51. package/dist/plugins-sentry-env.d.mts.map +1 -0
  52. package/dist/plugins-sentry-env.mjs +79 -0
  53. package/dist/plugins-sentry-env.mjs.map +1 -0
  54. package/dist/plugins-sentry-microfrontend-env.d.mts +49 -0
  55. package/dist/plugins-sentry-microfrontend-env.d.mts.map +1 -0
  56. package/dist/plugins-sentry-microfrontend-env.mjs +80 -0
  57. package/dist/plugins-sentry-microfrontend-env.mjs.map +1 -0
  58. package/dist/plugins-sentry-microfrontend.d.mts +2 -0
  59. package/dist/plugins-sentry-microfrontend.mjs +3 -0
  60. package/dist/plugins-sentry.d.mts +5 -0
  61. package/dist/plugins-sentry.mjs +6 -0
  62. package/dist/server-edge.d.mts +15 -0
  63. package/dist/server-edge.d.mts.map +1 -0
  64. package/dist/server-edge.mjs +53 -0
  65. package/dist/server-edge.mjs.map +1 -0
  66. package/dist/server-next.d.mts +17 -0
  67. package/dist/server-next.d.mts.map +1 -0
  68. package/dist/server-next.mjs +64 -0
  69. package/dist/server-next.mjs.map +1 -0
  70. package/dist/server.d.mts +11 -0
  71. package/dist/server.d.mts.map +1 -0
  72. package/dist/server.mjs +48 -0
  73. package/dist/server.mjs.map +1 -0
  74. package/dist/utils-CuGrTcD6.d.mts +77 -0
  75. package/dist/utils-CuGrTcD6.d.mts.map +1 -0
  76. package/env.ts +67 -0
  77. package/package.json +147 -0
  78. package/src/client-next.ts +131 -0
  79. package/src/client.ts +70 -0
  80. package/src/core/index.ts +15 -0
  81. package/src/core/manager.ts +361 -0
  82. package/src/core/plugin.ts +61 -0
  83. package/src/core/types.ts +151 -0
  84. package/src/factory/builder.ts +132 -0
  85. package/src/factory/index.ts +67 -0
  86. package/src/factory/presets.ts +78 -0
  87. package/src/hooks/useObservability.ts +206 -0
  88. package/src/plugins/betterstack/env.ts +101 -0
  89. package/src/plugins/betterstack/index.ts +15 -0
  90. package/src/plugins/betterstack/plugin.ts +373 -0
  91. package/src/plugins/console/index.ts +323 -0
  92. package/src/plugins/sentry/__tests__/plugin-tracing.test.ts +511 -0
  93. package/src/plugins/sentry/env.ts +93 -0
  94. package/src/plugins/sentry/index.ts +28 -0
  95. package/src/plugins/sentry/plugin.ts +953 -0
  96. package/src/plugins/sentry/types.ts +252 -0
  97. package/src/plugins/sentry-microfrontend/env.ts +105 -0
  98. package/src/plugins/sentry-microfrontend/index.ts +12 -0
  99. package/src/plugins/sentry-microfrontend/multiplexed-transport.ts +221 -0
  100. package/src/plugins/sentry-microfrontend/plugin.ts +500 -0
  101. package/src/plugins/sentry-microfrontend/sentry-types.ts +140 -0
  102. package/src/plugins/sentry-microfrontend/types.ts +130 -0
  103. package/src/plugins/sentry-microfrontend/utils.ts +326 -0
  104. package/src/server-edge.ts +113 -0
  105. package/src/server-next.ts +114 -0
  106. package/src/server.ts +71 -0
  107. package/src/shared.ts +148 -0
@@ -0,0 +1,174 @@
1
+ 'use client';
2
+
3
+ import { logDebug, logError } from "@od-oneapp/shared/logs";
4
+ import { use, useEffect, useSyncExternalStore } from "react";
5
+
6
+ //#region src/hooks/useObservability.ts
7
+ /**
8
+ * @fileoverview React hooks for observability integration
9
+ * React hooks for observability integration
10
+ * Optimized for React 19 features including use() hook and automatic error boundaries
11
+ */
12
+ /**
13
+ * Global observability instance promise for React 19's use() hook
14
+ * This allows components to suspend while waiting for initialization
15
+ */
16
+ let observabilityPromise = null;
17
+ /**
18
+ * Set the observability promise for React 19 Suspense integration
19
+ * @param promise - Promise that resolves to ObservabilityManager
20
+ */
21
+ function setObservabilityPromise(promise) {
22
+ observabilityPromise = promise;
23
+ }
24
+ /**
25
+ * React 19+ hook that suspends until observability is ready
26
+ * Uses the new use() hook for automatic Suspense integration
27
+ *
28
+ * @example
29
+ * ```tsx
30
+ * 'use client';
31
+ *
32
+ * import { Suspense } from 'react';
33
+ * import { useObservability } from '@od-oneapp/observability/hooks/useObservability';
34
+ * import { logInfo } from '@od-oneapp/shared/logs';
35
+ *
36
+ * function MyComponent() {
37
+ * const observability = useObservability();
38
+ *
39
+ * useEffect(() => {
40
+ * logInfo('Component mounted');
41
+ * }, [observability]);
42
+ *
43
+ * return <div>Hello</div>;
44
+ * }
45
+ *
46
+ * export default function Page() {
47
+ * return (
48
+ * <Suspense fallback={<div>Loading...</div>}>
49
+ * <MyComponent />
50
+ * </Suspense>
51
+ * );
52
+ * }
53
+ * ```
54
+ */
55
+ function useObservability() {
56
+ if (!observabilityPromise) throw new Error("Observability promise not set. Call setObservabilityPromise() during module initialization.");
57
+ return use(observabilityPromise);
58
+ }
59
+ let legacyCurrentInstance = void 0;
60
+ const legacyListeners = /* @__PURE__ */ new Set();
61
+ let legacyInitialized = false;
62
+ /**
63
+ * Legacy hook for React 18 compatibility
64
+ * Returns observability instance once available, undefined during initialization
65
+ * Does not use Suspense
66
+ *
67
+ * @deprecated Use useObservability() with Suspense for React 19+
68
+ */
69
+ function useObservabilityLegacy() {
70
+ const subscribe = (callback) => {
71
+ legacyListeners.add(callback);
72
+ if (observabilityPromise && !legacyInitialized) {
73
+ legacyInitialized = true;
74
+ (async () => {
75
+ try {
76
+ legacyCurrentInstance = await observabilityPromise;
77
+ legacyListeners.forEach((listener) => {
78
+ listener();
79
+ });
80
+ } catch {
81
+ legacyInitialized = false;
82
+ }
83
+ })();
84
+ }
85
+ return () => {
86
+ legacyListeners.delete(callback);
87
+ };
88
+ };
89
+ const getSnapshot = () => {
90
+ return legacyCurrentInstance;
91
+ };
92
+ return useSyncExternalStore(subscribe, getSnapshot);
93
+ }
94
+ /**
95
+ * Hook to track component lifecycle events
96
+ * Automatically logs mount, update, and unmount events
97
+ *
98
+ * @param componentName - Name of the component for logging
99
+ * @param deps - Dependencies to track for updates
100
+ *
101
+ * @example
102
+ * ```tsx
103
+ * 'use client';
104
+ *
105
+ * import { useObservabilityLifecycle } from '@od-oneapp/observability/hooks/useObservability';
106
+ *
107
+ * function UserProfile({ userId }: { userId: string }) {
108
+ * useObservabilityLifecycle('UserProfile', [userId]);
109
+ *
110
+ * return <div>User {userId}</div>;
111
+ * }
112
+ * ```
113
+ */
114
+ function useObservabilityLifecycle(componentName, deps = []) {
115
+ useEffect(() => {
116
+ logDebug(`Component mounted: ${componentName}`, {
117
+ component: componentName,
118
+ event: "mount"
119
+ });
120
+ return () => {
121
+ logDebug(`Component unmounted: ${componentName}`, {
122
+ component: componentName,
123
+ event: "unmount"
124
+ });
125
+ };
126
+ }, deps);
127
+ }
128
+ /**
129
+ * Hook to automatically report errors to observability
130
+ * Compatible with React 19 error boundaries
131
+ *
132
+ * @param error - Error to report
133
+ * @param errorInfo - Additional error information
134
+ *
135
+ * @example
136
+ * ```tsx
137
+ * 'use client';
138
+ *
139
+ * import { useObservabilityError } from '@od-oneapp/observability/hooks/useObservability';
140
+ *
141
+ * function MyComponent() {
142
+ * const [error, setError] = useState<Error | null>(null);
143
+ *
144
+ * useObservabilityError(error, { component: 'MyComponent' });
145
+ *
146
+ * if (error) {
147
+ * return <div>Error occurred</div>;
148
+ * }
149
+ *
150
+ * return <div>Hello</div>;
151
+ * }
152
+ * ```
153
+ */
154
+ function useObservabilityError(error, errorInfo) {
155
+ useEffect(() => {
156
+ if (error && observabilityPromise) (async () => {
157
+ try {
158
+ (await observabilityPromise).captureException(error, {
159
+ extra: errorInfo,
160
+ tags: { source: "react-component" }
161
+ });
162
+ } catch (reportError) {
163
+ logError("Failed to report error to observability", {
164
+ error: reportError,
165
+ originalError: error
166
+ });
167
+ }
168
+ })();
169
+ }, [error, errorInfo]);
170
+ }
171
+
172
+ //#endregion
173
+ export { setObservabilityPromise, useObservability, useObservabilityError, useObservabilityLegacy, useObservabilityLifecycle };
174
+ //# sourceMappingURL=hooks-useObservability.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks-useObservability.mjs","names":[],"sources":["../src/hooks/useObservability.ts"],"sourcesContent":["/**\n * @fileoverview React hooks for observability integration\n * React hooks for observability integration\n * Optimized for React 19 features including use() hook and automatic error boundaries\n */\n\n'use client';\n\nimport { use, useEffect, useSyncExternalStore } from 'react';\n\nimport { logDebug, logError } from '@repo/shared/logs';\n\nimport type { ObservabilityManager } from '../core/manager';\n\n/**\n * Global observability instance promise for React 19's use() hook\n * This allows components to suspend while waiting for initialization\n */\nlet observabilityPromise: Promise<ObservabilityManager> | null = null;\n\n/**\n * Set the observability promise for React 19 Suspense integration\n * @param promise - Promise that resolves to ObservabilityManager\n */\nexport function setObservabilityPromise(promise: Promise<ObservabilityManager>): void {\n observabilityPromise = promise;\n}\n\n/**\n * React 19+ hook that suspends until observability is ready\n * Uses the new use() hook for automatic Suspense integration\n *\n * @example\n * ```tsx\n * 'use client';\n *\n * import { Suspense } from 'react';\n * import { useObservability } from '@repo/observability/hooks/useObservability';\n * import { logInfo } from '@repo/shared/logs';\n *\n * function MyComponent() {\n * const observability = useObservability();\n *\n * useEffect(() => {\n * logInfo('Component mounted');\n * }, [observability]);\n *\n * return <div>Hello</div>;\n * }\n *\n * export default function Page() {\n * return (\n * <Suspense fallback={<div>Loading...</div>}>\n * <MyComponent />\n * </Suspense>\n * );\n * }\n * ```\n */\nexport function useObservability(): ObservabilityManager {\n if (!observabilityPromise) {\n throw new Error(\n 'Observability promise not set. Call setObservabilityPromise() during module initialization.',\n );\n }\n\n // React 19's use() hook automatically suspends until promise resolves\n return use(observabilityPromise);\n}\n\n// Module-level state for legacy hook (fixes state recreation bug)\nlet legacyCurrentInstance: ObservabilityManager | undefined = undefined;\nconst legacyListeners = new Set<() => void>();\nlet legacyInitialized = false;\n\n/**\n * Legacy hook for React 18 compatibility\n * Returns observability instance once available, undefined during initialization\n * Does not use Suspense\n *\n * @deprecated Use useObservability() with Suspense for React 19+\n */\nexport function useObservabilityLegacy(): ObservabilityManager | undefined {\n const subscribe = (callback: () => void) => {\n legacyListeners.add(callback);\n\n // If promise exists and instance not yet resolved, wait for it\n if (observabilityPromise && !legacyInitialized) {\n legacyInitialized = true;\n void (async () => {\n try {\n const instance = await observabilityPromise;\n legacyCurrentInstance = instance;\n legacyListeners.forEach(listener => {\n listener();\n });\n } catch {\n legacyInitialized = false; // Allow retry on failure\n }\n })();\n }\n\n return () => {\n legacyListeners.delete(callback);\n };\n };\n\n const getSnapshot = (): ObservabilityManager | undefined => {\n return legacyCurrentInstance;\n };\n\n return useSyncExternalStore(subscribe, getSnapshot);\n}\n\n/**\n * Hook to track component lifecycle events\n * Automatically logs mount, update, and unmount events\n *\n * @param componentName - Name of the component for logging\n * @param deps - Dependencies to track for updates\n *\n * @example\n * ```tsx\n * 'use client';\n *\n * import { useObservabilityLifecycle } from '@repo/observability/hooks/useObservability';\n *\n * function UserProfile({ userId }: { userId: string }) {\n * useObservabilityLifecycle('UserProfile', [userId]);\n *\n * return <div>User {userId}</div>;\n * }\n * ```\n */\nexport function useObservabilityLifecycle(\n componentName: string,\n deps: readonly unknown[] = [],\n): void {\n useEffect(() => {\n // Log mount\n logDebug(`Component mounted: ${componentName}`, {\n component: componentName,\n event: 'mount',\n });\n\n // Log unmount\n return () => {\n logDebug(`Component unmounted: ${componentName}`, {\n component: componentName,\n event: 'unmount',\n });\n };\n }, deps);\n}\n\n/**\n * Hook to automatically report errors to observability\n * Compatible with React 19 error boundaries\n *\n * @param error - Error to report\n * @param errorInfo - Additional error information\n *\n * @example\n * ```tsx\n * 'use client';\n *\n * import { useObservabilityError } from '@repo/observability/hooks/useObservability';\n *\n * function MyComponent() {\n * const [error, setError] = useState<Error | null>(null);\n *\n * useObservabilityError(error, { component: 'MyComponent' });\n *\n * if (error) {\n * return <div>Error occurred</div>;\n * }\n *\n * return <div>Hello</div>;\n * }\n * ```\n */\nexport function useObservabilityError(\n error: Error | null | undefined,\n errorInfo?: Record<string, unknown>,\n): void {\n useEffect(() => {\n if (error && observabilityPromise) {\n void (async () => {\n try {\n const obs = await observabilityPromise;\n obs.captureException(error, {\n extra: errorInfo,\n tags: {\n source: 'react-component',\n },\n });\n } catch (reportError) {\n logError('Failed to report error to observability', {\n error: reportError,\n originalError: error,\n });\n }\n })();\n }\n }, [error, errorInfo]);\n}\n"],"mappings":";;;;;;;;;;;;;;;AAkBA,IAAI,uBAA6D;;;;;AAMjE,SAAgB,wBAAwB,SAA8C;AACpF,wBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCzB,SAAgB,mBAAyC;AACvD,KAAI,CAAC,qBACH,OAAM,IAAI,MACR,8FACD;AAIH,QAAO,IAAI,qBAAqB;;AAIlC,IAAI,wBAA0D;AAC9D,MAAM,kCAAkB,IAAI,KAAiB;AAC7C,IAAI,oBAAoB;;;;;;;;AASxB,SAAgB,yBAA2D;CACzE,MAAM,aAAa,aAAyB;AAC1C,kBAAgB,IAAI,SAAS;AAG7B,MAAI,wBAAwB,CAAC,mBAAmB;AAC9C,uBAAoB;AACpB,IAAM,YAAY;AAChB,QAAI;AAEF,6BADiB,MAAM;AAEvB,qBAAgB,SAAQ,aAAY;AAClC,gBAAU;OACV;YACI;AACN,yBAAoB;;OAEpB;;AAGN,eAAa;AACX,mBAAgB,OAAO,SAAS;;;CAIpC,MAAM,oBAAsD;AAC1D,SAAO;;AAGT,QAAO,qBAAqB,WAAW,YAAY;;;;;;;;;;;;;;;;;;;;;;AAuBrD,SAAgB,0BACd,eACA,OAA2B,EAAE,EACvB;AACN,iBAAgB;AAEd,WAAS,sBAAsB,iBAAiB;GAC9C,WAAW;GACX,OAAO;GACR,CAAC;AAGF,eAAa;AACX,YAAS,wBAAwB,iBAAiB;IAChD,WAAW;IACX,OAAO;IACR,CAAC;;IAEH,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BV,SAAgB,sBACd,OACA,WACM;AACN,iBAAgB;AACd,MAAI,SAAS,qBACX,EAAM,YAAY;AAChB,OAAI;AAEF,KADY,MAAM,sBACd,iBAAiB,OAAO;KAC1B,OAAO;KACP,MAAM,EACJ,QAAQ,mBACT;KACF,CAAC;YACK,aAAa;AACpB,aAAS,2CAA2C;KAClD,OAAO;KACP,eAAe;KAChB,CAAC;;MAEF;IAEL,CAAC,OAAO,UAAU,CAAC"}
@@ -0,0 +1,24 @@
1
+ import { i as PluginLifecycle, n as ObservabilityServerPlugin, t as ObservabilityPlugin } from "./plugin-Bfq-o3nr.mjs";
2
+ import { t as ObservabilityManager } from "./manager-BxQqOPEg.mjs";
3
+
4
+ //#region src/factory/builder.d.ts
5
+ declare class ObservabilityBuilder {
6
+ private plugins;
7
+ private lifecycle;
8
+ private autoInitialize;
9
+ withPlugin(plugin: ObservabilityPlugin | ObservabilityServerPlugin): this;
10
+ withPlugins(plugins: (ObservabilityPlugin | ObservabilityServerPlugin)[]): this;
11
+ withLifecycle(lifecycle: PluginLifecycle): this;
12
+ withAutoInitialize(autoInitialize: boolean): this;
13
+ build(): ObservabilityManager;
14
+ buildWithAutoInit(): Promise<ObservabilityManager>;
15
+ static create(): ObservabilityBuilder;
16
+ }
17
+ //#endregion
18
+ //#region src/factory/index.d.ts
19
+ declare function createObservability(plugins: (ObservabilityPlugin | ObservabilityServerPlugin)[], options?: {
20
+ autoInitialize?: boolean;
21
+ }): ObservabilityManager;
22
+ //#endregion
23
+ export { ObservabilityBuilder as n, createObservability as t };
24
+ //# sourceMappingURL=index-CpcdzWrF.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-CpcdzWrF.d.mts","names":[],"sources":["../src/factory/builder.ts","../src/factory/index.ts"],"mappings":";;;;cAkBa,oBAAA;EAAA,QACH,OAAA;EAAA,QACA,SAAA;EAAA,QACA,cAAA;EAOR,UAAA,CAAW,MAAA,EAAQ,mBAAA,GAAsB,yBAAA;EAYzC,WAAA,CAAY,OAAA,GAAU,mBAAA,GAAsB,yBAAA;EAa5C,aAAA,CAAc,SAAA,EAAW,eAAA;EAQzB,kBAAA,CAAmB,cAAA;EASnB,KAAA,CAAA,GAAS,oBAAA;EAqCH,iBAAA,CAAA,GAAqB,OAAA,CAAQ,oBAAA;EAAA,OAqB5B,MAAA,CAAA,GAAU,oBAAA;AAAA;;;iBC/FH,mBAAA,CACd,OAAA,GAAU,mBAAA,GAAsB,yBAAA,KAChC,OAAA;EACE,cAAA;AAAA,IAED,oBAAA"}
@@ -0,0 +1,88 @@
1
+ //#region src/shared.d.ts
2
+ declare const getRuntimeInfo: () => {
3
+ type: string;
4
+ variant: string;
5
+ version?: undefined;
6
+ isNextJs?: undefined;
7
+ major?: undefined;
8
+ minor?: undefined;
9
+ isNode22Plus?: undefined;
10
+ } | {
11
+ type: string;
12
+ version: string;
13
+ variant?: undefined;
14
+ isNextJs?: undefined;
15
+ major?: undefined;
16
+ minor?: undefined;
17
+ isNode22Plus?: undefined;
18
+ } | {
19
+ type: string;
20
+ isNextJs: boolean;
21
+ variant?: undefined;
22
+ version?: undefined;
23
+ major?: undefined;
24
+ minor?: undefined;
25
+ isNode22Plus?: undefined;
26
+ } | {
27
+ type: string;
28
+ version: string;
29
+ major: number;
30
+ minor: number;
31
+ isNode22Plus: boolean;
32
+ isNextJs: boolean;
33
+ variant?: undefined;
34
+ } | {
35
+ type: string;
36
+ variant?: undefined;
37
+ version?: undefined;
38
+ isNextJs?: undefined;
39
+ major?: undefined;
40
+ minor?: undefined;
41
+ isNode22Plus?: undefined;
42
+ };
43
+ declare const getRuntimeEnvironment: () => {
44
+ type: string;
45
+ variant: string;
46
+ version?: undefined;
47
+ isNextJs?: undefined;
48
+ major?: undefined;
49
+ minor?: undefined;
50
+ isNode22Plus?: undefined;
51
+ } | {
52
+ type: string;
53
+ version: string;
54
+ variant?: undefined;
55
+ isNextJs?: undefined;
56
+ major?: undefined;
57
+ minor?: undefined;
58
+ isNode22Plus?: undefined;
59
+ } | {
60
+ type: string;
61
+ isNextJs: boolean;
62
+ variant?: undefined;
63
+ version?: undefined;
64
+ major?: undefined;
65
+ minor?: undefined;
66
+ isNode22Plus?: undefined;
67
+ } | {
68
+ type: string;
69
+ version: string;
70
+ major: number;
71
+ minor: number;
72
+ isNode22Plus: boolean;
73
+ isNextJs: boolean;
74
+ variant?: undefined;
75
+ } | {
76
+ type: string;
77
+ variant?: undefined;
78
+ version?: undefined;
79
+ isNextJs?: undefined;
80
+ major?: undefined;
81
+ minor?: undefined;
82
+ isNode22Plus?: undefined;
83
+ };
84
+ declare function isBrowser(): boolean;
85
+ declare function shouldEnableConsole(envNodeEnv?: string, consoleEnabled?: boolean, debugEnabled?: boolean): boolean;
86
+ //#endregion
87
+ export { getRuntimeEnvironment, getRuntimeInfo, isBrowser, shouldEnableConsole };
88
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/shared.ts"],"mappings":";cAuBa,cAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA2EA,qBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAOG,SAAA,CAAA;AAAA,iBAkBA,mBAAA,CACd,UAAA,WACA,cAAA,YACA,YAAA"}
package/dist/index.mjs ADDED
@@ -0,0 +1,97 @@
1
+ import { logWarn } from "@od-oneapp/shared/logger";
2
+
3
+ //#region src/shared.ts
4
+ /**
5
+ * @fileoverview Shared observability utilities and types
6
+ * Shared observability utilities and types
7
+ */
8
+ /**
9
+ * Get runtime environment information.
10
+ *
11
+ * Detects the current runtime environment (browser, Node.js, edge, Bun) and returns
12
+ * detailed information about the environment type, version, and capabilities.
13
+ *
14
+ * @returns Runtime information object with type, version, and environment-specific details
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * const runtime = getRuntimeInfo();
19
+ * // Returns: { type: 'node', version: '22.0.0', major: 22, minor: 0, isNode22Plus: true, isNextJs: true }
20
+ * // or: { type: 'browser', isNextJs: true }
21
+ * // or: { type: 'edge', variant: 'vercel' }
22
+ * ```
23
+ */
24
+ const getRuntimeInfo = () => {
25
+ if (typeof globalThis !== "undefined" && globalThis.EdgeRuntime) return {
26
+ type: "edge",
27
+ variant: "vercel"
28
+ };
29
+ if (typeof globalThis !== "undefined" && globalThis.caches && typeof globalThis.caches !== "undefined") return {
30
+ type: "edge",
31
+ variant: "cloudflare"
32
+ };
33
+ if (typeof process !== "undefined" && process.versions?.bun) return {
34
+ type: "bun",
35
+ version: process.versions.bun
36
+ };
37
+ if (typeof globalThis !== "undefined" && "window" in globalThis && typeof globalThis.window !== "undefined" && typeof globalThis.window.document !== "undefined" && typeof globalThis.window.navigator !== "undefined") return {
38
+ type: "browser",
39
+ isNextJs: Boolean(globalThis.window.__NEXT_DATA__)
40
+ };
41
+ if (typeof process !== "undefined" && process.versions?.node) {
42
+ const nodeVersion = parseInt(process.versions.node.split(".")[0] ?? "0");
43
+ const nodeVersionMinor = parseInt(process.versions.node.split(".")[1] ?? "0");
44
+ if (nodeVersion < 22) logWarn(`[Observability] Node ${process.versions.node} detected. Node 22+ is required for optimal performance and latest features.`);
45
+ return {
46
+ type: "node",
47
+ version: process.versions.node,
48
+ major: nodeVersion,
49
+ minor: nodeVersionMinor,
50
+ isNode22Plus: nodeVersion >= 22,
51
+ isNextJs: Boolean(process.env.NEXT_RUNTIME) || Boolean(process.env.__NEXT_RUNTIME) || Boolean(process.env.NEXT_PUBLIC_VERCEL_ENV)
52
+ };
53
+ }
54
+ return { type: "unknown" };
55
+ };
56
+ const runtimeInfo = getRuntimeInfo();
57
+ /**
58
+ * Get cached runtime environment information.
59
+ *
60
+ * Returns the runtime information that was detected at module load time.
61
+ * This is cached to avoid repeated detection checks.
62
+ *
63
+ * @returns Cached runtime information object
64
+ *
65
+ * @example
66
+ * ```typescript
67
+ * const runtime = getRuntimeEnvironment();
68
+ * console.log(runtime.type); // 'node', 'browser', 'edge', etc.
69
+ * ```
70
+ */
71
+ const getRuntimeEnvironment = () => runtimeInfo;
72
+ /**
73
+ * Detect if code is running in a browser environment
74
+ * Extracted to shared utility to avoid duplication
75
+ * @returns true if running in browser, false otherwise
76
+ */
77
+ function isBrowser() {
78
+ return typeof globalThis !== "undefined" && "window" in globalThis && typeof globalThis.window !== "undefined" && typeof globalThis.window.document !== "undefined" && typeof globalThis.window.navigator !== "undefined";
79
+ }
80
+ /**
81
+ * Determine if console logging should be enabled based on environment
82
+ * Centralized logic to avoid duplication across entry points
83
+ * @param envNodeEnv - The NEXT_PUBLIC_NODE_ENV value
84
+ * @param consoleEnabled - The NEXT_PUBLIC_OBSERVABILITY_CONSOLE_ENABLED value (explicit control)
85
+ * @param debugEnabled - The NEXT_PUBLIC_OBSERVABILITY_DEBUG value
86
+ * @returns boolean indicating if console should be enabled
87
+ */
88
+ function shouldEnableConsole(envNodeEnv, consoleEnabled, debugEnabled) {
89
+ const isDevelopment = envNodeEnv === "development" || true;
90
+ if (consoleEnabled !== void 0) return consoleEnabled;
91
+ if (isDevelopment) return true;
92
+ return debugEnabled ?? false;
93
+ }
94
+
95
+ //#endregion
96
+ export { getRuntimeEnvironment, getRuntimeInfo, isBrowser, shouldEnableConsole };
97
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/shared.ts"],"sourcesContent":["/**\n * @fileoverview Shared observability utilities and types\n * Shared observability utilities and types\n */\n\nimport { logWarn } from '@repo/shared/logger';\n\n/**\n * Get runtime environment information.\n *\n * Detects the current runtime environment (browser, Node.js, edge, Bun) and returns\n * detailed information about the environment type, version, and capabilities.\n *\n * @returns Runtime information object with type, version, and environment-specific details\n *\n * @example\n * ```typescript\n * const runtime = getRuntimeInfo();\n * // Returns: { type: 'node', version: '22.0.0', major: 22, minor: 0, isNode22Plus: true, isNextJs: true }\n * // or: { type: 'browser', isNextJs: true }\n * // or: { type: 'edge', variant: 'vercel' }\n * ```\n */\nexport const getRuntimeInfo = () => {\n // Edge runtime detection (Vercel Edge, Cloudflare Workers)\n if (typeof globalThis !== 'undefined' && (globalThis as any).EdgeRuntime) {\n return { type: 'edge', variant: 'vercel' };\n }\n if (\n typeof globalThis !== 'undefined' &&\n (globalThis as any).caches &&\n typeof (globalThis as any).caches !== 'undefined'\n ) {\n return { type: 'edge', variant: 'cloudflare' };\n }\n\n // Bun detection\n if (typeof process !== 'undefined' && process.versions?.bun) {\n return { type: 'bun', version: process.versions.bun };\n }\n\n // Browser detection (more robust)\n if (\n typeof globalThis !== 'undefined' &&\n 'window' in globalThis &&\n typeof (globalThis as any).window !== 'undefined' &&\n typeof (globalThis as any).window.document !== 'undefined' &&\n typeof (globalThis as any).window.navigator !== 'undefined'\n ) {\n return { type: 'browser', isNextJs: Boolean((globalThis as any).window.__NEXT_DATA__) };\n }\n\n // Node.js detection with version check\n if (typeof process !== 'undefined' && process.versions?.node) {\n const nodeVersion = parseInt(process.versions.node.split('.')[0] ?? '0');\n const nodeVersionMinor = parseInt(process.versions.node.split('.')[1] ?? '0');\n\n if (nodeVersion < 22) {\n // Note: Using logWarn here - observability system may not be initialized yet, but shared logger is always available\n logWarn(\n `[Observability] Node ${process.versions.node} detected. Node 22+ is required for optimal performance and latest features.`,\n );\n }\n\n return {\n type: 'node',\n version: process.versions.node,\n major: nodeVersion,\n minor: nodeVersionMinor,\n isNode22Plus: nodeVersion >= 22,\n isNextJs:\n Boolean(process.env.NEXT_RUNTIME) ||\n Boolean(process.env.__NEXT_RUNTIME) ||\n Boolean(process.env.NEXT_PUBLIC_VERCEL_ENV),\n };\n }\n\n // Fallback\n return { type: 'unknown' };\n};\n\n// Cache the runtime info\nconst runtimeInfo = getRuntimeInfo();\n\n/**\n * Get cached runtime environment information.\n *\n * Returns the runtime information that was detected at module load time.\n * This is cached to avoid repeated detection checks.\n *\n * @returns Cached runtime information object\n *\n * @example\n * ```typescript\n * const runtime = getRuntimeEnvironment();\n * console.log(runtime.type); // 'node', 'browser', 'edge', etc.\n * ```\n */\nexport const getRuntimeEnvironment = () => runtimeInfo;\n\n/**\n * Detect if code is running in a browser environment\n * Extracted to shared utility to avoid duplication\n * @returns true if running in browser, false otherwise\n */\nexport function isBrowser(): boolean {\n return (\n typeof globalThis !== 'undefined' &&\n 'window' in globalThis &&\n typeof (globalThis as any).window !== 'undefined' &&\n typeof (globalThis as any).window.document !== 'undefined' &&\n typeof (globalThis as any).window.navigator !== 'undefined'\n );\n}\n\n/**\n * Determine if console logging should be enabled based on environment\n * Centralized logic to avoid duplication across entry points\n * @param envNodeEnv - The NEXT_PUBLIC_NODE_ENV value\n * @param consoleEnabled - The NEXT_PUBLIC_OBSERVABILITY_CONSOLE_ENABLED value (explicit control)\n * @param debugEnabled - The NEXT_PUBLIC_OBSERVABILITY_DEBUG value\n * @returns boolean indicating if console should be enabled\n */\nexport function shouldEnableConsole(\n envNodeEnv?: string,\n consoleEnabled?: boolean,\n debugEnabled?: boolean,\n): boolean {\n const isDevelopment = envNodeEnv === 'development' || process.env.NODE_ENV === 'development';\n\n // Priority: explicit control > development mode > debug mode\n if (consoleEnabled !== undefined) {\n return consoleEnabled;\n }\n if (isDevelopment) {\n return true;\n }\n return debugEnabled ?? false;\n}\n\n// Export types for convenience - removed for Rollup compatibility\n\n// Note: For direct access to observability instances, import from environment-specific modules:\n// - @repo/observability/client-next\n// - @repo/observability/server-next\n// - @repo/observability/server-edge\n// - @repo/observability/client\n// - @repo/observability/server\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAa,uBAAuB;AAElC,KAAI,OAAO,eAAe,eAAgB,WAAmB,YAC3D,QAAO;EAAE,MAAM;EAAQ,SAAS;EAAU;AAE5C,KACE,OAAO,eAAe,eACrB,WAAmB,UACpB,OAAQ,WAAmB,WAAW,YAEtC,QAAO;EAAE,MAAM;EAAQ,SAAS;EAAc;AAIhD,KAAI,OAAO,YAAY,eAAe,QAAQ,UAAU,IACtD,QAAO;EAAE,MAAM;EAAO,SAAS,QAAQ,SAAS;EAAK;AAIvD,KACE,OAAO,eAAe,eACtB,YAAY,cACZ,OAAQ,WAAmB,WAAW,eACtC,OAAQ,WAAmB,OAAO,aAAa,eAC/C,OAAQ,WAAmB,OAAO,cAAc,YAEhD,QAAO;EAAE,MAAM;EAAW,UAAU,QAAS,WAAmB,OAAO,cAAc;EAAE;AAIzF,KAAI,OAAO,YAAY,eAAe,QAAQ,UAAU,MAAM;EAC5D,MAAM,cAAc,SAAS,QAAQ,SAAS,KAAK,MAAM,IAAI,CAAC,MAAM,IAAI;EACxE,MAAM,mBAAmB,SAAS,QAAQ,SAAS,KAAK,MAAM,IAAI,CAAC,MAAM,IAAI;AAE7E,MAAI,cAAc,GAEhB,SACE,wBAAwB,QAAQ,SAAS,KAAK,8EAC/C;AAGH,SAAO;GACL,MAAM;GACN,SAAS,QAAQ,SAAS;GAC1B,OAAO;GACP,OAAO;GACP,cAAc,eAAe;GAC7B,UACE,QAAQ,QAAQ,IAAI,aAAa,IACjC,QAAQ,QAAQ,IAAI,eAAe,IACnC,QAAQ,QAAQ,IAAI,uBAAuB;GAC9C;;AAIH,QAAO,EAAE,MAAM,WAAW;;AAI5B,MAAM,cAAc,gBAAgB;;;;;;;;;;;;;;;AAgBpC,MAAa,8BAA8B;;;;;;AAO3C,SAAgB,YAAqB;AACnC,QACE,OAAO,eAAe,eACtB,YAAY,cACZ,OAAQ,WAAmB,WAAW,eACtC,OAAQ,WAAmB,OAAO,aAAa,eAC/C,OAAQ,WAAmB,OAAO,cAAc;;;;;;;;;;AAYpD,SAAgB,oBACd,YACA,gBACA,cACS;CACT,MAAM,gBAAgB,eAAe,iBAAiB;AAGtD,KAAI,mBAAmB,OACrB,QAAO;AAET,KAAI,cACF,QAAO;AAET,QAAO,gBAAgB"}
@@ -0,0 +1,33 @@
1
+ import { a as Breadcrumb, d as ObservabilityServer, f as ObservabilityUser, i as PluginLifecycle, l as ObservabilityContext, n as ObservabilityServerPlugin, o as LogLevel, t as ObservabilityPlugin, u as ObservabilityScope } from "./plugin-Bfq-o3nr.mjs";
2
+
3
+ //#region src/core/manager.d.ts
4
+ declare class ObservabilityManager implements ObservabilityServer {
5
+ private plugins;
6
+ private initialized;
7
+ private initializationPromise;
8
+ private lifecycle;
9
+ private initializationError;
10
+ constructor(lifecycle?: PluginLifecycle);
11
+ addPlugin(plugin: ObservabilityPlugin | ObservabilityServerPlugin): this;
12
+ getPlugin<T extends ObservabilityPlugin>(name: string): T | undefined;
13
+ getPlugins(): ObservabilityPlugin[];
14
+ listPlugins(): ObservabilityPlugin[];
15
+ initialize(): Promise<void>;
16
+ private doInitialize;
17
+ hasInitializationError(): boolean;
18
+ getInitializationError(): Error | null;
19
+ shutdown(): Promise<void>;
20
+ captureException(error: Error | unknown, context?: ObservabilityContext): void;
21
+ captureMessage(message: string, level?: LogLevel, context?: ObservabilityContext): void;
22
+ private validateUser;
23
+ setUser(user: ObservabilityUser | null): void;
24
+ addBreadcrumb(breadcrumb: Breadcrumb): void;
25
+ withScope(callback: (scope: ObservabilityScope) => void): void;
26
+ flush(timeout?: number): Promise<boolean>;
27
+ private broadcast;
28
+ hasEnabledPlugins(): boolean;
29
+ getEnabledPluginNames(): string[];
30
+ }
31
+ //#endregion
32
+ export { ObservabilityManager as t };
33
+ //# sourceMappingURL=manager-BxQqOPEg.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manager-BxQqOPEg.d.mts","names":[],"sources":["../src/core/manager.ts"],"mappings":";;;cAqBa,oBAAA,YAAgC,mBAAA;EAAA,QACnC,OAAA;EAAA,QACA,WAAA;EAAA,QACA,qBAAA;EAAA,QACA,SAAA;EAAA,QACA,mBAAA;cAOI,SAAA,GAAY,eAAA;EASxB,SAAA,CAAU,MAAA,EAAQ,mBAAA,GAAsB,yBAAA;EAWxC,SAAA,WAAoB,mBAAA,CAAA,CAAqB,IAAA,WAAe,CAAA;EASxD,UAAA,CAAA,GAAc,mBAAA;EASd,WAAA,CAAA,GAAe,mBAAA;EAST,UAAA,CAAA,GAAc,OAAA;EAAA,QA8BN,YAAA;EAiCd,sBAAA,CAAA;EAQA,sBAAA,CAAA,GAA0B,KAAA;EAOpB,QAAA,CAAA,GAAY,OAAA;EAyBlB,gBAAA,CAAiB,KAAA,EAAO,KAAA,YAAiB,OAAA,GAAU,oBAAA;EAWnD,cAAA,CAAe,OAAA,UAAiB,KAAA,GAAO,QAAA,EAAmB,OAAA,GAAU,oBAAA;EAAA,QAS5D,YAAA;EAiER,OAAA,CAAQ,IAAA,EAAM,iBAAA;EAUd,aAAA,CAAc,UAAA,EAAY,UAAA;EAS1B,SAAA,CAAU,QAAA,GAAW,KAAA,EAAO,kBAAA;EAYtB,KAAA,CAAM,OAAA,YAAmB,OAAA;EAAA,QAmBvB,SAAA;EA4BR,iBAAA,CAAA;EASA,qBAAA,CAAA;AAAA"}
@@ -0,0 +1,60 @@
1
+ //#region src/core/types.d.ts
2
+ interface ObservabilityUser {
3
+ id: string;
4
+ email?: string;
5
+ username?: string;
6
+ ip_address?: string;
7
+ [key: string]: unknown;
8
+ }
9
+ interface ObservabilityContext {
10
+ [key: string]: unknown;
11
+ }
12
+ interface ObservabilityScope {
13
+ setTag(key: string, value: string): void;
14
+ setExtra(key: string, value: unknown): void;
15
+ setUser(user: ObservabilityUser | null): void;
16
+ setLevel(level: LogLevel): void;
17
+ [key: string]: unknown;
18
+ }
19
+ type LogLevel = 'debug' | 'info' | 'warning' | 'error';
20
+ interface Breadcrumb {
21
+ message: string;
22
+ category?: string;
23
+ level?: LogLevel | 'critical';
24
+ data?: Record<string, unknown>;
25
+ timestamp?: number;
26
+ }
27
+ interface ObservabilityClient {
28
+ captureException(error: Error | unknown, context?: ObservabilityContext): void;
29
+ captureMessage(message: string, level?: LogLevel, context?: ObservabilityContext): void;
30
+ setUser(user: ObservabilityUser | null): void;
31
+ addBreadcrumb(breadcrumb: Breadcrumb): void;
32
+ withScope(callback: (scope: ObservabilityScope) => void): void;
33
+ }
34
+ interface ObservabilityServer extends ObservabilityClient {
35
+ flush(timeout?: number): Promise<boolean>;
36
+ }
37
+ interface ObservabilityConfig {
38
+ enabled?: boolean;
39
+ environment?: 'development' | 'preview' | 'production';
40
+ debug?: boolean;
41
+ }
42
+ //#endregion
43
+ //#region src/core/plugin.d.ts
44
+ interface ObservabilityPlugin<TClient = any> extends ObservabilityClient {
45
+ name: string;
46
+ enabled: boolean;
47
+ getClient(): TClient | undefined;
48
+ initialize?(config?: any): Promise<void>;
49
+ shutdown?(): Promise<void>;
50
+ }
51
+ interface ObservabilityServerPlugin<TClient = any> extends ObservabilityPlugin<TClient>, ObservabilityServer {}
52
+ type PluginFactory<TConfig = any, TPlugin = ObservabilityPlugin> = (config?: TConfig) => TPlugin;
53
+ interface PluginLifecycle {
54
+ onError?: (error: Error, plugin: ObservabilityPlugin) => void;
55
+ onInitialized?: (plugin: ObservabilityPlugin) => void;
56
+ onShutdown?: (plugin: ObservabilityPlugin) => void;
57
+ }
58
+ //#endregion
59
+ export { Breadcrumb as a, ObservabilityConfig as c, ObservabilityServer as d, ObservabilityUser as f, PluginLifecycle as i, ObservabilityContext as l, ObservabilityServerPlugin as n, LogLevel as o, PluginFactory as r, ObservabilityClient as s, ObservabilityPlugin as t, ObservabilityScope as u };
60
+ //# sourceMappingURL=plugin-Bfq-o3nr.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin-Bfq-o3nr.d.mts","names":[],"sources":["../src/core/types.ts","../src/core/plugin.ts"],"mappings":";UAYiB,iBAAA;EAEf,EAAA;EAEA,KAAA;EAEA,QAAA;EAEA,UAAA;EAAA,CAMC,GAAA;AAAA;AAAA,UASc,oBAAA;EAAA,CACd,GAAA;AAAA;AAAA,UASc,kBAAA;EACf,MAAA,CAAO,GAAA,UAAa,KAAA;EACpB,QAAA,CAAS,GAAA,UAAa,KAAA;EACtB,OAAA,CAAQ,IAAA,EAAM,iBAAA;EACd,QAAA,CAAS,KAAA,EAAO,QAAA;EAAA,CACf,GAAA;AAAA;AAAA,KAQS,QAAA;AAAA,UAQK,UAAA;EAEf,OAAA;EAEA,QAAA;EAEA,KAAA,GAAQ,QAAA;EAER,IAAA,GAAO,MAAA;EAEP,SAAA;AAAA;AAAA,UASe,mBAAA;EAOf,gBAAA,CAAiB,KAAA,EAAO,KAAA,YAAiB,OAAA,GAAU,oBAAA;EAQnD,cAAA,CAAe,OAAA,UAAiB,KAAA,GAAQ,QAAA,EAAU,OAAA,GAAU,oBAAA;EAM5D,OAAA,CAAQ,IAAA,EAAM,iBAAA;EAMd,aAAA,CAAc,UAAA,EAAY,UAAA;EAM1B,SAAA,CAAU,QAAA,GAAW,KAAA,EAAO,kBAAA;AAAA;AAAA,UASb,mBAAA,SAA4B,mBAAA;EAU3C,KAAA,CAAM,OAAA,YAAmB,OAAA;AAAA;AAAA,UAMV,mBAAA;EAEf,OAAA;EAEA,WAAA;EAEA,KAAA;AAAA;;;UC3Ie,mBAAA,wBAA2C,mBAAA;EAI1D,IAAA;EAKA,OAAA;EAMA,SAAA,IAAa,OAAA;EAKb,UAAA,EAAY,MAAA,SAAe,OAAA;EAK3B,QAAA,KAAa,OAAA;AAAA;AAAA,UAME,yBAAA,wBACP,mBAAA,CAAoB,OAAA,GAAU,mBAAA;AAAA,KAO5B,aAAA,0BAAuC,mBAAA,KACjD,MAAA,GAAS,OAAA,KACN,OAAA;AAAA,UAKY,eAAA;EACf,OAAA,IAAW,KAAA,EAAO,KAAA,EAAO,MAAA,EAAQ,mBAAA;EACjC,aAAA,IAAiB,MAAA,EAAQ,mBAAA;EACzB,UAAA,IAAc,MAAA,EAAQ,mBAAA;AAAA"}