@contrail/telemetry 2.0.7 → 2.0.8-alpha-formatting.1

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.
@@ -57,6 +57,11 @@ if (globalRecord[TELEMETRY_SINGLETON_KEY]) {
57
57
  else {
58
58
  globalRecord[TELEMETRY_SINGLETON_KEY] = true;
59
59
  }
60
+ // Capture the real console.log before app-framework's hijackConsole() replaces it.
61
+ // This module loads first (as a dependency), so this is always the original.
62
+ // Using it in the stdout stream avoids the infinite loop (hijacked console → pino → console → …)
63
+ // while preserving single-event CloudWatch output (process.stdout.write splits on newlines).
64
+ const originalConsoleLog = console.log;
60
65
  // --- Environment & Resource Setup ---
61
66
  const semantic_conventions_4 = require("../semantic-conventions");
62
67
  const LAMBDA_ENV_OTEL_ATTRIBUTES = getLambdaEnvAttributes();
@@ -82,7 +87,6 @@ const otelLoggerProvider = new sdk_logs_1.LoggerProvider({
82
87
  });
83
88
  const otelLogger = otelLoggerProvider.getLogger(serviceName);
84
89
  // --- Pino Stream Destinations ---
85
- const stdout_writer_1 = require("./stdout-writer");
86
90
  function isPinoPrettyInstalled() {
87
91
  try {
88
92
  require.resolve('pino-pretty');
@@ -125,7 +129,7 @@ function createStdoutStream() {
125
129
  catch {
126
130
  line = chunk.toString().replace(/\n$/, '');
127
131
  }
128
- stdout_writer_1.stdoutWriter.log(line);
132
+ originalConsoleLog(line);
129
133
  callback();
130
134
  },
131
135
  }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/telemetry",
3
- "version": "2.0.7",
3
+ "version": "2.0.8-alpha-formatting.1",
4
4
  "description": "Telemetry and monitoring utilities for contrail services",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -1,6 +0,0 @@
1
- export declare const stdoutWriter: {
2
- log: {
3
- (...data: any[]): void;
4
- (message?: any, ...optionalParams: any[]): void;
5
- };
6
- };
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.stdoutWriter = void 0;
4
- // Capture console.log so we can use it from the pino stdout stream.
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.
7
- //
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
- // Any other console.log replacement (e.g. the OTel Lambda layer) is safe to use.
11
- const _capturedConsoleLog = console.log;
12
- const isConsoleHijacked = _capturedConsoleLog.name === 'overridenLog';
13
- // Wrapped in an object so tests can jest.spyOn(stdoutWriter, 'log') regardless
14
- // of Jest's console patching strategy (BufferedConsole vs CustomConsole).
15
- exports.stdoutWriter = {
16
- log: isConsoleHijacked
17
- ? (...args) => process.stdout.write(args.map(String).join(' ') + '\n')
18
- : _capturedConsoleLog,
19
- };