@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
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { shouldEnableConsole } from "./index.mjs";
|
|
2
|
+
import { env } from "./env.mjs";
|
|
3
|
+
import { n as ObservabilityBuilder, r as ObservabilityManager, t as createObservability } from "./factory-DkY353r8.mjs";
|
|
4
|
+
import { ConsolePlugin, createConsoleServerPlugin } from "./plugins-console.mjs";
|
|
5
|
+
import { env as env$1 } from "./plugins-betterstack-env.mjs";
|
|
6
|
+
import { n as createBetterStackPlugin, t as BetterStackPlugin } from "./plugin-lPdJirTY.mjs";
|
|
7
|
+
import { env as env$2 } from "./plugins-sentry-env.mjs";
|
|
8
|
+
import { n as createSentryPlugin, t as SentryPlugin } from "./plugin-CP895lBx.mjs";
|
|
9
|
+
import { t as SentryMicroFrontendPlugin } from "./plugin-CLFwRERa.mjs";
|
|
10
|
+
|
|
11
|
+
//#region src/server-next.ts
|
|
12
|
+
/**
|
|
13
|
+
* @fileoverview Next.js server-specific observability export
|
|
14
|
+
* Next.js server-specific observability export
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Create auto-configured observability for Next.js server
|
|
18
|
+
*/
|
|
19
|
+
async function createServerObservability() {
|
|
20
|
+
const builder = ObservabilityBuilder.create();
|
|
21
|
+
const enableConsole = shouldEnableConsole(env.NEXT_PUBLIC_NODE_ENV, env.NEXT_PUBLIC_OBSERVABILITY_CONSOLE_ENABLED, env.NEXT_PUBLIC_OBSERVABILITY_DEBUG);
|
|
22
|
+
builder.withPlugin(createConsoleServerPlugin({
|
|
23
|
+
prefix: "[Next.js Server]",
|
|
24
|
+
enabled: enableConsole
|
|
25
|
+
}));
|
|
26
|
+
const sentryDSN = env$2.NEXT_PUBLIC_SENTRY_DSN;
|
|
27
|
+
if (sentryDSN) {
|
|
28
|
+
const sentry = createSentryPlugin({ dsn: sentryDSN });
|
|
29
|
+
await sentry.initialize();
|
|
30
|
+
builder.withPlugin(sentry);
|
|
31
|
+
}
|
|
32
|
+
const betterStackToken = env$1.BETTER_STACK_SOURCE_TOKEN ?? env$1.BETTERSTACK_SOURCE_TOKEN ?? env$1.LOGTAIL_SOURCE_TOKEN;
|
|
33
|
+
if (betterStackToken) {
|
|
34
|
+
const betterstack = createBetterStackPlugin({ sourceToken: betterStackToken });
|
|
35
|
+
await betterstack.initialize();
|
|
36
|
+
builder.withPlugin(betterstack);
|
|
37
|
+
}
|
|
38
|
+
return builder.build();
|
|
39
|
+
}
|
|
40
|
+
let initializationPromise = null;
|
|
41
|
+
/**
|
|
42
|
+
* Get or create the observability instance
|
|
43
|
+
* Uses promise-based singleton pattern to prevent race conditions in concurrent scenarios
|
|
44
|
+
* @returns Promise resolving to the ObservabilityManager instance
|
|
45
|
+
*/
|
|
46
|
+
async function getObservability() {
|
|
47
|
+
if (!initializationPromise) initializationPromise = (async () => {
|
|
48
|
+
try {
|
|
49
|
+
return await createServerObservability();
|
|
50
|
+
} catch (error) {
|
|
51
|
+
initializationPromise = null;
|
|
52
|
+
throw error;
|
|
53
|
+
}
|
|
54
|
+
})();
|
|
55
|
+
return initializationPromise;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* @deprecated Configuration now happens through the observability system
|
|
59
|
+
*/
|
|
60
|
+
const configureLogger = () => {};
|
|
61
|
+
|
|
62
|
+
//#endregion
|
|
63
|
+
export { BetterStackPlugin, ConsolePlugin, ObservabilityBuilder, ObservabilityManager, SentryMicroFrontendPlugin, SentryPlugin, configureLogger, createObservability, createServerObservability, getObservability };
|
|
64
|
+
//# sourceMappingURL=server-next.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-next.mjs","names":["sentryEnv","betterStackEnv"],"sources":["../src/server-next.ts"],"sourcesContent":["/**\n * @fileoverview Next.js server-specific observability export\n * Next.js server-specific observability export\n */\n\nimport { env } from '../env';\n\nimport { ObservabilityBuilder } from './factory/builder';\nimport { createBetterStackPlugin } from './plugins/betterstack';\nimport { env as betterStackEnv } from './plugins/betterstack/env';\nimport { createConsoleServerPlugin } from './plugins/console';\nimport { createSentryPlugin } from './plugins/sentry';\nimport { env as sentryEnv } from './plugins/sentry/env';\nimport { shouldEnableConsole } from './shared';\n\nimport type { ObservabilityManager } from './core/manager';\n\n/**\n * Create auto-configured observability for Next.js server\n */\nexport async function createServerObservability() {\n const builder = ObservabilityBuilder.create();\n\n // Console logging control using shared utility\n const enableConsole = shouldEnableConsole(\n env.NEXT_PUBLIC_NODE_ENV,\n env.NEXT_PUBLIC_OBSERVABILITY_CONSOLE_ENABLED,\n env.NEXT_PUBLIC_OBSERVABILITY_DEBUG,\n );\n\n // Always add console plugin, control via enabled flag\n builder.withPlugin(\n createConsoleServerPlugin({\n prefix: '[Next.js Server]',\n enabled: enableConsole,\n }),\n );\n\n // Auto-activate Sentry if DSN is provided\n // Only use client-accessible DSN for auto-detection to avoid server/client boundary issues\n const sentryDSN = sentryEnv.NEXT_PUBLIC_SENTRY_DSN;\n if (sentryDSN) {\n const sentry = createSentryPlugin({\n dsn: sentryDSN,\n });\n await sentry.initialize();\n builder.withPlugin(sentry);\n }\n\n // Auto-activate Better Stack if source token is provided\n const betterStackToken =\n betterStackEnv.BETTER_STACK_SOURCE_TOKEN ??\n betterStackEnv.BETTERSTACK_SOURCE_TOKEN ??\n betterStackEnv.LOGTAIL_SOURCE_TOKEN;\n\n if (betterStackToken) {\n const betterstack = createBetterStackPlugin({\n sourceToken: betterStackToken,\n });\n await betterstack.initialize();\n builder.withPlugin(betterstack);\n }\n\n return builder.build();\n}\n\n// Lazy initialization for the observability instance using promise-based singleton\nlet initializationPromise: Promise<ObservabilityManager> | null = null;\n\n/**\n * Get or create the observability instance\n * Uses promise-based singleton pattern to prevent race conditions in concurrent scenarios\n * @returns Promise resolving to the ObservabilityManager instance\n */\nexport async function getObservability(): Promise<ObservabilityManager> {\n if (!initializationPromise) {\n initializationPromise = (async () => {\n try {\n return await createServerObservability();\n } catch (error) {\n // Reset cached promise on failure so callers can retry\n initializationPromise = null;\n throw error;\n }\n })();\n }\n return initializationPromise;\n}\n\n// Export types and utilities\nexport * from './core/types';\nexport { createObservability } from './factory';\nexport { ObservabilityBuilder } from './factory/builder';\nexport { ObservabilityManager } from \"./factory\";\n\n// Re-export plugins for direct access (excluding conflicting exports)\nexport { BetterStackPlugin } from './plugins/betterstack';\nexport { ConsolePlugin } from './plugins/console';\nexport { SentryPlugin } from './plugins/sentry';\nexport { SentryMicroFrontendPlugin } from './plugins/sentry-microfrontend';\n\n// Re-export plugin-specific types with aliases to avoid conflicts\n// Removed for Rollup compatibility\n// Removed for Rollup compatibility\n\n// Legacy function for backward compatibility (no-op)\n/**\n * @deprecated Configuration now happens through the observability system\n */\nexport const configureLogger = (): void => {\n // No-op: Configuration now happens through the observability system\n};\n\n// Re-export type - removed for Rollup compatibility\n"],"mappings":";;;;;;;;;;;;;;;;;;AAoBA,eAAsB,4BAA4B;CAChD,MAAM,UAAU,qBAAqB,QAAQ;CAG7C,MAAM,gBAAgB,oBACpB,IAAI,sBACJ,IAAI,2CACJ,IAAI,gCACL;AAGD,SAAQ,WACN,0BAA0B;EACxB,QAAQ;EACR,SAAS;EACV,CAAC,CACH;CAID,MAAM,YAAYA,MAAU;AAC5B,KAAI,WAAW;EACb,MAAM,SAAS,mBAAmB,EAChC,KAAK,WACN,CAAC;AACF,QAAM,OAAO,YAAY;AACzB,UAAQ,WAAW,OAAO;;CAI5B,MAAM,mBACJC,MAAe,6BACfA,MAAe,4BACfA,MAAe;AAEjB,KAAI,kBAAkB;EACpB,MAAM,cAAc,wBAAwB,EAC1C,aAAa,kBACd,CAAC;AACF,QAAM,YAAY,YAAY;AAC9B,UAAQ,WAAW,YAAY;;AAGjC,QAAO,QAAQ,OAAO;;AAIxB,IAAI,wBAA8D;;;;;;AAOlE,eAAsB,mBAAkD;AACtE,KAAI,CAAC,sBACH,0BAAyB,YAAY;AACnC,MAAI;AACF,UAAO,MAAM,2BAA2B;WACjC,OAAO;AAEd,2BAAwB;AACxB,SAAM;;KAEN;AAEN,QAAO;;;;;AAuBT,MAAa,wBAA8B"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { a as Breadcrumb, c as ObservabilityConfig, d as ObservabilityServer, f as ObservabilityUser, l as ObservabilityContext, o as LogLevel, s as ObservabilityClient, u as ObservabilityScope } from "./plugin-Bfq-o3nr.mjs";
|
|
2
|
+
import { t as ObservabilityManager } from "./manager-BxQqOPEg.mjs";
|
|
3
|
+
import { n as ObservabilityBuilder, t as createObservability } from "./index-CpcdzWrF.mjs";
|
|
4
|
+
|
|
5
|
+
//#region src/server.d.ts
|
|
6
|
+
declare const observability: ObservabilityManager;
|
|
7
|
+
declare const configureLogger: () => void;
|
|
8
|
+
type LogContext = Record<string, any>;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { Breadcrumb, LogContext, LogLevel, ObservabilityBuilder, ObservabilityClient, ObservabilityConfig, ObservabilityContext, ObservabilityScope, ObservabilityServer, ObservabilityUser, configureLogger, createObservability, observability };
|
|
11
|
+
//# sourceMappingURL=server.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.mts","names":[],"sources":["../src/server.ts"],"mappings":";;;;;cAwCa,aAAA,EAA+B,oBAAA;AAAA,cAyB/B,eAAA;AAAA,KAKD,UAAA,GAAa,MAAA"}
|
package/dist/server.mjs
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { shouldEnableConsole } from "./index.mjs";
|
|
2
|
+
import { safeEnv } from "./env.mjs";
|
|
3
|
+
import { n as ObservabilityBuilder, t as createObservability } from "./factory-DkY353r8.mjs";
|
|
4
|
+
import { createConsoleServerPlugin } from "./plugins-console.mjs";
|
|
5
|
+
|
|
6
|
+
//#region src/server.ts
|
|
7
|
+
/**
|
|
8
|
+
* @fileoverview Auto-configuring server export for Node.js environments (non-Next.js)
|
|
9
|
+
* Auto-configuring server export for Node.js environments (non-Next.js)
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Auto-configured observability for Node.js server environments
|
|
13
|
+
* Automatically sets up console logging based on environment variables
|
|
14
|
+
*/
|
|
15
|
+
const builder = ObservabilityBuilder.create();
|
|
16
|
+
const env = safeEnv();
|
|
17
|
+
const enableConsole = shouldEnableConsole(env.NEXT_PUBLIC_NODE_ENV, env.NEXT_PUBLIC_OBSERVABILITY_CONSOLE_ENABLED, env.NEXT_PUBLIC_OBSERVABILITY_DEBUG);
|
|
18
|
+
builder.withPlugin(createConsoleServerPlugin({
|
|
19
|
+
prefix: "[Server]",
|
|
20
|
+
enabled: enableConsole
|
|
21
|
+
}));
|
|
22
|
+
/**
|
|
23
|
+
* Pre-configured observability instance for Node.js server environments
|
|
24
|
+
* Includes console logging with automatic environment-based configuration
|
|
25
|
+
*/
|
|
26
|
+
const observability = builder.build();
|
|
27
|
+
/**
|
|
28
|
+
* Synchronous logger functions for non-Next.js Node.js environments.
|
|
29
|
+
* These are bound to a pre-built observability instance at module load time.
|
|
30
|
+
*
|
|
31
|
+
* Note: For Next.js apps, use `@od-oneapp/observability/server/next` instead,
|
|
32
|
+
* which provides async loggers that support lazy initialization.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* import { logInfo, logError } from '@od-oneapp/shared/logger';
|
|
37
|
+
* logInfo('Server started', { port: 3000 });
|
|
38
|
+
* logError('Database connection failed', { error: err });
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
/**
|
|
42
|
+
* @deprecated Configuration now happens through the observability system
|
|
43
|
+
*/
|
|
44
|
+
const configureLogger = () => {};
|
|
45
|
+
|
|
46
|
+
//#endregion
|
|
47
|
+
export { ObservabilityBuilder, configureLogger, createObservability, observability };
|
|
48
|
+
//# sourceMappingURL=server.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.mjs","names":[],"sources":["../src/server.ts"],"sourcesContent":["/**\n * @fileoverview Auto-configuring server export for Node.js environments (non-Next.js)\n * Auto-configuring server export for Node.js environments (non-Next.js)\n */\n\nimport { safeEnv } from '../env';\n\nimport { ObservabilityBuilder } from './factory/builder';\nimport { createConsoleServerPlugin } from './plugins/console';\nimport { shouldEnableConsole } from './shared';\n\n/**\n * Auto-configured observability for Node.js server environments\n * Automatically sets up console logging based on environment variables\n */\nconst builder = ObservabilityBuilder.create();\n\n// Console logging control using shared utility\nconst env = safeEnv();\nconst enableConsole = shouldEnableConsole(\n env.NEXT_PUBLIC_NODE_ENV,\n env.NEXT_PUBLIC_OBSERVABILITY_CONSOLE_ENABLED,\n env.NEXT_PUBLIC_OBSERVABILITY_DEBUG,\n);\n\n// Always add console plugin, control via enabled flag\nbuilder.withPlugin(\n createConsoleServerPlugin({\n prefix: '[Server]',\n enabled: enableConsole,\n }),\n);\n\n// Note: Production providers would typically be configured by the app\n// This is just a fallback for non-Next.js server usage\n\n/**\n * Pre-configured observability instance for Node.js server environments\n * Includes console logging with automatic environment-based configuration\n */\nexport const observability = builder.build();\n\n// Export types and utilities\nexport * from './core/types';\nexport { createObservability } from './factory';\nexport { ObservabilityBuilder } from './factory/builder';\n\n/**\n * Synchronous logger functions for non-Next.js Node.js environments.\n * These are bound to a pre-built observability instance at module load time.\n *\n * Note: For Next.js apps, use `@repo/observability/server/next` instead,\n * which provides async loggers that support lazy initialization.\n *\n * @example\n * ```typescript\n * import { logInfo, logError } from '@repo/shared/logger';\n * logInfo('Server started', { port: 3000 });\n * logError('Database connection failed', { error: err });\n * ```\n */\n// Legacy function for backward compatibility (no-op)\n/**\n * @deprecated Configuration now happens through the observability system\n */\nexport const configureLogger = () => {\n // No-op: Configuration now happens through the observability system\n};\n\n// Re-export type\nexport type LogContext = Record<string, any>;\n"],"mappings":";;;;;;;;;;;;;;AAeA,MAAM,UAAU,qBAAqB,QAAQ;AAG7C,MAAM,MAAM,SAAS;AACrB,MAAM,gBAAgB,oBACpB,IAAI,sBACJ,IAAI,2CACJ,IAAI,gCACL;AAGD,QAAQ,WACN,0BAA0B;CACxB,QAAQ;CACR,SAAS;CACV,CAAC,CACH;;;;;AASD,MAAa,gBAAgB,QAAQ,OAAO;;;;;;;;;;;;;;;;;;AAyB5C,MAAa,wBAAwB"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { l as ObservabilityContext, o as LogLevel } from "./plugin-Bfq-o3nr.mjs";
|
|
2
|
+
import { n as SentryPluginConfig } from "./plugin-Bt-ygG1m.mjs";
|
|
3
|
+
import { SentryPlugin } from "@integrations/sentry/observability-plugin/plugin";
|
|
4
|
+
|
|
5
|
+
//#region src/plugins/sentry-microfrontend/types.d.ts
|
|
6
|
+
interface BackstageAppConfig {
|
|
7
|
+
name: string;
|
|
8
|
+
dsn?: string;
|
|
9
|
+
release?: string;
|
|
10
|
+
tags?: Record<string, string>;
|
|
11
|
+
pathPatterns?: (string | RegExp)[];
|
|
12
|
+
}
|
|
13
|
+
type MicroFrontendMode = 'host' | 'child' | 'standalone';
|
|
14
|
+
interface SentryMicroFrontendConfig extends Omit<SentryPluginConfig, 'transport'> {
|
|
15
|
+
isHost?: boolean;
|
|
16
|
+
backstageApp?: string;
|
|
17
|
+
backstageApps?: BackstageAppConfig[];
|
|
18
|
+
detectParent?: boolean;
|
|
19
|
+
backstageAppDetector?: () => string | undefined;
|
|
20
|
+
addBackstageContext?: boolean;
|
|
21
|
+
fallbackDsn?: string;
|
|
22
|
+
useMultiplexedTransport?: boolean;
|
|
23
|
+
globalTags?: Record<string, string>;
|
|
24
|
+
preventDuplicateInit?: boolean;
|
|
25
|
+
integrationConfig?: {
|
|
26
|
+
nodeProfilingIntegration?: boolean;
|
|
27
|
+
captureConsoleIntegration?: boolean;
|
|
28
|
+
vercelAIIntegration?: boolean;
|
|
29
|
+
};
|
|
30
|
+
_experiments?: {
|
|
31
|
+
enableLogs?: boolean;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
declare global {
|
|
35
|
+
interface Window {
|
|
36
|
+
Sentry?: any;
|
|
37
|
+
__SENTRY_MICRO_FRONTEND_HOST__?: boolean;
|
|
38
|
+
__SENTRY_MICRO_FRONTEND_APP__?: string;
|
|
39
|
+
}
|
|
40
|
+
} //# sourceMappingURL=types.d.ts.map
|
|
41
|
+
//#endregion
|
|
42
|
+
//#region src/plugins/sentry-microfrontend/multiplexed-transport.d.ts
|
|
43
|
+
declare function createMultiplexedTransport(backstage: BackstageAppConfig[], fallbackDsn?: string, sentryClient?: any): any;
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region src/plugins/sentry-microfrontend/plugin.d.ts
|
|
46
|
+
declare class SentryMicroFrontendPlugin extends SentryPlugin {
|
|
47
|
+
private mode;
|
|
48
|
+
private backstageApp;
|
|
49
|
+
private parentSentry;
|
|
50
|
+
private backstageScope;
|
|
51
|
+
private microFrontendConfig;
|
|
52
|
+
private eventProcessorCleanup?;
|
|
53
|
+
constructor(config?: SentryMicroFrontendConfig);
|
|
54
|
+
private static determineMode;
|
|
55
|
+
private static prepareConfig;
|
|
56
|
+
initialize(config?: SentryMicroFrontendConfig): Promise<void>;
|
|
57
|
+
private configureParentSentry;
|
|
58
|
+
private setupHostMode;
|
|
59
|
+
private shouldProcessEvent;
|
|
60
|
+
captureException(error: Error | unknown, context?: ObservabilityContext): void;
|
|
61
|
+
captureMessage(message: string, level?: LogLevel, context?: ObservabilityContext): void;
|
|
62
|
+
getMode(): MicroFrontendMode;
|
|
63
|
+
getBackstageApp(): string | undefined;
|
|
64
|
+
getZone(): string | undefined;
|
|
65
|
+
getDebugInfo(): Record<string, any>;
|
|
66
|
+
cleanup(): Promise<void>;
|
|
67
|
+
destroy(): Promise<void>;
|
|
68
|
+
}
|
|
69
|
+
declare const createSentryMicroFrontendPlugin: (config?: SentryMicroFrontendConfig) => SentryMicroFrontendPlugin;
|
|
70
|
+
//#endregion
|
|
71
|
+
//#region src/plugins/sentry-microfrontend/utils.d.ts
|
|
72
|
+
declare function detectCurrentBackstageApp(customPatterns?: BackstageAppConfig[]): string | undefined;
|
|
73
|
+
declare function isHostEnvironment(): boolean;
|
|
74
|
+
declare function createBackstageScope(backstageApp: string, additionalTags?: Record<string, string>): unknown;
|
|
75
|
+
//#endregion
|
|
76
|
+
export { createSentryMicroFrontendPlugin as a, MicroFrontendMode as c, SentryMicroFrontendPlugin as i, SentryMicroFrontendConfig as l, detectCurrentBackstageApp as n, createMultiplexedTransport as o, isHostEnvironment as r, BackstageAppConfig as s, createBackstageScope as t };
|
|
77
|
+
//# sourceMappingURL=utils-CuGrTcD6.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils-CuGrTcD6.d.mts","names":[],"sources":["../src/plugins/sentry-microfrontend/types.ts","../src/plugins/sentry-microfrontend/multiplexed-transport.ts","../src/plugins/sentry-microfrontend/plugin.ts","../src/plugins/sentry-microfrontend/utils.ts"],"mappings":";;;;;UAUiB,kBAAA;EAIf,IAAA;EAKA,GAAA;EAKA,OAAA;EAKA,IAAA,GAAO,MAAA;EAKP,YAAA,aAAyB,MAAA;AAAA;AAAA,KAMf,iBAAA;AAAA,UAKK,yBAAA,SAAkC,IAAA,CAAK,kBAAA;EAItD,MAAA;EAKA,YAAA;EAKA,aAAA,GAAgB,kBAAA;EAMhB,YAAA;EAKA,oBAAA;EAMA,mBAAA;EAKA,WAAA;EAMA,uBAAA;EAKA,UAAA,GAAa,MAAA;EAMb,oBAAA;EAKA,iBAAA;IACE,wBAAA;IACA,yBAAA;IACA,mBAAA;EAAA;EAOF,YAAA;IACE,UAAA;EAAA;AAAA;AAAA,QAOI,MAAA;EAAA,UACI,MAAA;IACR,MAAA;IAEA,8BAAA;IAEA,6BAAA;EAAA;AAAA;;;iBC1GY,0BAAA,CACd,SAAA,EAAW,kBAAA,IACX,WAAA,WAEA,YAAA;;;cCgBW,yBAAA,SAAkC,YAAA;EAAA,QACrC,IAAA;EAAA,QACA,YAAA;EAAA,QACA,YAAA;EAAA,QACA,cAAA;EAAA,QACA,mBAAA;EAAA,QACA,qBAAA;cAOI,MAAA,GAAQ,yBAAA;EAAA,eA2CL,aAAA;EAAA,eAwBA,aAAA;EAwBT,UAAA,CAAW,MAAA,GAAS,yBAAA,GAA4B,OAAA;EAAA,QAwC9C,qBAAA;EAAA,QA6CA,aAAA;EAAA,QA0CA,kBAAA;EAqBR,gBAAA,CAAiB,KAAA,EAAO,KAAA,YAAiB,OAAA,GAAU,oBAAA;EAuDnD,cAAA,CAAe,OAAA,UAAiB,KAAA,GAAO,QAAA,EAAmB,OAAA,GAAU,oBAAA;EAoDpE,OAAA,CAAA,GAAW,iBAAA;EAOX,eAAA,CAAA;EAOA,OAAA,CAAA;EAQA,YAAA,CAAA,GAAgB,MAAA;EAcV,OAAA,CAAA,GAAW,OAAA;EAkCX,OAAA,CAAA,GAAW,OAAA;AAAA;AAAA,cAyBN,+BAAA,GACX,MAAA,GAAS,yBAAA,KACR,yBAAA;;;iBCtda,yBAAA,CACd,cAAA,GAAiB,kBAAA;AAAA,iBA+DH,iBAAA,CAAA;AAAA,iBAkCA,oBAAA,CACd,YAAA,UACA,cAAA,GAAiB,MAAA"}
|
package/env.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Core environment configuration for the observability package
|
|
3
|
+
* Core environment configuration for the observability package
|
|
4
|
+
* Provider-specific configurations are handled by their respective plugins
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { logWarn } from '@repo/shared/logger';
|
|
8
|
+
import { createEnv } from '@t3-oss/env-core';
|
|
9
|
+
import { z } from 'zod/v4';
|
|
10
|
+
|
|
11
|
+
// Create validated env object
|
|
12
|
+
export const env = createEnv({
|
|
13
|
+
server: {
|
|
14
|
+
// Core observability config only - providers handle their own
|
|
15
|
+
},
|
|
16
|
+
clientPrefix: 'NEXT_PUBLIC_',
|
|
17
|
+
client: {
|
|
18
|
+
// Core configuration available on both client and server
|
|
19
|
+
NEXT_PUBLIC_NODE_ENV: z.enum(['development', 'test', 'production']).default('development'),
|
|
20
|
+
NEXT_PUBLIC_OBSERVABILITY_DEBUG: z
|
|
21
|
+
.string()
|
|
22
|
+
.optional()
|
|
23
|
+
.transform(val => val === 'true')
|
|
24
|
+
.default(false),
|
|
25
|
+
NEXT_PUBLIC_OBSERVABILITY_CONSOLE_ENABLED: z
|
|
26
|
+
.string()
|
|
27
|
+
.optional()
|
|
28
|
+
.transform(val => (val === 'true' ? true : val === 'false' ? false : undefined)),
|
|
29
|
+
},
|
|
30
|
+
runtimeEnv: process.env,
|
|
31
|
+
emptyStringAsUndefined: true,
|
|
32
|
+
onInvalidAccess: (variable: string) => {
|
|
33
|
+
throw new Error(
|
|
34
|
+
`❌ Attempted to access a server-side environment variable on the client: ${variable}`,
|
|
35
|
+
);
|
|
36
|
+
},
|
|
37
|
+
onValidationError: error => {
|
|
38
|
+
logWarn('Observability package environment validation failed', { error });
|
|
39
|
+
// Don't throw in packages - use fallbacks
|
|
40
|
+
return undefined as never;
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// Helper for non-Next.js contexts (Node.js, workers, tests)
|
|
45
|
+
export function safeEnv() {
|
|
46
|
+
try {
|
|
47
|
+
if (env && typeof env === 'object') return env;
|
|
48
|
+
} catch {
|
|
49
|
+
// Environment validation failed, use fallbacks
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Fallback values for resilience
|
|
53
|
+
return {
|
|
54
|
+
// Core configuration only
|
|
55
|
+
NEXT_PUBLIC_NODE_ENV: process.env.NODE_ENV ?? 'development',
|
|
56
|
+
NEXT_PUBLIC_OBSERVABILITY_DEBUG: process.env.NEXT_PUBLIC_OBSERVABILITY_DEBUG === 'true',
|
|
57
|
+
NEXT_PUBLIC_OBSERVABILITY_CONSOLE_ENABLED:
|
|
58
|
+
process.env.NEXT_PUBLIC_OBSERVABILITY_CONSOLE_ENABLED === 'true'
|
|
59
|
+
? true
|
|
60
|
+
: process.env.NEXT_PUBLIC_OBSERVABILITY_CONSOLE_ENABLED === 'false'
|
|
61
|
+
? false
|
|
62
|
+
: undefined,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Export type
|
|
67
|
+
export type Env = typeof env;
|
package/package.json
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@od-oneapp/observability",
|
|
3
|
+
"version": "2026.1.1301",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "Clean observability package with provider subpackages",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/OneDigital-Product/monorepo.git",
|
|
9
|
+
"directory": "platform/packages/observability"
|
|
10
|
+
},
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"sideEffects": false,
|
|
13
|
+
"type": "module",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.mts",
|
|
17
|
+
"import": "./dist/index.mjs",
|
|
18
|
+
"default": "./dist/index.mjs"
|
|
19
|
+
},
|
|
20
|
+
"./client": {
|
|
21
|
+
"types": "./dist/client.d.mts",
|
|
22
|
+
"import": "./dist/client.mjs",
|
|
23
|
+
"default": "./dist/client.mjs"
|
|
24
|
+
},
|
|
25
|
+
"./server": {
|
|
26
|
+
"types": "./dist/server.d.mts",
|
|
27
|
+
"import": "./dist/server.mjs",
|
|
28
|
+
"default": "./dist/server.mjs"
|
|
29
|
+
},
|
|
30
|
+
"./client/next": {
|
|
31
|
+
"types": "./dist/client-next.d.mts",
|
|
32
|
+
"import": "./dist/client-next.mjs",
|
|
33
|
+
"default": "./dist/client-next.mjs"
|
|
34
|
+
},
|
|
35
|
+
"./server/next": {
|
|
36
|
+
"types": "./dist/server-next.d.mts",
|
|
37
|
+
"import": "./dist/server-next.mjs",
|
|
38
|
+
"default": "./dist/server-next.mjs"
|
|
39
|
+
},
|
|
40
|
+
"./server/edge": {
|
|
41
|
+
"types": "./dist/server-edge.d.mts",
|
|
42
|
+
"import": "./dist/server-edge.mjs",
|
|
43
|
+
"default": "./dist/server-edge.mjs"
|
|
44
|
+
},
|
|
45
|
+
"./env": {
|
|
46
|
+
"types": "./dist/env.d.mts",
|
|
47
|
+
"import": "./dist/env.mjs",
|
|
48
|
+
"default": "./dist/env.mjs"
|
|
49
|
+
},
|
|
50
|
+
"./plugins/console": {
|
|
51
|
+
"types": "./dist/plugins-console.d.mts",
|
|
52
|
+
"import": "./dist/plugins-console.mjs",
|
|
53
|
+
"default": "./dist/plugins-console.mjs"
|
|
54
|
+
},
|
|
55
|
+
"./plugins/sentry": {
|
|
56
|
+
"types": "./dist/plugins-sentry.d.mts",
|
|
57
|
+
"import": "./dist/plugins-sentry.mjs",
|
|
58
|
+
"default": "./dist/plugins-sentry.mjs"
|
|
59
|
+
},
|
|
60
|
+
"./plugins/sentry/env": {
|
|
61
|
+
"types": "./dist/plugins-sentry-env.d.mts",
|
|
62
|
+
"import": "./dist/plugins-sentry-env.mjs",
|
|
63
|
+
"default": "./dist/plugins-sentry-env.mjs"
|
|
64
|
+
},
|
|
65
|
+
"./plugins/betterstack": {
|
|
66
|
+
"types": "./dist/plugins-betterstack.d.mts",
|
|
67
|
+
"import": "./dist/plugins-betterstack.mjs",
|
|
68
|
+
"default": "./dist/plugins-betterstack.mjs"
|
|
69
|
+
},
|
|
70
|
+
"./plugins/betterstack/env": {
|
|
71
|
+
"types": "./dist/plugins-betterstack-env.d.mts",
|
|
72
|
+
"import": "./dist/plugins-betterstack-env.mjs",
|
|
73
|
+
"default": "./dist/plugins-betterstack-env.mjs"
|
|
74
|
+
},
|
|
75
|
+
"./plugins/sentry-microfrontend": {
|
|
76
|
+
"types": "./dist/plugins-sentry-microfrontend.d.mts",
|
|
77
|
+
"import": "./dist/plugins-sentry-microfrontend.mjs",
|
|
78
|
+
"default": "./dist/plugins-sentry-microfrontend.mjs"
|
|
79
|
+
},
|
|
80
|
+
"./plugins/sentry-microfrontend/env": {
|
|
81
|
+
"types": "./dist/plugins-sentry-microfrontend-env.d.mts",
|
|
82
|
+
"import": "./dist/plugins-sentry-microfrontend-env.mjs",
|
|
83
|
+
"default": "./dist/plugins-sentry-microfrontend-env.mjs"
|
|
84
|
+
},
|
|
85
|
+
"./hooks/useObservability": {
|
|
86
|
+
"types": "./dist/hooks-useObservability.d.mts",
|
|
87
|
+
"import": "./dist/hooks-useObservability.mjs",
|
|
88
|
+
"default": "./dist/hooks-useObservability.mjs"
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
"files": [
|
|
92
|
+
"src",
|
|
93
|
+
"env.ts",
|
|
94
|
+
"dist"
|
|
95
|
+
],
|
|
96
|
+
"dependencies": {
|
|
97
|
+
"@sentry/nextjs": "^10.38.0",
|
|
98
|
+
"@t3-oss/env-core": "^0.13.10",
|
|
99
|
+
"zod": "4.3.6",
|
|
100
|
+
"@integrations/sentry": "2026.1.1301",
|
|
101
|
+
"@repo/shared": "2026.1.1301",
|
|
102
|
+
"@integrations/betterstack": "2026.1.1301"
|
|
103
|
+
},
|
|
104
|
+
"devDependencies": {
|
|
105
|
+
"@testing-library/react": "^16.3.2",
|
|
106
|
+
"@types/node": "25.2.3",
|
|
107
|
+
"@types/react": "19.2.13",
|
|
108
|
+
"@vitest/coverage-v8": "4.0.18",
|
|
109
|
+
"eslint": "9.39.2",
|
|
110
|
+
"madge": "8.0.0",
|
|
111
|
+
"react": "^19.2.4",
|
|
112
|
+
"tsdown": "^0.20.3",
|
|
113
|
+
"typescript": "5.9.3",
|
|
114
|
+
"vite-tsconfig-paths": "6.1.0",
|
|
115
|
+
"vitest": "4.0.18",
|
|
116
|
+
"@od-oneapp/qa": "2026.1.1301",
|
|
117
|
+
"@repo/config": "2026.1.1301"
|
|
118
|
+
},
|
|
119
|
+
"peerDependencies": {
|
|
120
|
+
"next": "16.1.6",
|
|
121
|
+
"react": "^19.2.4"
|
|
122
|
+
},
|
|
123
|
+
"peerDependenciesMeta": {
|
|
124
|
+
"next": {
|
|
125
|
+
"optional": true
|
|
126
|
+
},
|
|
127
|
+
"react": {
|
|
128
|
+
"optional": true
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
"publishConfig": {
|
|
132
|
+
"access": "restricted",
|
|
133
|
+
"registry": "https://registry.npmjs.org/"
|
|
134
|
+
},
|
|
135
|
+
"scripts": {
|
|
136
|
+
"build": "tsdown",
|
|
137
|
+
"build:publish": "tsdown && node ../../../scripts/prepare-publish.mjs",
|
|
138
|
+
"circular": "madge --circular --extensions ts,tsx,js,jsx .",
|
|
139
|
+
"clean": "rm -rf .turbo node_modules",
|
|
140
|
+
"format": "prettier --write --cache --ignore-unknown --ignore-path ../../../.prettierignore .",
|
|
141
|
+
"format:check": "prettier --check --cache --ignore-unknown --ignore-path ../../../.prettierignore .",
|
|
142
|
+
"lint": "eslint . --fix",
|
|
143
|
+
"test": "vitest run",
|
|
144
|
+
"test:coverage": "vitest run --coverage",
|
|
145
|
+
"typecheck": "tsc --noEmit"
|
|
146
|
+
}
|
|
147
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Next.js client-specific observability export
|
|
3
|
+
* Next.js client-specific observability export
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { env } from '../env';
|
|
7
|
+
|
|
8
|
+
import { ObservabilityBuilder } from './factory/builder';
|
|
9
|
+
import { createBetterStackPlugin } from './plugins/betterstack';
|
|
10
|
+
import { env as betterStackEnv } from './plugins/betterstack/env';
|
|
11
|
+
import { createConsolePlugin } from './plugins/console';
|
|
12
|
+
import { createSentryPlugin } from './plugins/sentry';
|
|
13
|
+
import { env as sentryEnv } from './plugins/sentry/env';
|
|
14
|
+
import { shouldEnableConsole } from './shared';
|
|
15
|
+
|
|
16
|
+
import type { ObservabilityManager } from './core/manager';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Create auto-configured observability for Next.js client
|
|
20
|
+
*/
|
|
21
|
+
export async function createClientObservability() {
|
|
22
|
+
const builder = ObservabilityBuilder.create();
|
|
23
|
+
|
|
24
|
+
// Console logging control using shared utility
|
|
25
|
+
const enableConsole = shouldEnableConsole(
|
|
26
|
+
env.NEXT_PUBLIC_NODE_ENV,
|
|
27
|
+
env.NEXT_PUBLIC_OBSERVABILITY_CONSOLE_ENABLED,
|
|
28
|
+
env.NEXT_PUBLIC_OBSERVABILITY_DEBUG,
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
// Always add console plugin, control via enabled flag
|
|
32
|
+
builder.withPlugin(
|
|
33
|
+
createConsolePlugin({
|
|
34
|
+
prefix: '[Next.js Client]',
|
|
35
|
+
enabled: enableConsole,
|
|
36
|
+
}),
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
// Auto-activate Sentry if client DSN is provided
|
|
40
|
+
if (sentryEnv.NEXT_PUBLIC_SENTRY_DSN) {
|
|
41
|
+
builder.withPlugin(
|
|
42
|
+
createSentryPlugin({
|
|
43
|
+
dsn: sentryEnv.NEXT_PUBLIC_SENTRY_DSN,
|
|
44
|
+
}),
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Auto-activate Better Stack if client token is provided
|
|
49
|
+
const clientBetterStackToken =
|
|
50
|
+
betterStackEnv.NEXT_PUBLIC_BETTER_STACK_SOURCE_TOKEN ??
|
|
51
|
+
betterStackEnv.NEXT_PUBLIC_BETTERSTACK_TOKEN ??
|
|
52
|
+
betterStackEnv.NEXT_PUBLIC_LOGTAIL_TOKEN;
|
|
53
|
+
|
|
54
|
+
if (clientBetterStackToken) {
|
|
55
|
+
builder.withPlugin(
|
|
56
|
+
createBetterStackPlugin({
|
|
57
|
+
sourceToken: clientBetterStackToken,
|
|
58
|
+
}),
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return builder.build();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Lazy initialization for the observability instance using promise-based singleton
|
|
66
|
+
let initializationPromise: Promise<ObservabilityManager> | null = null;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Get or create the observability instance
|
|
70
|
+
* Uses promise-based singleton pattern to prevent race conditions in concurrent scenarios
|
|
71
|
+
* @returns Promise resolving to the ObservabilityManager instance
|
|
72
|
+
*/
|
|
73
|
+
export async function getObservability(): Promise<ObservabilityManager> {
|
|
74
|
+
if (!initializationPromise) {
|
|
75
|
+
initializationPromise = (async () => {
|
|
76
|
+
try {
|
|
77
|
+
return await createClientObservability();
|
|
78
|
+
} catch (error) {
|
|
79
|
+
// Reset cached promise on failure so callers can retry
|
|
80
|
+
initializationPromise = null;
|
|
81
|
+
throw error;
|
|
82
|
+
}
|
|
83
|
+
})();
|
|
84
|
+
|
|
85
|
+
// Set promise for React 19 hooks (dynamic import to avoid circular dependency)
|
|
86
|
+
void (async () => {
|
|
87
|
+
try {
|
|
88
|
+
const { setObservabilityPromise } = await import('./hooks/useObservability');
|
|
89
|
+
const promise = initializationPromise;
|
|
90
|
+
if (promise !== null) {
|
|
91
|
+
setObservabilityPromise(promise);
|
|
92
|
+
}
|
|
93
|
+
} catch {
|
|
94
|
+
// Hooks module not available or import failed - continue without hooks
|
|
95
|
+
}
|
|
96
|
+
})();
|
|
97
|
+
}
|
|
98
|
+
return initializationPromise;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Export types and utilities
|
|
102
|
+
export * from './core/types';
|
|
103
|
+
export { createObservability } from './factory';
|
|
104
|
+
export { ObservabilityBuilder } from './factory/builder';
|
|
105
|
+
|
|
106
|
+
// Re-export plugins for direct access (excluding conflicting exports)
|
|
107
|
+
export { BetterStackPlugin } from './plugins/betterstack';
|
|
108
|
+
export { ConsolePlugin } from './plugins/console';
|
|
109
|
+
export { SentryPlugin } from './plugins/sentry';
|
|
110
|
+
export { SentryMicroFrontendPlugin } from './plugins/sentry-microfrontend';
|
|
111
|
+
|
|
112
|
+
// Re-export plugin-specific types with aliases to avoid conflicts
|
|
113
|
+
export type { Env as BetterStackEnv, BetterStackPluginConfig } from './plugins/betterstack';
|
|
114
|
+
export type { ConsolePluginConfig } from './plugins/console';
|
|
115
|
+
export type { Env as SentryEnv, SentryPluginConfig } from './plugins/sentry';
|
|
116
|
+
export type {
|
|
117
|
+
BackstageAppConfig,
|
|
118
|
+
MicroFrontendMode,
|
|
119
|
+
SentryMicroFrontendConfig,
|
|
120
|
+
} from './plugins/sentry-microfrontend';
|
|
121
|
+
|
|
122
|
+
// Legacy function for backward compatibility (no-op)
|
|
123
|
+
/**
|
|
124
|
+
* @deprecated Configuration now happens through the observability system
|
|
125
|
+
*/
|
|
126
|
+
export const configureLogger = () => {
|
|
127
|
+
// No-op: Configuration now happens through the observability system
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
// Re-export type
|
|
131
|
+
export type LogContext = Record<string, any>;
|
package/src/client.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Auto-configuring client export for browser environments (non-Next.js)
|
|
3
|
+
* Auto-configuring client export for browser environments (non-Next.js)
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { env } from '../env';
|
|
7
|
+
|
|
8
|
+
import { ObservabilityBuilder } from './factory/builder';
|
|
9
|
+
import { createConsolePlugin } from './plugins/console';
|
|
10
|
+
import { shouldEnableConsole } from './shared';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Auto-configured observability for browser environments
|
|
14
|
+
* Automatically sets up console logging based on environment variables
|
|
15
|
+
*/
|
|
16
|
+
const builder = ObservabilityBuilder.create();
|
|
17
|
+
|
|
18
|
+
// Console logging control using shared utility
|
|
19
|
+
const enableConsole = shouldEnableConsole(
|
|
20
|
+
env.NEXT_PUBLIC_NODE_ENV,
|
|
21
|
+
env.NEXT_PUBLIC_OBSERVABILITY_CONSOLE_ENABLED,
|
|
22
|
+
env.NEXT_PUBLIC_OBSERVABILITY_DEBUG,
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
// Always add console plugin, control via enabled flag
|
|
26
|
+
builder.withPlugin(
|
|
27
|
+
createConsolePlugin({
|
|
28
|
+
prefix: '[Browser]',
|
|
29
|
+
enabled: enableConsole,
|
|
30
|
+
}),
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
// Note: Sentry and Better Stack would typically be configured by the app
|
|
34
|
+
// This is just a fallback for non-Next.js browser usage
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Pre-configured observability instance for browser environments
|
|
38
|
+
* Includes console logging with automatic environment-based configuration
|
|
39
|
+
*/
|
|
40
|
+
export const observability = builder.build();
|
|
41
|
+
|
|
42
|
+
// Export types and utilities
|
|
43
|
+
export * from './core/types';
|
|
44
|
+
export { createObservability } from './factory';
|
|
45
|
+
export { ObservabilityBuilder } from './factory/builder';
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Synchronous logger functions for non-Next.js browser environments.
|
|
49
|
+
* These are bound to a pre-built observability instance at module load time.
|
|
50
|
+
*
|
|
51
|
+
* Note: For Next.js apps, use `@repo/observability/client/next` instead,
|
|
52
|
+
* which provides async loggers that support lazy initialization.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* import { logInfo, logError } from '@repo/shared/logger';
|
|
57
|
+
* logInfo('User logged in', { userId: '123' });
|
|
58
|
+
* logError('Failed to save data', { error: err });
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
// Legacy function for backward compatibility (no-op)
|
|
62
|
+
/**
|
|
63
|
+
* @deprecated Configuration now happens through the observability system
|
|
64
|
+
*/
|
|
65
|
+
export const configureLogger = () => {
|
|
66
|
+
// No-op: Configuration now happens through the observability system
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
// Re-export type
|
|
70
|
+
export type LogContext = Record<string, any>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Core observability package exports
|
|
3
|
+
* Core observability package exports
|
|
4
|
+
* Provides types and interfaces for logging, monitoring, and telemetry
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export type {
|
|
8
|
+
Breadcrumb,
|
|
9
|
+
LogLevel,
|
|
10
|
+
ObservabilityClient,
|
|
11
|
+
ObservabilityConfig,
|
|
12
|
+
ObservabilityContext,
|
|
13
|
+
ObservabilityServer,
|
|
14
|
+
ObservabilityUser,
|
|
15
|
+
} from './types';
|