@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.
- package/README.md +523 -0
- package/dist/client-next.d.mts +20 -0
- package/dist/client-next.d.mts.map +1 -0
- package/dist/client-next.mjs +64 -0
- package/dist/client-next.mjs.map +1 -0
- package/dist/client.d.mts +11 -0
- package/dist/client.d.mts.map +1 -0
- package/dist/client.mjs +47 -0
- package/dist/client.mjs.map +1 -0
- package/dist/env.d.mts +15 -0
- package/dist/env.d.mts.map +1 -0
- package/dist/env.mjs +45 -0
- package/dist/env.mjs.map +1 -0
- package/dist/factory-DkY353r8.mjs +380 -0
- package/dist/factory-DkY353r8.mjs.map +1 -0
- package/dist/hooks-useObservability.d.mts +11 -0
- package/dist/hooks-useObservability.d.mts.map +1 -0
- package/dist/hooks-useObservability.mjs +174 -0
- package/dist/hooks-useObservability.mjs.map +1 -0
- package/dist/index-CpcdzWrF.d.mts +24 -0
- package/dist/index-CpcdzWrF.d.mts.map +1 -0
- package/dist/index.d.mts +88 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +97 -0
- package/dist/index.mjs.map +1 -0
- package/dist/manager-BxQqOPEg.d.mts +33 -0
- package/dist/manager-BxQqOPEg.d.mts.map +1 -0
- package/dist/plugin-Bfq-o3nr.d.mts +60 -0
- package/dist/plugin-Bfq-o3nr.d.mts.map +1 -0
- package/dist/plugin-Bt-ygG1m.d.mts +254 -0
- package/dist/plugin-Bt-ygG1m.d.mts.map +1 -0
- package/dist/plugin-CLFwRERa.mjs +593 -0
- package/dist/plugin-CLFwRERa.mjs.map +1 -0
- package/dist/plugin-CP895lBx.mjs +534 -0
- package/dist/plugin-CP895lBx.mjs.map +1 -0
- package/dist/plugin-CaQxviDs.d.mts +61 -0
- package/dist/plugin-CaQxviDs.d.mts.map +1 -0
- package/dist/plugin-lPdJirTY.mjs +234 -0
- package/dist/plugin-lPdJirTY.mjs.map +1 -0
- package/dist/plugins-betterstack-env.d.mts +29 -0
- package/dist/plugins-betterstack-env.d.mts.map +1 -0
- package/dist/plugins-betterstack-env.mjs +75 -0
- package/dist/plugins-betterstack-env.mjs.map +1 -0
- package/dist/plugins-betterstack.d.mts +4 -0
- package/dist/plugins-betterstack.mjs +4 -0
- package/dist/plugins-console.d.mts +37 -0
- package/dist/plugins-console.d.mts.map +1 -0
- package/dist/plugins-console.mjs +196 -0
- package/dist/plugins-console.mjs.map +1 -0
- package/dist/plugins-sentry-env.d.mts +37 -0
- package/dist/plugins-sentry-env.d.mts.map +1 -0
- package/dist/plugins-sentry-env.mjs +79 -0
- package/dist/plugins-sentry-env.mjs.map +1 -0
- package/dist/plugins-sentry-microfrontend-env.d.mts +49 -0
- package/dist/plugins-sentry-microfrontend-env.d.mts.map +1 -0
- package/dist/plugins-sentry-microfrontend-env.mjs +80 -0
- package/dist/plugins-sentry-microfrontend-env.mjs.map +1 -0
- package/dist/plugins-sentry-microfrontend.d.mts +2 -0
- package/dist/plugins-sentry-microfrontend.mjs +3 -0
- package/dist/plugins-sentry.d.mts +5 -0
- package/dist/plugins-sentry.mjs +6 -0
- package/dist/server-edge.d.mts +15 -0
- package/dist/server-edge.d.mts.map +1 -0
- package/dist/server-edge.mjs +53 -0
- package/dist/server-edge.mjs.map +1 -0
- package/dist/server-next.d.mts +17 -0
- package/dist/server-next.d.mts.map +1 -0
- package/dist/server-next.mjs +64 -0
- package/dist/server-next.mjs.map +1 -0
- package/dist/server.d.mts +11 -0
- package/dist/server.d.mts.map +1 -0
- package/dist/server.mjs +48 -0
- package/dist/server.mjs.map +1 -0
- package/dist/utils-CuGrTcD6.d.mts +77 -0
- package/dist/utils-CuGrTcD6.d.mts.map +1 -0
- package/env.ts +67 -0
- package/package.json +147 -0
- package/src/client-next.ts +131 -0
- package/src/client.ts +70 -0
- package/src/core/index.ts +15 -0
- package/src/core/manager.ts +361 -0
- package/src/core/plugin.ts +61 -0
- package/src/core/types.ts +151 -0
- package/src/factory/builder.ts +132 -0
- package/src/factory/index.ts +67 -0
- package/src/factory/presets.ts +78 -0
- package/src/hooks/useObservability.ts +206 -0
- package/src/plugins/betterstack/env.ts +101 -0
- package/src/plugins/betterstack/index.ts +15 -0
- package/src/plugins/betterstack/plugin.ts +373 -0
- package/src/plugins/console/index.ts +323 -0
- package/src/plugins/sentry/__tests__/plugin-tracing.test.ts +511 -0
- package/src/plugins/sentry/env.ts +93 -0
- package/src/plugins/sentry/index.ts +28 -0
- package/src/plugins/sentry/plugin.ts +953 -0
- package/src/plugins/sentry/types.ts +252 -0
- package/src/plugins/sentry-microfrontend/env.ts +105 -0
- package/src/plugins/sentry-microfrontend/index.ts +12 -0
- package/src/plugins/sentry-microfrontend/multiplexed-transport.ts +221 -0
- package/src/plugins/sentry-microfrontend/plugin.ts +500 -0
- package/src/plugins/sentry-microfrontend/sentry-types.ts +140 -0
- package/src/plugins/sentry-microfrontend/types.ts +130 -0
- package/src/plugins/sentry-microfrontend/utils.ts +326 -0
- package/src/server-edge.ts +113 -0
- package/src/server-next.ts +114 -0
- package/src/server.ts +71 -0
- package/src/shared.ts +148 -0
package/dist/env.d.mts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//#region env.d.ts
|
|
2
|
+
declare const env: Readonly<{
|
|
3
|
+
NEXT_PUBLIC_OBSERVABILITY_CONSOLE_ENABLED?: boolean | undefined;
|
|
4
|
+
NEXT_PUBLIC_NODE_ENV: "development" | "production" | "test";
|
|
5
|
+
NEXT_PUBLIC_OBSERVABILITY_DEBUG: boolean;
|
|
6
|
+
}>;
|
|
7
|
+
declare function safeEnv(): Readonly<{
|
|
8
|
+
NEXT_PUBLIC_OBSERVABILITY_CONSOLE_ENABLED?: boolean | undefined;
|
|
9
|
+
NEXT_PUBLIC_NODE_ENV: "development" | "production" | "test";
|
|
10
|
+
NEXT_PUBLIC_OBSERVABILITY_DEBUG: boolean;
|
|
11
|
+
}>;
|
|
12
|
+
type Env = typeof env;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { Env, env, safeEnv };
|
|
15
|
+
//# sourceMappingURL=env.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.d.mts","names":[],"sources":["../env.ts"],"mappings":";cAWa,GAAA,EAAG,QAAA;;;;;iBAiCA,OAAA,CAAA,GAAO,QAAA;;;;;KAsBX,GAAA,UAAa,GAAA"}
|
package/dist/env.mjs
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { logWarn } from "@od-oneapp/shared/logger";
|
|
2
|
+
import { createEnv } from "@t3-oss/env-core";
|
|
3
|
+
import { z } from "zod/v4";
|
|
4
|
+
|
|
5
|
+
//#region env.ts
|
|
6
|
+
/**
|
|
7
|
+
* @fileoverview Core environment configuration for the observability package
|
|
8
|
+
* Core environment configuration for the observability package
|
|
9
|
+
* Provider-specific configurations are handled by their respective plugins
|
|
10
|
+
*/
|
|
11
|
+
const env = createEnv({
|
|
12
|
+
server: {},
|
|
13
|
+
clientPrefix: "NEXT_PUBLIC_",
|
|
14
|
+
client: {
|
|
15
|
+
NEXT_PUBLIC_NODE_ENV: z.enum([
|
|
16
|
+
"development",
|
|
17
|
+
"test",
|
|
18
|
+
"production"
|
|
19
|
+
]).default("development"),
|
|
20
|
+
NEXT_PUBLIC_OBSERVABILITY_DEBUG: z.string().optional().transform((val) => val === "true").default(false),
|
|
21
|
+
NEXT_PUBLIC_OBSERVABILITY_CONSOLE_ENABLED: z.string().optional().transform((val) => val === "true" ? true : val === "false" ? false : void 0)
|
|
22
|
+
},
|
|
23
|
+
runtimeEnv: process.env,
|
|
24
|
+
emptyStringAsUndefined: true,
|
|
25
|
+
onInvalidAccess: (variable) => {
|
|
26
|
+
throw new Error(`❌ Attempted to access a server-side environment variable on the client: ${variable}`);
|
|
27
|
+
},
|
|
28
|
+
onValidationError: (error) => {
|
|
29
|
+
logWarn("Observability package environment validation failed", { error });
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
function safeEnv() {
|
|
33
|
+
try {
|
|
34
|
+
if (env && typeof env === "object") return env;
|
|
35
|
+
} catch {}
|
|
36
|
+
return {
|
|
37
|
+
NEXT_PUBLIC_NODE_ENV: "development",
|
|
38
|
+
NEXT_PUBLIC_OBSERVABILITY_DEBUG: process.env.NEXT_PUBLIC_OBSERVABILITY_DEBUG === "true",
|
|
39
|
+
NEXT_PUBLIC_OBSERVABILITY_CONSOLE_ENABLED: process.env.NEXT_PUBLIC_OBSERVABILITY_CONSOLE_ENABLED === "true" ? true : process.env.NEXT_PUBLIC_OBSERVABILITY_CONSOLE_ENABLED === "false" ? false : void 0
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
//#endregion
|
|
44
|
+
export { env, safeEnv };
|
|
45
|
+
//# sourceMappingURL=env.mjs.map
|
package/dist/env.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.mjs","names":[],"sources":["../env.ts"],"sourcesContent":["/**\n * @fileoverview Core environment configuration for the observability package\n * Core environment configuration for the observability package\n * Provider-specific configurations are handled by their respective plugins\n */\n\nimport { logWarn } from '@repo/shared/logger';\nimport { createEnv } from '@t3-oss/env-core';\nimport { z } from 'zod/v4';\n\n// Create validated env object\nexport const env = createEnv({\n server: {\n // Core observability config only - providers handle their own\n },\n clientPrefix: 'NEXT_PUBLIC_',\n client: {\n // Core configuration available on both client and server\n NEXT_PUBLIC_NODE_ENV: z.enum(['development', 'test', 'production']).default('development'),\n NEXT_PUBLIC_OBSERVABILITY_DEBUG: z\n .string()\n .optional()\n .transform(val => val === 'true')\n .default(false),\n NEXT_PUBLIC_OBSERVABILITY_CONSOLE_ENABLED: z\n .string()\n .optional()\n .transform(val => (val === 'true' ? true : val === 'false' ? false : undefined)),\n },\n runtimeEnv: process.env,\n emptyStringAsUndefined: true,\n onInvalidAccess: (variable: string) => {\n throw new Error(\n `❌ Attempted to access a server-side environment variable on the client: ${variable}`,\n );\n },\n onValidationError: error => {\n logWarn('Observability package environment validation failed', { error });\n // Don't throw in packages - use fallbacks\n return undefined as never;\n },\n});\n\n// Helper for non-Next.js contexts (Node.js, workers, tests)\nexport function safeEnv() {\n try {\n if (env && typeof env === 'object') return env;\n } catch {\n // Environment validation failed, use fallbacks\n }\n\n // Fallback values for resilience\n return {\n // Core configuration only\n NEXT_PUBLIC_NODE_ENV: process.env.NODE_ENV ?? 'development',\n NEXT_PUBLIC_OBSERVABILITY_DEBUG: process.env.NEXT_PUBLIC_OBSERVABILITY_DEBUG === 'true',\n NEXT_PUBLIC_OBSERVABILITY_CONSOLE_ENABLED:\n process.env.NEXT_PUBLIC_OBSERVABILITY_CONSOLE_ENABLED === 'true'\n ? true\n : process.env.NEXT_PUBLIC_OBSERVABILITY_CONSOLE_ENABLED === 'false'\n ? false\n : undefined,\n };\n}\n\n// Export type\nexport type Env = typeof env;\n"],"mappings":";;;;;;;;;;AAWA,MAAa,MAAM,UAAU;CAC3B,QAAQ,EAEP;CACD,cAAc;CACd,QAAQ;EAEN,sBAAsB,EAAE,KAAK;GAAC;GAAe;GAAQ;GAAa,CAAC,CAAC,QAAQ,cAAc;EAC1F,iCAAiC,EAC9B,QAAQ,CACR,UAAU,CACV,WAAU,QAAO,QAAQ,OAAO,CAChC,QAAQ,MAAM;EACjB,2CAA2C,EACxC,QAAQ,CACR,UAAU,CACV,WAAU,QAAQ,QAAQ,SAAS,OAAO,QAAQ,UAAU,QAAQ,OAAW;EACnF;CACD,YAAY,QAAQ;CACpB,wBAAwB;CACxB,kBAAkB,aAAqB;AACrC,QAAM,IAAI,MACR,2EAA2E,WAC5E;;CAEH,oBAAmB,UAAS;AAC1B,UAAQ,uDAAuD,EAAE,OAAO,CAAC;;CAI5E,CAAC;AAGF,SAAgB,UAAU;AACxB,KAAI;AACF,MAAI,OAAO,OAAO,QAAQ,SAAU,QAAO;SACrC;AAKR,QAAO;EAEL;EACA,iCAAiC,QAAQ,IAAI,oCAAoC;EACjF,2CACE,QAAQ,IAAI,8CAA8C,SACtD,OACA,QAAQ,IAAI,8CAA8C,UACxD,QACA;EACT"}
|
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
import { logError, logWarn } from "@od-oneapp/shared/logs";
|
|
2
|
+
|
|
3
|
+
//#region src/core/manager.ts
|
|
4
|
+
/**
|
|
5
|
+
* @fileoverview ObservabilityManager - Core orchestrator for multiple observability providers
|
|
6
|
+
* ObservabilityManager - Core orchestrator for multiple observability providers
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Manager that orchestrates multiple observability plugins
|
|
10
|
+
* Broadcasts all method calls to enabled plugins
|
|
11
|
+
*/
|
|
12
|
+
var ObservabilityManager = class {
|
|
13
|
+
plugins = /* @__PURE__ */ new Map();
|
|
14
|
+
initialized = false;
|
|
15
|
+
initializationPromise = null;
|
|
16
|
+
lifecycle = {};
|
|
17
|
+
initializationError = null;
|
|
18
|
+
/**
|
|
19
|
+
* Create a new ObservabilityManager instance.
|
|
20
|
+
*
|
|
21
|
+
* @param lifecycle - Optional lifecycle callbacks for plugin events
|
|
22
|
+
*/
|
|
23
|
+
constructor(lifecycle) {
|
|
24
|
+
if (lifecycle) this.lifecycle = lifecycle;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Add a plugin to the manager
|
|
28
|
+
*/
|
|
29
|
+
addPlugin(plugin) {
|
|
30
|
+
this.plugins.set(plugin.name, plugin);
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Get a specific plugin by name.
|
|
35
|
+
*
|
|
36
|
+
* @param name - Name of the plugin to retrieve
|
|
37
|
+
* @returns Plugin instance if found, undefined otherwise
|
|
38
|
+
*/
|
|
39
|
+
getPlugin(name) {
|
|
40
|
+
return this.plugins.get(name);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Get all registered plugins.
|
|
44
|
+
*
|
|
45
|
+
* @returns Array of all registered plugins
|
|
46
|
+
*/
|
|
47
|
+
getPlugins() {
|
|
48
|
+
return Array.from(this.plugins.values());
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* List all registered plugins (alias for getPlugins).
|
|
52
|
+
*
|
|
53
|
+
* @returns Array of all registered plugins
|
|
54
|
+
*/
|
|
55
|
+
listPlugins() {
|
|
56
|
+
return this.getPlugins();
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Initialize all plugins
|
|
60
|
+
* Note: Failed initialization is retryable - subsequent calls will re-attempt initialization.
|
|
61
|
+
* This allows recovery from transient failures (network issues, temporary misconfigurations).
|
|
62
|
+
*/
|
|
63
|
+
async initialize() {
|
|
64
|
+
if (this.initializationPromise) return this.initializationPromise;
|
|
65
|
+
if (this.initialized) return;
|
|
66
|
+
if (this.initializationError) {
|
|
67
|
+
logWarn("ObservabilityManager: Retrying failed initialization");
|
|
68
|
+
this.initializationError = null;
|
|
69
|
+
}
|
|
70
|
+
this.initializationPromise = this.doInitialize();
|
|
71
|
+
try {
|
|
72
|
+
await this.initializationPromise;
|
|
73
|
+
} finally {
|
|
74
|
+
this.initializationPromise = null;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
async doInitialize() {
|
|
78
|
+
const initPromises = Array.from(this.plugins.values()).filter((plugin) => plugin.enabled && plugin.initialize).map(async (plugin) => {
|
|
79
|
+
try {
|
|
80
|
+
if (plugin.initialize) await plugin.initialize();
|
|
81
|
+
this.lifecycle.onInitialized?.(plugin);
|
|
82
|
+
} catch (error) {
|
|
83
|
+
logError(`Failed to initialize plugin ${plugin.name}`, {
|
|
84
|
+
error,
|
|
85
|
+
pluginName: plugin.name
|
|
86
|
+
});
|
|
87
|
+
this.lifecycle.onError?.(error, plugin);
|
|
88
|
+
throw error;
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
try {
|
|
92
|
+
await Promise.all(initPromises);
|
|
93
|
+
this.initialized = true;
|
|
94
|
+
} catch (error) {
|
|
95
|
+
this.initializationError = error instanceof Error ? error : new Error(String(error));
|
|
96
|
+
throw this.initializationError;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Check if initialization had an error
|
|
101
|
+
* @returns `true` if initialization failed, `false` otherwise
|
|
102
|
+
*/
|
|
103
|
+
hasInitializationError() {
|
|
104
|
+
return this.initializationError !== null;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Get the initialization error if one occurred
|
|
108
|
+
* @returns The initialization error or `null` if no error
|
|
109
|
+
*/
|
|
110
|
+
getInitializationError() {
|
|
111
|
+
return this.initializationError;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Shutdown all plugins
|
|
115
|
+
*/
|
|
116
|
+
async shutdown() {
|
|
117
|
+
const shutdownPromises = Array.from(this.plugins.values()).filter((plugin) => plugin.shutdown).map(async (plugin) => {
|
|
118
|
+
try {
|
|
119
|
+
if (plugin.shutdown) await plugin.shutdown();
|
|
120
|
+
this.lifecycle.onShutdown?.(plugin);
|
|
121
|
+
} catch (error) {
|
|
122
|
+
logError(`Failed to shutdown plugin ${plugin.name}`, {
|
|
123
|
+
error,
|
|
124
|
+
pluginName: plugin.name
|
|
125
|
+
});
|
|
126
|
+
this.lifecycle.onError?.(error, plugin);
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
await Promise.allSettled(shutdownPromises);
|
|
130
|
+
this.initialized = false;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Broadcast exception to all enabled plugins.
|
|
134
|
+
*
|
|
135
|
+
* @param error - Error object or unknown error value
|
|
136
|
+
* @param context - Optional additional context data
|
|
137
|
+
*/
|
|
138
|
+
captureException(error, context) {
|
|
139
|
+
this.broadcast((plugin) => plugin.captureException(error, context));
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Broadcast message to all enabled plugins.
|
|
143
|
+
*
|
|
144
|
+
* @param message - Message to log
|
|
145
|
+
* @param level - Log level (default: 'info')
|
|
146
|
+
* @param context - Optional additional context data
|
|
147
|
+
*/
|
|
148
|
+
captureMessage(message, level = "info", context) {
|
|
149
|
+
this.broadcast((plugin) => plugin.captureMessage(message, level, context));
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Validate and sanitize user data to prevent injection and DoS attacks
|
|
153
|
+
* @param user - User data to validate
|
|
154
|
+
* @returns Validated user data with length limits and format validation applied
|
|
155
|
+
*/
|
|
156
|
+
validateUser(user) {
|
|
157
|
+
if (!user) return null;
|
|
158
|
+
const id = String(user.id).trim().slice(0, 255);
|
|
159
|
+
if (!id) {
|
|
160
|
+
logWarn("ObservabilityManager: User ID is empty, ignoring user data");
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
const validated = { id };
|
|
164
|
+
if ("email" in user && user.email) {
|
|
165
|
+
const email = String(user.email).trim().slice(0, 255);
|
|
166
|
+
if (email && /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/.test(email)) validated.email = email;
|
|
167
|
+
}
|
|
168
|
+
if ("username" in user && user.username) {
|
|
169
|
+
const username = String(user.username).trim().slice(0, 255);
|
|
170
|
+
if (username) validated.username = username;
|
|
171
|
+
}
|
|
172
|
+
if ("ip_address" in user && user.ip_address) {
|
|
173
|
+
const ip = String(user.ip_address).trim();
|
|
174
|
+
const isValidIPv4 = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(ip);
|
|
175
|
+
const looksLikeIPv6 = /^[0-9a-fA-F:]+$/.test(ip) && ip.includes(":") && ip.split(":").length <= 8;
|
|
176
|
+
if (isValidIPv4 || looksLikeIPv6) validated.ip_address = ip.slice(0, 45);
|
|
177
|
+
}
|
|
178
|
+
return validated;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Set user on all enabled plugins
|
|
182
|
+
* User data is validated and sanitized before being set
|
|
183
|
+
* @param user - User data to set (will be validated)
|
|
184
|
+
*/
|
|
185
|
+
setUser(user) {
|
|
186
|
+
const validatedUser = this.validateUser(user);
|
|
187
|
+
this.broadcast((plugin) => plugin.setUser(validatedUser));
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Add breadcrumb to all enabled plugins.
|
|
191
|
+
*
|
|
192
|
+
* @param breadcrumb - Breadcrumb data to add
|
|
193
|
+
*/
|
|
194
|
+
addBreadcrumb(breadcrumb) {
|
|
195
|
+
this.broadcast((plugin) => plugin.addBreadcrumb(breadcrumb));
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Execute callback within scope for all enabled plugins.
|
|
199
|
+
*
|
|
200
|
+
* @param callback - Callback that receives the scope
|
|
201
|
+
*/
|
|
202
|
+
withScope(callback) {
|
|
203
|
+
this.broadcast((plugin) => plugin.withScope(callback));
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Flush all plugins that support it.
|
|
207
|
+
*
|
|
208
|
+
* Waits for all enabled plugins with flush capability to send pending events.
|
|
209
|
+
*
|
|
210
|
+
* @param timeout - Maximum time to wait in milliseconds
|
|
211
|
+
* @returns Promise resolving to true if all plugins flushed successfully
|
|
212
|
+
*/
|
|
213
|
+
async flush(timeout) {
|
|
214
|
+
const flushPromises = Array.from(this.plugins.values()).filter((plugin) => {
|
|
215
|
+
return plugin.enabled && "flush" in plugin && typeof plugin.flush === "function";
|
|
216
|
+
}).map((plugin) => plugin.flush(timeout));
|
|
217
|
+
if (flushPromises.length === 0) return true;
|
|
218
|
+
return (await Promise.allSettled(flushPromises)).every((result) => result.status === "fulfilled" && result.value === true);
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Helper to broadcast a method call to all enabled plugins
|
|
222
|
+
* Uses nested try-catch to ensure errors in error handling don't prevent other plugins from executing
|
|
223
|
+
*/
|
|
224
|
+
broadcast(fn) {
|
|
225
|
+
this.plugins.forEach((plugin) => {
|
|
226
|
+
if (plugin.enabled) try {
|
|
227
|
+
fn(plugin);
|
|
228
|
+
} catch (error) {
|
|
229
|
+
try {
|
|
230
|
+
logError(`Plugin ${plugin.name} error`, {
|
|
231
|
+
error,
|
|
232
|
+
pluginName: plugin.name
|
|
233
|
+
});
|
|
234
|
+
} catch {}
|
|
235
|
+
try {
|
|
236
|
+
this.lifecycle.onError?.(error, plugin);
|
|
237
|
+
} catch {}
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Check if manager has any enabled plugins.
|
|
243
|
+
*
|
|
244
|
+
* @returns True if at least one plugin is enabled, false otherwise
|
|
245
|
+
*/
|
|
246
|
+
hasEnabledPlugins() {
|
|
247
|
+
return Array.from(this.plugins.values()).some((plugin) => plugin.enabled);
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Get names of all enabled plugins.
|
|
251
|
+
*
|
|
252
|
+
* @returns Array of plugin names that are currently enabled
|
|
253
|
+
*/
|
|
254
|
+
getEnabledPluginNames() {
|
|
255
|
+
return Array.from(this.plugins.values()).filter((plugin) => plugin.enabled).map((plugin) => plugin.name);
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
//#endregion
|
|
260
|
+
//#region src/factory/builder.ts
|
|
261
|
+
/**
|
|
262
|
+
* @fileoverview ObservabilityBuilder - Fluent API for building observability instances
|
|
263
|
+
* ObservabilityBuilder - Fluent API for building observability instances
|
|
264
|
+
*/
|
|
265
|
+
/**
|
|
266
|
+
* Builder for creating configured ObservabilityManager instances
|
|
267
|
+
*/
|
|
268
|
+
var ObservabilityBuilder = class ObservabilityBuilder {
|
|
269
|
+
plugins = [];
|
|
270
|
+
lifecycle = {};
|
|
271
|
+
autoInitialize = true;
|
|
272
|
+
/**
|
|
273
|
+
* Add a plugin to the observability stack
|
|
274
|
+
* @param plugin - Observability plugin to add
|
|
275
|
+
* @returns Builder instance for chaining
|
|
276
|
+
*/
|
|
277
|
+
withPlugin(plugin) {
|
|
278
|
+
if (plugin) this.plugins.push(plugin);
|
|
279
|
+
return this;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Add multiple plugins at once
|
|
283
|
+
* @param plugins - Array of observability plugins to add
|
|
284
|
+
* @returns Builder instance for chaining
|
|
285
|
+
*/
|
|
286
|
+
withPlugins(plugins) {
|
|
287
|
+
if (plugins && Array.isArray(plugins)) {
|
|
288
|
+
const validPlugins = plugins.filter((plugin) => plugin != null);
|
|
289
|
+
this.plugins.push(...validPlugins);
|
|
290
|
+
}
|
|
291
|
+
return this;
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Set lifecycle callbacks for plugin management
|
|
295
|
+
* @param lifecycle - Lifecycle callback configuration
|
|
296
|
+
* @returns Builder instance for chaining
|
|
297
|
+
*/
|
|
298
|
+
withLifecycle(lifecycle) {
|
|
299
|
+
this.lifecycle = {
|
|
300
|
+
...this.lifecycle,
|
|
301
|
+
...lifecycle
|
|
302
|
+
};
|
|
303
|
+
return this;
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Configure whether to auto-initialize plugins (default: true)
|
|
307
|
+
*/
|
|
308
|
+
withAutoInitialize(autoInitialize) {
|
|
309
|
+
this.autoInitialize = autoInitialize;
|
|
310
|
+
return this;
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Build the ObservabilityManager instance
|
|
314
|
+
* @returns Configured ObservabilityManager instance
|
|
315
|
+
*/
|
|
316
|
+
build() {
|
|
317
|
+
const manager = new ObservabilityManager(this.lifecycle);
|
|
318
|
+
this.plugins.forEach((plugin) => manager.addPlugin(plugin));
|
|
319
|
+
if (this.autoInitialize && typeof process !== "undefined" && process.env.NEXT_RUNTIME !== "edge") (async () => {
|
|
320
|
+
try {
|
|
321
|
+
await manager.initialize();
|
|
322
|
+
} catch (error) {
|
|
323
|
+
try {
|
|
324
|
+
logError("Failed to initialize observability", { error });
|
|
325
|
+
} catch {}
|
|
326
|
+
}
|
|
327
|
+
})();
|
|
328
|
+
return manager;
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Build and initialize the ObservabilityManager instance
|
|
332
|
+
* @returns Promise resolving to initialized ObservabilityManager
|
|
333
|
+
*/
|
|
334
|
+
async buildWithAutoInit() {
|
|
335
|
+
const manager = new ObservabilityManager(this.lifecycle);
|
|
336
|
+
this.plugins.forEach((plugin) => manager.addPlugin(plugin));
|
|
337
|
+
try {
|
|
338
|
+
await manager.initialize();
|
|
339
|
+
} catch {}
|
|
340
|
+
return manager;
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Create a new builder instance
|
|
344
|
+
* @returns New ObservabilityBuilder instance
|
|
345
|
+
*/
|
|
346
|
+
static create() {
|
|
347
|
+
return new ObservabilityBuilder();
|
|
348
|
+
}
|
|
349
|
+
};
|
|
350
|
+
|
|
351
|
+
//#endregion
|
|
352
|
+
//#region src/factory/index.ts
|
|
353
|
+
/**
|
|
354
|
+
* Create an observability instance with the provided plugins.
|
|
355
|
+
*
|
|
356
|
+
* Factory function that creates a configured ObservabilityManager with the given plugins.
|
|
357
|
+
* Provides a simpler API than using ObservabilityBuilder directly.
|
|
358
|
+
*
|
|
359
|
+
* @param plugins - Array of observability plugins to include
|
|
360
|
+
* @param options - Optional configuration options
|
|
361
|
+
* @param options.autoInitialize - Whether to auto-initialize plugins (default: true)
|
|
362
|
+
* @returns Configured ObservabilityManager instance
|
|
363
|
+
*
|
|
364
|
+
* @example
|
|
365
|
+
* ```typescript
|
|
366
|
+
* const obs = createObservability([
|
|
367
|
+
* createConsolePlugin(),
|
|
368
|
+
* createSentryPlugin({ dsn: '...' }),
|
|
369
|
+
* ], { autoInitialize: true });
|
|
370
|
+
* ```
|
|
371
|
+
*/
|
|
372
|
+
function createObservability(plugins, options) {
|
|
373
|
+
const builder = new ObservabilityBuilder();
|
|
374
|
+
if (options?.autoInitialize !== void 0) builder.withAutoInitialize(options.autoInitialize);
|
|
375
|
+
return builder.withPlugins(plugins).build();
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
//#endregion
|
|
379
|
+
export { ObservabilityBuilder as n, ObservabilityManager as r, createObservability as t };
|
|
380
|
+
//# sourceMappingURL=factory-DkY353r8.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory-DkY353r8.mjs","names":[],"sources":["../src/core/manager.ts","../src/factory/builder.ts","../src/factory/index.ts"],"sourcesContent":["/**\n * @fileoverview ObservabilityManager - Core orchestrator for multiple observability providers\n * ObservabilityManager - Core orchestrator for multiple observability providers\n */\n\nimport { logError, logWarn } from '@repo/shared/logs';\n\nimport type { ObservabilityPlugin, ObservabilityServerPlugin, PluginLifecycle } from './plugin';\nimport type {\n Breadcrumb,\n LogLevel,\n ObservabilityContext,\n ObservabilityScope,\n ObservabilityServer,\n ObservabilityUser,\n} from './types';\n\n/**\n * Manager that orchestrates multiple observability plugins\n * Broadcasts all method calls to enabled plugins\n */\nexport class ObservabilityManager implements ObservabilityServer {\n private plugins = new Map<string, ObservabilityPlugin | ObservabilityServerPlugin>();\n private initialized = false;\n private initializationPromise: Promise<void> | null = null;\n private lifecycle: PluginLifecycle = {};\n private initializationError: Error | null = null;\n\n /**\n * Create a new ObservabilityManager instance.\n *\n * @param lifecycle - Optional lifecycle callbacks for plugin events\n */\n constructor(lifecycle?: PluginLifecycle) {\n if (lifecycle) {\n this.lifecycle = lifecycle;\n }\n }\n\n /**\n * Add a plugin to the manager\n */\n addPlugin(plugin: ObservabilityPlugin | ObservabilityServerPlugin): this {\n this.plugins.set(plugin.name, plugin);\n return this;\n }\n\n /**\n * Get a specific plugin by name.\n *\n * @param name - Name of the plugin to retrieve\n * @returns Plugin instance if found, undefined otherwise\n */\n getPlugin<T extends ObservabilityPlugin>(name: string): T | undefined {\n return this.plugins.get(name) as T;\n }\n\n /**\n * Get all registered plugins.\n *\n * @returns Array of all registered plugins\n */\n getPlugins(): ObservabilityPlugin[] {\n return Array.from(this.plugins.values());\n }\n\n /**\n * List all registered plugins (alias for getPlugins).\n *\n * @returns Array of all registered plugins\n */\n listPlugins(): ObservabilityPlugin[] {\n return this.getPlugins();\n }\n\n /**\n * Initialize all plugins\n * Note: Failed initialization is retryable - subsequent calls will re-attempt initialization.\n * This allows recovery from transient failures (network issues, temporary misconfigurations).\n */\n async initialize(): Promise<void> {\n // If there's already an initialization in progress, wait for it\n if (this.initializationPromise) {\n return this.initializationPromise;\n }\n\n // If already initialized successfully, return early\n if (this.initialized) {\n return;\n }\n\n // Allow retry if previous attempt failed\n if (this.initializationError) {\n // Log retry attempt for debugging\n logWarn('ObservabilityManager: Retrying failed initialization');\n // Clear previous error to allow fresh attempt\n this.initializationError = null;\n }\n\n // Create the initialization promise and store it to prevent concurrent calls\n this.initializationPromise = this.doInitialize();\n\n try {\n await this.initializationPromise;\n } finally {\n // Clear the promise after initialization completes (success or failure)\n this.initializationPromise = null;\n }\n }\n\n private async doInitialize(): Promise<void> {\n const initPromises = Array.from(this.plugins.values())\n .filter(plugin => plugin.enabled && plugin.initialize)\n .map(async plugin => {\n try {\n if (plugin.initialize) {\n await plugin.initialize();\n }\n this.lifecycle.onInitialized?.(plugin);\n } catch (error) {\n logError(`Failed to initialize plugin ${plugin.name}`, {\n error,\n pluginName: plugin.name,\n });\n this.lifecycle.onError?.(error as Error, plugin);\n // Re-throw to propagate error to Promise.all\n throw error;\n }\n });\n\n try {\n await Promise.all(initPromises);\n this.initialized = true;\n } catch (error) {\n this.initializationError = error instanceof Error ? error : new Error(String(error));\n throw this.initializationError;\n }\n }\n\n /**\n * Check if initialization had an error\n * @returns `true` if initialization failed, `false` otherwise\n */\n hasInitializationError(): boolean {\n return this.initializationError !== null;\n }\n\n /**\n * Get the initialization error if one occurred\n * @returns The initialization error or `null` if no error\n */\n getInitializationError(): Error | null {\n return this.initializationError;\n }\n\n /**\n * Shutdown all plugins\n */\n async shutdown(): Promise<void> {\n const shutdownPromises = Array.from(this.plugins.values())\n .filter(plugin => plugin.shutdown)\n .map(async plugin => {\n try {\n if (plugin.shutdown) {\n await plugin.shutdown();\n }\n this.lifecycle.onShutdown?.(plugin);\n } catch (error) {\n logError(`Failed to shutdown plugin ${plugin.name}`, { error, pluginName: plugin.name });\n this.lifecycle.onError?.(error as Error, plugin);\n }\n });\n\n await Promise.allSettled(shutdownPromises);\n this.initialized = false;\n }\n\n /**\n * Broadcast exception to all enabled plugins.\n *\n * @param error - Error object or unknown error value\n * @param context - Optional additional context data\n */\n captureException(error: Error | unknown, context?: ObservabilityContext): void {\n this.broadcast(plugin => plugin.captureException(error, context));\n }\n\n /**\n * Broadcast message to all enabled plugins.\n *\n * @param message - Message to log\n * @param level - Log level (default: 'info')\n * @param context - Optional additional context data\n */\n captureMessage(message: string, level: LogLevel = 'info', context?: ObservabilityContext): void {\n this.broadcast(plugin => plugin.captureMessage(message, level, context));\n }\n\n /**\n * Validate and sanitize user data to prevent injection and DoS attacks\n * @param user - User data to validate\n * @returns Validated user data with length limits and format validation applied\n */\n private validateUser(user: ObservabilityUser | null): ObservabilityUser | null {\n if (!user) return null;\n\n // Validate required ID field\n const id = String(user.id).trim().slice(0, 255);\n if (!id) {\n // Log warning but don't throw - graceful degradation\n logWarn('ObservabilityManager: User ID is empty, ignoring user data');\n return null;\n }\n\n const validated: ObservabilityUser = { id };\n\n // Validate email format if provided\n if ('email' in user && user.email) {\n const email = String(user.email).trim().slice(0, 255);\n // More robust email validation - RFC 5322 simplified but stricter\n // Allows: alphanumeric, dots, plus, hyphens, underscores before @\n // Requires: valid domain with at least one dot after @\n if (\n email &&\n // eslint-disable-next-line security/detect-unsafe-regex -- Safe: bounded input (max 255 chars), RFC 5322 compliant pattern\n /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/.test(\n email,\n )\n ) {\n validated.email = email;\n }\n }\n\n // Validate username if provided\n if ('username' in user && user.username) {\n const username = String(user.username).trim().slice(0, 255);\n if (username) {\n validated.username = username;\n }\n }\n\n // Validate IP address format if provided\n if ('ip_address' in user && user.ip_address) {\n const ip = String(user.ip_address).trim();\n // Stricter IP validation\n // IPv4: Each octet must be 0-255\n const isValidIPv4 =\n // eslint-disable-next-line security/detect-unsafe-regex -- Safe: bounded pattern for IPv4 validation, input is trimmed string\n /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(\n ip,\n );\n // IPv6: Basic format check (full validation is complex, this catches most invalid cases)\n const looksLikeIPv6 =\n /^[0-9a-fA-F:]+$/.test(ip) && ip.includes(':') && ip.split(':').length <= 8;\n\n if (isValidIPv4 || looksLikeIPv6) {\n validated.ip_address = ip.slice(0, 45); // IPv6 max length\n }\n }\n\n return validated;\n }\n\n /**\n * Set user on all enabled plugins\n * User data is validated and sanitized before being set\n * @param user - User data to set (will be validated)\n */\n setUser(user: ObservabilityUser | null): void {\n const validatedUser = this.validateUser(user);\n this.broadcast(plugin => plugin.setUser(validatedUser));\n }\n\n /**\n * Add breadcrumb to all enabled plugins.\n *\n * @param breadcrumb - Breadcrumb data to add\n */\n addBreadcrumb(breadcrumb: Breadcrumb): void {\n this.broadcast(plugin => plugin.addBreadcrumb(breadcrumb));\n }\n\n /**\n * Execute callback within scope for all enabled plugins.\n *\n * @param callback - Callback that receives the scope\n */\n withScope(callback: (scope: ObservabilityScope) => void): void {\n this.broadcast(plugin => plugin.withScope(callback));\n }\n\n /**\n * Flush all plugins that support it.\n *\n * Waits for all enabled plugins with flush capability to send pending events.\n *\n * @param timeout - Maximum time to wait in milliseconds\n * @returns Promise resolving to true if all plugins flushed successfully\n */\n async flush(timeout?: number): Promise<boolean> {\n const flushPromises = Array.from(this.plugins.values())\n .filter((plugin): plugin is ObservabilityServerPlugin => {\n return plugin.enabled && 'flush' in plugin && typeof plugin.flush === 'function';\n })\n .map(plugin => plugin.flush(timeout));\n\n if (flushPromises.length === 0) {\n return true;\n }\n\n const results = await Promise.allSettled(flushPromises);\n return results.every(result => result.status === 'fulfilled' && result.value === true);\n }\n\n /**\n * Helper to broadcast a method call to all enabled plugins\n * Uses nested try-catch to ensure errors in error handling don't prevent other plugins from executing\n */\n private broadcast(fn: (plugin: ObservabilityPlugin) => void): void {\n this.plugins.forEach(plugin => {\n if (plugin.enabled) {\n try {\n fn(plugin);\n } catch (error) {\n // Safely handle error without throwing - nested try-catch ensures resilience\n try {\n logError(`Plugin ${plugin.name} error`, { error, pluginName: plugin.name });\n } catch {\n // Logger unavailable - continue silently\n }\n\n try {\n this.lifecycle.onError?.(error as Error, plugin);\n } catch {\n // Error handler failed - continue to next plugin\n }\n }\n }\n });\n }\n\n /**\n * Check if manager has any enabled plugins.\n *\n * @returns True if at least one plugin is enabled, false otherwise\n */\n hasEnabledPlugins(): boolean {\n return Array.from(this.plugins.values()).some(plugin => plugin.enabled);\n }\n\n /**\n * Get names of all enabled plugins.\n *\n * @returns Array of plugin names that are currently enabled\n */\n getEnabledPluginNames(): string[] {\n return Array.from(this.plugins.values())\n .filter(plugin => plugin.enabled)\n .map(plugin => plugin.name);\n }\n}\n","/**\n * @fileoverview ObservabilityBuilder - Fluent API for building observability instances\n * ObservabilityBuilder - Fluent API for building observability instances\n */\n\nimport { logError } from '@repo/shared/logs';\n\nimport { ObservabilityManager } from '../core/manager';\n\nimport type {\n ObservabilityPlugin,\n ObservabilityServerPlugin,\n PluginLifecycle,\n} from '../core/plugin';\n\n/**\n * Builder for creating configured ObservabilityManager instances\n */\nexport class ObservabilityBuilder {\n private plugins: (ObservabilityPlugin | ObservabilityServerPlugin)[] = [];\n private lifecycle: PluginLifecycle = {};\n private autoInitialize = true;\n\n /**\n * Add a plugin to the observability stack\n * @param plugin - Observability plugin to add\n * @returns Builder instance for chaining\n */\n withPlugin(plugin: ObservabilityPlugin | ObservabilityServerPlugin): this {\n if (plugin) {\n this.plugins.push(plugin);\n }\n return this;\n }\n\n /**\n * Add multiple plugins at once\n * @param plugins - Array of observability plugins to add\n * @returns Builder instance for chaining\n */\n withPlugins(plugins: (ObservabilityPlugin | ObservabilityServerPlugin)[]): this {\n if (plugins && Array.isArray(plugins)) {\n const validPlugins = plugins.filter(plugin => plugin != null);\n this.plugins.push(...validPlugins);\n }\n return this;\n }\n\n /**\n * Set lifecycle callbacks for plugin management\n * @param lifecycle - Lifecycle callback configuration\n * @returns Builder instance for chaining\n */\n withLifecycle(lifecycle: PluginLifecycle): this {\n this.lifecycle = { ...this.lifecycle, ...lifecycle };\n return this;\n }\n\n /**\n * Configure whether to auto-initialize plugins (default: true)\n */\n withAutoInitialize(autoInitialize: boolean): this {\n this.autoInitialize = autoInitialize;\n return this;\n }\n\n /**\n * Build the ObservabilityManager instance\n * @returns Configured ObservabilityManager instance\n */\n build(): ObservabilityManager {\n const manager = new ObservabilityManager(this.lifecycle);\n\n // Add all plugins\n this.plugins.forEach(plugin => manager.addPlugin(plugin));\n\n // Auto-initialize if enabled and not in edge runtime\n if (\n this.autoInitialize &&\n typeof process !== 'undefined' &&\n process.env.NEXT_RUNTIME !== 'edge'\n ) {\n // Initialize asynchronously with safe error handling\n void (async () => {\n try {\n await manager.initialize();\n } catch (error) {\n // Store error in manager for later inspection\n // Note: We can't directly set private property, but manager stores it internally\n\n // Try logError, but don't fail if unavailable\n try {\n logError('Failed to initialize observability', { error });\n } catch {\n // Logger unavailable - error is stored in manager via initialize() method\n }\n }\n })();\n }\n\n return manager;\n }\n\n /**\n * Build and initialize the ObservabilityManager instance\n * @returns Promise resolving to initialized ObservabilityManager\n */\n async buildWithAutoInit(): Promise<ObservabilityManager> {\n const manager = new ObservabilityManager(this.lifecycle);\n\n // Add all plugins\n this.plugins.forEach(plugin => manager.addPlugin(plugin));\n\n // Initialize all plugins - catch errors but still return manager (graceful degradation)\n try {\n await manager.initialize();\n } catch {\n // Error is stored in manager, but we still return it for graceful degradation\n // This allows the application to continue even if observability initialization fails\n }\n\n return manager;\n }\n\n /**\n * Create a new builder instance\n * @returns New ObservabilityBuilder instance\n */\n static create(): ObservabilityBuilder {\n return new ObservabilityBuilder();\n }\n}\n","/**\n * @fileoverview Factory functions for creating observability instances\n * Factory functions for creating observability instances\n */\n\nimport { ObservabilityManager } from '../core/manager';\n\nimport { ObservabilityBuilder } from './builder';\n\nimport type { ObservabilityPlugin, ObservabilityServerPlugin } from '../core/plugin';\n\nexport { ObservabilityManager } from '../core/manager';\nexport { ObservabilityBuilder } from './builder';\n\n/**\n * Create an observability instance with the provided plugins.\n *\n * Factory function that creates a configured ObservabilityManager with the given plugins.\n * Provides a simpler API than using ObservabilityBuilder directly.\n *\n * @param plugins - Array of observability plugins to include\n * @param options - Optional configuration options\n * @param options.autoInitialize - Whether to auto-initialize plugins (default: true)\n * @returns Configured ObservabilityManager instance\n *\n * @example\n * ```typescript\n * const obs = createObservability([\n * createConsolePlugin(),\n * createSentryPlugin({ dsn: '...' }),\n * ], { autoInitialize: true });\n * ```\n */\nexport function createObservability(\n plugins: (ObservabilityPlugin | ObservabilityServerPlugin)[],\n options?: {\n autoInitialize?: boolean;\n },\n): ObservabilityManager {\n const builder = new ObservabilityBuilder();\n\n if (options?.autoInitialize !== undefined) {\n builder.withAutoInitialize(options.autoInitialize);\n }\n\n return builder.withPlugins(plugins).build();\n}\n\n/**\n * Create a no-op observability instance for testing or when observability is disabled.\n *\n * Returns an ObservabilityManager with no plugins configured. All observability methods\n * will be no-ops. Useful for testing or when observability should be disabled.\n *\n * Note: For logging, use @repo/shared/logger instead.\n *\n * @returns Empty ObservabilityManager instance\n *\n * @example\n * ```typescript\n * const obs = createNoOpObservability();\n * obs.captureMessage('This will not be logged'); // No-op\n * ```\n */\nexport function createNoOpObservability(): ObservabilityManager {\n return new ObservabilityManager();\n}\n"],"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AU,QAAQ,UAAU,OAAO,CAAC;AAGzD,MAAI;AACF,SAAM,QAAQ,YAAY;UACpB;AAKR,SAAO;;;;;;CAOT,OAAO,SAA+B;AACpC,SAAO,IAAI,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;AChGrC,SAAgB,oBACd,SACA,SAGsB;CACtB,MAAM,UAAU,IAAI,sBAAsB;AAE1C,KAAI,SAAS,mBAAmB,OAC9B,SAAQ,mBAAmB,QAAQ,eAAe;AAGpD,QAAO,QAAQ,YAAY,QAAQ,CAAC,OAAO"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { t as ObservabilityManager } from "./manager-BxQqOPEg.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/hooks/useObservability.d.ts
|
|
4
|
+
declare function setObservabilityPromise(promise: Promise<ObservabilityManager>): void;
|
|
5
|
+
declare function useObservability(): ObservabilityManager;
|
|
6
|
+
declare function useObservabilityLegacy(): ObservabilityManager | undefined;
|
|
7
|
+
declare function useObservabilityLifecycle(componentName: string, deps?: readonly unknown[]): void;
|
|
8
|
+
declare function useObservabilityError(error: Error | null | undefined, errorInfo?: Record<string, unknown>): void;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { setObservabilityPromise, useObservability, useObservabilityError, useObservabilityLegacy, useObservabilityLifecycle };
|
|
11
|
+
//# sourceMappingURL=hooks-useObservability.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks-useObservability.d.mts","names":[],"sources":["../src/hooks/useObservability.ts"],"mappings":";;;iBAwBgB,uBAAA,CAAwB,OAAA,EAAS,OAAA,CAAQ,oBAAA;AAAA,iBAmCzC,gBAAA,CAAA,GAAoB,oBAAA;AAAA,iBAuBpB,sBAAA,CAAA,GAA0B,oBAAA;AAAA,iBAoD1B,yBAAA,CACd,aAAA,UACA,IAAA;AAAA,iBA6Cc,qBAAA,CACd,KAAA,EAAO,KAAA,qBACP,SAAA,GAAY,MAAA"}
|