sasai-common-utils 1.0.53 → 1.0.55

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sasai-common-utils",
3
- "version": "1.0.53",
3
+ "version": "1.0.55",
4
4
  "description": "Reusable utility library for common logging and other shared features.",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -13,12 +13,12 @@
13
13
  "@elastic/ecs-winston-format": "^1.5.3",
14
14
  "@opentelemetry/api-logs": "^0.211.0",
15
15
  "@opentelemetry/exporter-logs-otlp-http": "^0.211.0",
16
+ "@opentelemetry/instrumentation-pino": "^0.55.0",
16
17
  "@opentelemetry/resources": "^2.5.0",
17
18
  "@opentelemetry/sdk-logs": "^0.211.0",
18
19
  "jsonwebtoken": "^9.0.2",
19
20
  "klona": "^2.0.6",
20
21
  "pino": "^9.6.0",
21
- "pino-opentelemetry-transport": "^1.1.0",
22
22
  "pino-pretty": "^13.0.0",
23
23
  "traverse": "^0.6.11",
24
24
  "winston": "^3.17.0"
@@ -7,7 +7,6 @@ let contextProvider = () => ({});
7
7
  let globalConfig = {};
8
8
  let loggerInstance;
9
9
  let pinoLogger;
10
- let pinoTransport;
11
10
 
12
11
  function setContextProvider(provider) {
13
12
  contextProvider = typeof provider === "function" ? provider : () => ({});
@@ -20,9 +19,6 @@ function setGlobalConfig(config) {
20
19
  DEBUG_MODE: config?.DEBUG_MODE,
21
20
  SENSITIVE_KEYS: config?.SENSITIVE_KEYS,
22
21
  NODE_ENV: config?.NODE_ENV,
23
- OTEL_EXPORTER_OTLP_LOGS_ENDPOINT: config?.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT,
24
- OTEL_EXPORTER_OTLP_LOGS_PROTOCOL:
25
- config?.OTEL_EXPORTER_OTLP_LOGS_PROTOCOL || "http/protobuf",
26
22
  };
27
23
  }
28
24
 
@@ -86,6 +82,7 @@ function getTraceContext() {
86
82
  function initPinoLogger() {
87
83
  const pinoOptions = {
88
84
  timestamp: false,
85
+ messageKey: "message",
89
86
  level:
90
87
  globalConfig.DEBUG_MODE === DEBUG_MODES.DISABLE
91
88
  ? "silent"
@@ -101,54 +98,23 @@ function initPinoLogger() {
101
98
  },
102
99
  };
103
100
 
104
- if (globalConfig.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT) {
105
- const stdoutTarget = {
106
- target: require.resolve("pino/file"),
107
- options: { destination: 1 },
108
- };
109
-
110
- const otelTarget = {
111
- target: require.resolve("pino-opentelemetry-transport"),
112
- options: {
113
- url: globalConfig.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT,
114
- protocol: globalConfig.OTEL_EXPORTER_OTLP_LOGS_PROTOCOL,
115
- resourceAttributes: {
116
- "service.name": globalConfig.SERVICE_NAME,
117
- "deployment.environment": globalConfig.NODE_ENV,
118
- },
119
- },
120
- };
121
-
122
- pinoTransport = pino.transport({
123
- targets: [stdoutTarget, otelTarget],
124
- });
125
-
126
- pinoTransport.on("error", (err) => {
127
- console.error("Pino OTEL transport error:", err);
128
- });
129
-
130
- pinoTransport.on("close", () => {
131
- console.warn("Pino OTEL transport closed");
132
- });
133
-
134
- pinoLogger = pino(pinoOptions, pinoTransport);
101
+ // OTel log export is handled by PinoInstrumentation inside the NodeSDK (tracing.js).
102
+ // Pino only needs to write to its local destination (stdout or file).
103
+ // PinoInstrumentation hooks into pino internally and routes records through
104
+ // the OTel Logs SDK pipeline automatically — no separate transport needed.
105
+ let destination;
106
+ if (globalConfig.DEBUG_MODE === DEBUG_MODES.FILE) {
107
+ destination = pino.destination("app.log");
135
108
  } else {
136
- let destination;
137
- if (globalConfig.DEBUG_MODE === DEBUG_MODES.FILE) {
138
- destination = pino.destination("app.log");
139
- } else {
140
- destination = pino.destination(1);
141
- }
142
- pinoLogger = pino(pinoOptions, destination);
109
+ destination = pino.destination(1); // stdout
143
110
  }
111
+ pinoLogger = pino(pinoOptions, destination);
144
112
 
145
113
  try {
146
114
  pinoLogger.info({
147
115
  message: "Pino logger initialized",
148
116
  "service.name": globalConfig.SERVICE_NAME,
149
117
  "deployment.environment": globalConfig.NODE_ENV,
150
- otel_logs_endpoint: globalConfig.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT || "",
151
- otel_logs_protocol: globalConfig.OTEL_EXPORTER_OTLP_LOGS_PROTOCOL || "",
152
118
  });
153
119
  } catch (error) {
154
120
  console.error("Failed to write startup log:", error);
@@ -165,13 +131,21 @@ function emitLog(level, data) {
165
131
  ? cleanString(message)
166
132
  : "Application log";
167
133
 
168
- pinoLogger[level]({
134
+ const logPayload = {
135
+ app: globalConfig.SERVICE_NAME,
169
136
  trace_id: trace || undefined,
170
137
  span_id: span || undefined,
171
138
  parent_span_id: parentSpan || undefined,
172
- body: finalMessage,
173
- message: finalMessage,
174
139
  ...rest,
140
+ };
141
+
142
+ // OTel body (shown in SigNoz list view) = full serialized payload so the
143
+ // entire structured data is visible at a glance, not just the label string.
144
+ const fullBody = safeJsonStringify({ message: finalMessage, ...logPayload });
145
+
146
+ pinoLogger[level]({
147
+ ...logPayload,
148
+ message: fullBody, // PinoInstrumentation reads messageKey ("message") as OTel body
175
149
  });
176
150
  }
177
151
 
@@ -274,11 +248,11 @@ function createLogger(config) {
274
248
 
275
249
  flush: async () => {
276
250
  try {
277
- if (pinoTransport && typeof pinoTransport.flush === "function") {
278
- await pinoTransport.flush();
251
+ if (pinoLogger && typeof pinoLogger.flush === "function") {
252
+ pinoLogger.flush();
279
253
  }
280
254
  } catch (error) {
281
- console.error("Failed to flush pino transport:", error);
255
+ console.error("Failed to flush pino logger:", error);
282
256
  }
283
257
  },
284
258
  };