@contrail/telemetry 2.0.4 → 2.0.5

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.
@@ -82,6 +82,7 @@ const otelLoggerProvider = new sdk_logs_1.LoggerProvider({
82
82
  });
83
83
  const otelLogger = otelLoggerProvider.getLogger(serviceName);
84
84
  // --- Pino Stream Destinations ---
85
+ const stdout_writer_1 = require("./stdout-writer");
85
86
  function isPinoPrettyInstalled() {
86
87
  try {
87
88
  require.resolve('pino-pretty');
@@ -117,14 +118,14 @@ function createStdoutStream() {
117
118
  const requestId = (_d = getLambdaRequestId()) !== null && _d !== void 0 ? _d : '-';
118
119
  const payload = logRecord[semantic_conventions_2.ATTR_LOG_PAYLOAD];
119
120
  const payloadLine = payload && typeof payload === 'object' && Object.keys(payload).length > 0
120
- ? `${JSON.stringify(payload, null, 2)}\n`
121
+ ? `\n${JSON.stringify(payload, null, 2)}`
121
122
  : '';
122
- line = `${time}\t${requestId}\t${level}\t${message}\n${payloadLine}`;
123
+ line = `${time}\t${requestId}\t${level}\t${message}${payloadLine}`;
123
124
  }
124
125
  catch {
125
- line = chunk.toString();
126
+ line = chunk.toString().replace(/\n$/, '');
126
127
  }
127
- process.stdout.write(line);
128
+ stdout_writer_1.stdoutWriter.log(line);
128
129
  callback();
129
130
  },
130
131
  }),
@@ -0,0 +1,6 @@
1
+ export declare const stdoutWriter: {
2
+ log: {
3
+ (...data: any[]): void;
4
+ (message?: any, ...optionalParams: any[]): void;
5
+ };
6
+ };
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.stdoutWriter = void 0;
4
+ // Capture the original console.log before app-framework's hijackConsole() replaces it.
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.
8
+ //
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.
12
+ const _capturedConsoleLog = console.log;
13
+ const isNative = Function.prototype.toString.call(_capturedConsoleLog).includes('[native code]');
14
+ // Wrapped in an object so tests can jest.spyOn(stdoutWriter, 'log') regardless
15
+ // of Jest's console patching strategy (BufferedConsole vs CustomConsole).
16
+ exports.stdoutWriter = {
17
+ log: isNative
18
+ ? _capturedConsoleLog
19
+ : (...args) => process.stdout.write(args.map(String).join(' ') + '\n'),
20
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/telemetry",
3
- "version": "2.0.4",
3
+ "version": "2.0.5",
4
4
  "description": "Telemetry and monitoring utilities for contrail services",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",