@contrail/telemetry 2.0.5 → 2.0.6-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,20 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.stdoutWriter = void 0;
4
- // Capture the original console.log before app-framework's hijackConsole() replaces it.
4
+ // Capture console.log so we can use it from the pino stdout stream.
5
5
  // Lambda treats each console.log() call as a single CloudWatch log event (even with
6
- // embedded newlines), unlike process.stdout.write() which splits on \n. Using the
7
- // original lets us pretty-print objects without them scattering across log events.
6
+ // embedded newlines), unlike process.stdout.write() which splits on \n.
8
7
  //
9
- // Guard: if telemetry is imported after hijackConsole(), the captured function would be
10
- // the hijacked one, creating an infinite loop. Detect by checking for [native code]
11
- // falls back to process.stdout.write if console.log has been replaced by anything.
8
+ // Guard: app-framework's hijackConsole() replaces console.log with overridenLog,
9
+ // which routes back into pino using it here would create an infinite loop.
10
+ // We detect that specific replacement by name. Any other replacement (e.g. the
11
+ // OTel Lambda layer's console patch) is safe to use.
12
12
  const _capturedConsoleLog = console.log;
13
- const isNative = Function.prototype.toString.call(_capturedConsoleLog).includes('[native code]');
13
+ const isAppFrameworkHijack = _capturedConsoleLog.name === 'overridenLog';
14
14
  // Wrapped in an object so tests can jest.spyOn(stdoutWriter, 'log') regardless
15
15
  // of Jest's console patching strategy (BufferedConsole vs CustomConsole).
16
16
  exports.stdoutWriter = {
17
- log: isNative
18
- ? _capturedConsoleLog
19
- : (...args) => process.stdout.write(args.map(String).join(' ') + '\n'),
17
+ log: isAppFrameworkHijack
18
+ ? (...args) => process.stdout.write(args.map(String).join(' ') + '\n')
19
+ : _capturedConsoleLog,
20
20
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/telemetry",
3
- "version": "2.0.5",
3
+ "version": "2.0.6-alpha.0",
4
4
  "description": "Telemetry and monitoring utilities for contrail services",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",