@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/src/server.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Auto-configuring server export for Node.js environments (non-Next.js)
|
|
3
|
+
* Auto-configuring server export for Node.js environments (non-Next.js)
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { safeEnv } from '../env';
|
|
7
|
+
|
|
8
|
+
import { ObservabilityBuilder } from './factory/builder';
|
|
9
|
+
import { createConsoleServerPlugin } from './plugins/console';
|
|
10
|
+
import { shouldEnableConsole } from './shared';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Auto-configured observability for Node.js server 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 env = safeEnv();
|
|
20
|
+
const enableConsole = shouldEnableConsole(
|
|
21
|
+
env.NEXT_PUBLIC_NODE_ENV,
|
|
22
|
+
env.NEXT_PUBLIC_OBSERVABILITY_CONSOLE_ENABLED,
|
|
23
|
+
env.NEXT_PUBLIC_OBSERVABILITY_DEBUG,
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
// Always add console plugin, control via enabled flag
|
|
27
|
+
builder.withPlugin(
|
|
28
|
+
createConsoleServerPlugin({
|
|
29
|
+
prefix: '[Server]',
|
|
30
|
+
enabled: enableConsole,
|
|
31
|
+
}),
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
// Note: Production providers would typically be configured by the app
|
|
35
|
+
// This is just a fallback for non-Next.js server usage
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Pre-configured observability instance for Node.js server environments
|
|
39
|
+
* Includes console logging with automatic environment-based configuration
|
|
40
|
+
*/
|
|
41
|
+
export const observability = builder.build();
|
|
42
|
+
|
|
43
|
+
// Export types and utilities
|
|
44
|
+
export * from './core/types';
|
|
45
|
+
export { createObservability } from './factory';
|
|
46
|
+
export { ObservabilityBuilder } from './factory/builder';
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Synchronous logger functions for non-Next.js Node.js environments.
|
|
50
|
+
* These are bound to a pre-built observability instance at module load time.
|
|
51
|
+
*
|
|
52
|
+
* Note: For Next.js apps, use `@repo/observability/server/next` instead,
|
|
53
|
+
* which provides async loggers that support lazy initialization.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* import { logInfo, logError } from '@repo/shared/logger';
|
|
58
|
+
* logInfo('Server started', { port: 3000 });
|
|
59
|
+
* logError('Database connection failed', { error: err });
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
// Legacy function for backward compatibility (no-op)
|
|
63
|
+
/**
|
|
64
|
+
* @deprecated Configuration now happens through the observability system
|
|
65
|
+
*/
|
|
66
|
+
export const configureLogger = () => {
|
|
67
|
+
// No-op: Configuration now happens through the observability system
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
// Re-export type
|
|
71
|
+
export type LogContext = Record<string, any>;
|
package/src/shared.ts
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Shared observability utilities and types
|
|
3
|
+
* Shared observability utilities and types
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { logWarn } from '@repo/shared/logger';
|
|
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
|
+
export const getRuntimeInfo = () => {
|
|
25
|
+
// Edge runtime detection (Vercel Edge, Cloudflare Workers)
|
|
26
|
+
if (typeof globalThis !== 'undefined' && (globalThis as any).EdgeRuntime) {
|
|
27
|
+
return { type: 'edge', variant: 'vercel' };
|
|
28
|
+
}
|
|
29
|
+
if (
|
|
30
|
+
typeof globalThis !== 'undefined' &&
|
|
31
|
+
(globalThis as any).caches &&
|
|
32
|
+
typeof (globalThis as any).caches !== 'undefined'
|
|
33
|
+
) {
|
|
34
|
+
return { type: 'edge', variant: 'cloudflare' };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Bun detection
|
|
38
|
+
if (typeof process !== 'undefined' && process.versions?.bun) {
|
|
39
|
+
return { type: 'bun', version: process.versions.bun };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Browser detection (more robust)
|
|
43
|
+
if (
|
|
44
|
+
typeof globalThis !== 'undefined' &&
|
|
45
|
+
'window' in globalThis &&
|
|
46
|
+
typeof (globalThis as any).window !== 'undefined' &&
|
|
47
|
+
typeof (globalThis as any).window.document !== 'undefined' &&
|
|
48
|
+
typeof (globalThis as any).window.navigator !== 'undefined'
|
|
49
|
+
) {
|
|
50
|
+
return { type: 'browser', isNextJs: Boolean((globalThis as any).window.__NEXT_DATA__) };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Node.js detection with version check
|
|
54
|
+
if (typeof process !== 'undefined' && process.versions?.node) {
|
|
55
|
+
const nodeVersion = parseInt(process.versions.node.split('.')[0] ?? '0');
|
|
56
|
+
const nodeVersionMinor = parseInt(process.versions.node.split('.')[1] ?? '0');
|
|
57
|
+
|
|
58
|
+
if (nodeVersion < 22) {
|
|
59
|
+
// Note: Using logWarn here - observability system may not be initialized yet, but shared logger is always available
|
|
60
|
+
logWarn(
|
|
61
|
+
`[Observability] Node ${process.versions.node} detected. Node 22+ is required for optimal performance and latest features.`,
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
type: 'node',
|
|
67
|
+
version: process.versions.node,
|
|
68
|
+
major: nodeVersion,
|
|
69
|
+
minor: nodeVersionMinor,
|
|
70
|
+
isNode22Plus: nodeVersion >= 22,
|
|
71
|
+
isNextJs:
|
|
72
|
+
Boolean(process.env.NEXT_RUNTIME) ||
|
|
73
|
+
Boolean(process.env.__NEXT_RUNTIME) ||
|
|
74
|
+
Boolean(process.env.NEXT_PUBLIC_VERCEL_ENV),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Fallback
|
|
79
|
+
return { type: 'unknown' };
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
// Cache the runtime info
|
|
83
|
+
const runtimeInfo = getRuntimeInfo();
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Get cached runtime environment information.
|
|
87
|
+
*
|
|
88
|
+
* Returns the runtime information that was detected at module load time.
|
|
89
|
+
* This is cached to avoid repeated detection checks.
|
|
90
|
+
*
|
|
91
|
+
* @returns Cached runtime information object
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```typescript
|
|
95
|
+
* const runtime = getRuntimeEnvironment();
|
|
96
|
+
* console.log(runtime.type); // 'node', 'browser', 'edge', etc.
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
export const getRuntimeEnvironment = () => runtimeInfo;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Detect if code is running in a browser environment
|
|
103
|
+
* Extracted to shared utility to avoid duplication
|
|
104
|
+
* @returns true if running in browser, false otherwise
|
|
105
|
+
*/
|
|
106
|
+
export function isBrowser(): boolean {
|
|
107
|
+
return (
|
|
108
|
+
typeof globalThis !== 'undefined' &&
|
|
109
|
+
'window' in globalThis &&
|
|
110
|
+
typeof (globalThis as any).window !== 'undefined' &&
|
|
111
|
+
typeof (globalThis as any).window.document !== 'undefined' &&
|
|
112
|
+
typeof (globalThis as any).window.navigator !== 'undefined'
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Determine if console logging should be enabled based on environment
|
|
118
|
+
* Centralized logic to avoid duplication across entry points
|
|
119
|
+
* @param envNodeEnv - The NEXT_PUBLIC_NODE_ENV value
|
|
120
|
+
* @param consoleEnabled - The NEXT_PUBLIC_OBSERVABILITY_CONSOLE_ENABLED value (explicit control)
|
|
121
|
+
* @param debugEnabled - The NEXT_PUBLIC_OBSERVABILITY_DEBUG value
|
|
122
|
+
* @returns boolean indicating if console should be enabled
|
|
123
|
+
*/
|
|
124
|
+
export function shouldEnableConsole(
|
|
125
|
+
envNodeEnv?: string,
|
|
126
|
+
consoleEnabled?: boolean,
|
|
127
|
+
debugEnabled?: boolean,
|
|
128
|
+
): boolean {
|
|
129
|
+
const isDevelopment = envNodeEnv === 'development' || process.env.NODE_ENV === 'development';
|
|
130
|
+
|
|
131
|
+
// Priority: explicit control > development mode > debug mode
|
|
132
|
+
if (consoleEnabled !== undefined) {
|
|
133
|
+
return consoleEnabled;
|
|
134
|
+
}
|
|
135
|
+
if (isDevelopment) {
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
138
|
+
return debugEnabled ?? false;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Export types for convenience - removed for Rollup compatibility
|
|
142
|
+
|
|
143
|
+
// Note: For direct access to observability instances, import from environment-specific modules:
|
|
144
|
+
// - @repo/observability/client-next
|
|
145
|
+
// - @repo/observability/server-next
|
|
146
|
+
// - @repo/observability/server-edge
|
|
147
|
+
// - @repo/observability/client
|
|
148
|
+
// - @repo/observability/server
|