@contrail/util 1.2.0 → 1.2.1-alpha-otel-logs-2

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/CHANGELOG.md CHANGED
@@ -1,6 +1,17 @@
1
1
  # Changelog
2
2
 
3
- ## 1.2.0 (2026-03-09)
3
+ All notable changes to `@contrail/util` are documented here.
4
+
5
+ Format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
6
+ Versioning follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ### Changed
11
+
12
+ - Replaced `console.log/warn/error` calls with structured logger from `@contrail/telemetry`. No API changes. On the backend, logs are now captured by the OTel pipeline. In the browser, behavior is unchanged (Pino delegates to native console).
13
+
14
+ ## [1.2.0] - 2026-03-09
4
15
 
5
16
  ### Added
6
17
 
@@ -12,6 +23,6 @@
12
23
  - Converts `bigint`, `symbol`, and `function` values to strings
13
24
  - Skips `null` and `undefined` values
14
25
 
15
- ## 1.1.19
26
+ ## [1.1.19] - 2026-03-01
16
27
 
17
28
  - Previous stable release
@@ -3,10 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.compressIntoString = compressIntoString;
4
4
  exports.decompressFromString = decompressFromString;
5
5
  const fflate_1 = require("fflate");
6
+ const telemetry_1 = require("@contrail/telemetry");
6
7
  function compressIntoString(obj) {
7
8
  const jsonStr = JSON.stringify(obj === undefined ? null : obj);
8
9
  if (typeof Buffer === 'undefined') {
9
- console.warn('Buffer is not available. Compression will be skipped.');
10
+ telemetry_1.logger.warn('Buffer is not available. Compression will be skipped.');
10
11
  return jsonStr;
11
12
  }
12
13
  const buffer = new TextEncoder().encode(jsonStr);
@@ -15,7 +16,7 @@ function compressIntoString(obj) {
15
16
  }
16
17
  function decompressFromString(str) {
17
18
  if (typeof Buffer === 'undefined') {
18
- console.warn('Buffer is not available. Decompression will be skipped. Returning original string.');
19
+ telemetry_1.logger.warn('Buffer is not available. Decompression will be skipped. Returning original string.');
19
20
  return str;
20
21
  }
21
22
  const compressed = Buffer.from(str, 'base64');
@@ -2,9 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getIsoDatePart = getIsoDatePart;
4
4
  function getIsoDatePart(date) {
5
- console.log('date 1: ', date.toISOString(), '\n\n\n\n\n\n\n\n');
6
5
  let d = new Date(date);
7
- console.log('date 2: ', d.toISOString(), '\n\n\n\n\n\n\n\n');
8
6
  let month = '' + (d.getMonth() + 1), day = '' + d.getDate(), year = d.getFullYear();
9
7
  if (month.length < 2) {
10
8
  month = '0' + month;
@@ -10,17 +10,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const performance_util_1 = require("./performance-util");
13
+ const telemetry_1 = require("@contrail/telemetry");
13
14
  function demonstrateStartEndSpan() {
14
- console.log('--- Demonstrating startSpan/endSpan functionality ---\n');
15
+ telemetry_1.logger.debug('--- Demonstrating startSpan/endSpan functionality ---\n');
15
16
  (0, performance_util_1.clearDefaultTimingProfile)();
16
- console.log('Example 1: Simple span');
17
+ telemetry_1.logger.debug('Example 1: Simple span');
17
18
  (0, performance_util_1.startSpan)('Data Processing');
18
19
  const start1 = performance.now();
19
20
  while (performance.now() < start1 + 100) {
20
21
  }
21
22
  (0, performance_util_1.endSpan)('Data Processing');
22
23
  (0, performance_util_1.displayTimingTree)();
23
- console.log('\nExample 2: Nested spans');
24
+ telemetry_1.logger.debug('\nExample 2: Nested spans');
24
25
  (0, performance_util_1.clearDefaultTimingProfile)();
25
26
  (0, performance_util_1.startSpan)('Complete Task');
26
27
  (0, performance_util_1.startSpan)('Initialization');
@@ -47,7 +48,7 @@ function demonstrateStartEndSpan() {
47
48
  (0, performance_util_1.endSpan)('Cleanup');
48
49
  (0, performance_util_1.endSpan)('Complete Task');
49
50
  (0, performance_util_1.displayTimingTree)();
50
- console.log('\nExample 3: Multiple sequential spans');
51
+ telemetry_1.logger.debug('\nExample 3: Multiple sequential spans');
51
52
  (0, performance_util_1.clearDefaultTimingProfile)();
52
53
  (0, performance_util_1.startSpan)('Phase 1');
53
54
  const start6 = performance.now();
@@ -67,49 +68,49 @@ function demonstrateStartEndSpan() {
67
68
  (0, performance_util_1.displayTimingTree)();
68
69
  }
69
70
  function demonstrateWarningBehavior() {
70
- console.log('\n--- Demonstrating Warning Behavior ---\n');
71
+ telemetry_1.logger.debug('\n--- Demonstrating Warning Behavior ---\n');
71
72
  (0, performance_util_1.clearDefaultTimingProfile)();
72
- console.log('Example 4: Warning behavior');
73
+ telemetry_1.logger.debug('Example 4: Warning behavior');
73
74
  (0, performance_util_1.startSpan)('Test Span');
74
- console.log('Started "Test Span"');
75
+ telemetry_1.logger.debug('Started "Test Span"');
75
76
  (0, performance_util_1.startSpan)('Test Span');
76
- console.log('Attempted to start "Test Span" again (should see warning above)');
77
+ telemetry_1.logger.debug('Attempted to start "Test Span" again (should see warning above)');
77
78
  (0, performance_util_1.endSpan)('Test Span');
78
- console.log('Ended "Test Span"');
79
+ telemetry_1.logger.debug('Ended "Test Span"');
79
80
  (0, performance_util_1.endSpan)('Non-existent Span');
80
- console.log('Attempted to end "Non-existent Span" (should see warning above)');
81
+ telemetry_1.logger.debug('Attempted to end "Non-existent Span" (should see warning above)');
81
82
  (0, performance_util_1.displayTimingTree)();
82
83
  }
83
84
  function demonstrateParentNodeId() {
84
85
  return __awaiter(this, void 0, void 0, function* () {
85
- console.log('\n--- Demonstrating parentNodeId Functionality ---\n');
86
+ telemetry_1.logger.debug('\n--- Demonstrating parentNodeId Functionality ---\n');
86
87
  (0, performance_util_1.clearDefaultTimingProfile)();
87
- console.log('Example 5: Concurrent async operations with explicit parent');
88
+ telemetry_1.logger.debug('Example 5: Concurrent async operations with explicit parent');
88
89
  yield (0, performance_util_1.withTimingAsync)('Main Operation', () => __awaiter(this, void 0, void 0, function* () {
89
90
  const mainOpId = (0, performance_util_1.getCurrentParentNodeId)();
90
- console.log(`Main Operation ID: ${String(mainOpId)}`);
91
- console.log('Starting concurrent operations...');
91
+ telemetry_1.logger.debug(`Main Operation ID: ${String(mainOpId)}`);
92
+ telemetry_1.logger.debug('Starting concurrent operations...');
92
93
  const results = yield Promise.all([
93
94
  (0, performance_util_1.withTimingAsync)('Fetch User Data', () => __awaiter(this, void 0, void 0, function* () {
94
95
  yield new Promise((resolve) => setTimeout(resolve, 80));
95
- console.log(' ✓ User data fetched');
96
+ telemetry_1.logger.debug(' ✓ User data fetched');
96
97
  return 'user-data';
97
98
  }), { parentNodeId: mainOpId }),
98
99
  (0, performance_util_1.withTimingAsync)('Fetch Permissions', () => __awaiter(this, void 0, void 0, function* () {
99
100
  yield new Promise((resolve) => setTimeout(resolve, 60));
100
- console.log(' ✓ Permissions fetched');
101
+ telemetry_1.logger.debug(' ✓ Permissions fetched');
101
102
  return 'permissions-data';
102
103
  }), { parentNodeId: mainOpId }),
103
104
  (0, performance_util_1.withTimingAsync)('Fetch Preferences', () => __awaiter(this, void 0, void 0, function* () {
104
105
  yield new Promise((resolve) => setTimeout(resolve, 100));
105
- console.log(' ✓ Preferences fetched');
106
+ telemetry_1.logger.debug(' ✓ Preferences fetched');
106
107
  return 'preferences-data';
107
108
  }), { parentNodeId: mainOpId }),
108
109
  ]);
109
- console.log('All concurrent operations completed:', results);
110
+ telemetry_1.logger.debug(`All concurrent operations completed: ${JSON.stringify(results)}`);
110
111
  yield (0, performance_util_1.withTimingAsync)('Process Results', () => __awaiter(this, void 0, void 0, function* () {
111
112
  yield new Promise((resolve) => setTimeout(resolve, 30));
112
- console.log(' ✓ Results processed');
113
+ telemetry_1.logger.debug(' ✓ Results processed');
113
114
  }));
114
115
  }));
115
116
  (0, performance_util_1.displayTimingTree)();
@@ -117,140 +118,140 @@ function demonstrateParentNodeId() {
117
118
  }
118
119
  function demonstrateMixedNesting() {
119
120
  return __awaiter(this, void 0, void 0, function* () {
120
- console.log('\n--- Demonstrating Mixed Natural and Explicit Nesting ---\n');
121
+ telemetry_1.logger.debug('\n--- Demonstrating Mixed Natural and Explicit Nesting ---\n');
121
122
  (0, performance_util_1.clearDefaultTimingProfile)();
122
- console.log('Example 6: Mixed natural and explicit nesting');
123
+ telemetry_1.logger.debug('Example 6: Mixed natural and explicit nesting');
123
124
  yield (0, performance_util_1.withTimingAsync)('Application Startup', () => __awaiter(this, void 0, void 0, function* () {
124
125
  yield (0, performance_util_1.withTimingAsync)('Load Configuration', () => __awaiter(this, void 0, void 0, function* () {
125
126
  yield new Promise((resolve) => setTimeout(resolve, 50));
126
- console.log(' ✓ Configuration loaded');
127
+ telemetry_1.logger.debug(' ✓ Configuration loaded');
127
128
  yield (0, performance_util_1.withTimingAsync)('Validate Config', () => __awaiter(this, void 0, void 0, function* () {
128
129
  yield new Promise((resolve) => setTimeout(resolve, 20));
129
- console.log(' ✓ Configuration validated');
130
+ telemetry_1.logger.debug(' ✓ Configuration validated');
130
131
  }));
131
132
  }));
132
- console.log('Starting parallel initialization...');
133
+ telemetry_1.logger.debug('Starting parallel initialization...');
133
134
  (0, performance_util_1.startSpan)('Initialization');
134
135
  const ininitializeId = (0, performance_util_1.getCurrentParentNodeId)();
135
136
  (0, performance_util_1.withTimingSync)('Do something before initialization', () => {
136
137
  const start = performance.now();
137
138
  while (performance.now() < start + 20) {
138
139
  }
139
- console.log(' ✓ Pre-initialization task completed');
140
+ telemetry_1.logger.debug(' ✓ Pre-initialization task completed');
140
141
  });
141
142
  yield Promise.all([
142
143
  (0, performance_util_1.withTimingAsync)('Initialize Database', () => __awaiter(this, void 0, void 0, function* () {
143
144
  yield new Promise((resolve) => setTimeout(resolve, 120));
144
- console.log(' ✓ Database initialized');
145
+ telemetry_1.logger.debug(' ✓ Database initialized');
145
146
  }), { parentNodeId: ininitializeId }),
146
147
  (0, performance_util_1.withTimingAsync)('Initialize Cache', () => __awaiter(this, void 0, void 0, function* () {
147
148
  yield new Promise((resolve) => setTimeout(resolve, 90));
148
- console.log(' ✓ Cache initialized');
149
+ telemetry_1.logger.debug(' ✓ Cache initialized');
149
150
  }), { parentNodeId: ininitializeId }),
150
151
  (0, performance_util_1.withTimingAsync)('Initialize Logging', () => __awaiter(this, void 0, void 0, function* () {
151
152
  yield new Promise((resolve) => setTimeout(resolve, 40));
152
- console.log(' ✓ Logging initialized');
153
+ telemetry_1.logger.debug(' ✓ Logging initialized');
153
154
  }), { parentNodeId: ininitializeId }),
154
155
  ]);
155
156
  (0, performance_util_1.withTimingSync)('Do something after initialization', () => {
156
157
  const start = performance.now();
157
158
  while (performance.now() < start + 20) {
158
159
  }
159
- console.log(' ✓ Post-initialization task completed');
160
+ telemetry_1.logger.debug(' ✓ Post-initialization task completed');
160
161
  });
161
162
  (0, performance_util_1.endSpan)('Initialization');
162
163
  yield (0, performance_util_1.withTimingAsync)('Final Setup', () => __awaiter(this, void 0, void 0, function* () {
163
164
  yield new Promise((resolve) => setTimeout(resolve, 30));
164
- console.log(' ✓ Final setup completed');
165
+ telemetry_1.logger.debug(' ✓ Final setup completed');
165
166
  }));
166
167
  }));
167
168
  (0, performance_util_1.displayTimingTree)();
168
169
  });
169
170
  }
170
171
  function demonstrateSyncWithParentId() {
171
- console.log('\n--- Demonstrating Sync Functions with parentNodeId ---\n');
172
+ telemetry_1.logger.debug('\n--- Demonstrating Sync Functions with parentNodeId ---\n');
172
173
  (0, performance_util_1.clearDefaultTimingProfile)();
173
- console.log('Example 7: Sync functions with explicit parent');
174
+ telemetry_1.logger.debug('Example 7: Sync functions with explicit parent');
174
175
  (0, performance_util_1.withTimingSync)('Data Processing Pipeline', () => {
175
176
  const pipelineId = (0, performance_util_1.getCurrentParentNodeId)();
176
- console.log(`Pipeline ID: ${String(pipelineId)}`);
177
+ telemetry_1.logger.debug(`Pipeline ID: ${String(pipelineId)}`);
177
178
  (0, performance_util_1.withTimingSync)('Load Input Data', () => {
178
179
  const start = performance.now();
179
180
  while (performance.now() < start + 50) {
180
181
  }
181
- console.log(' ✓ Input data loaded');
182
+ telemetry_1.logger.debug(' ✓ Input data loaded');
182
183
  });
183
184
  (0, performance_util_1.withTimingSync)('Process Batch 1', () => {
184
185
  const start = performance.now();
185
186
  while (performance.now() < start + 80) {
186
187
  }
187
- console.log(' ✓ Batch 1 processed');
188
+ telemetry_1.logger.debug(' ✓ Batch 1 processed');
188
189
  }, { parentNodeId: pipelineId });
189
190
  (0, performance_util_1.withTimingSync)('Process Batch 2', () => {
190
191
  const start = performance.now();
191
192
  while (performance.now() < start + 70) {
192
193
  }
193
- console.log(' ✓ Batch 2 processed');
194
+ telemetry_1.logger.debug(' ✓ Batch 2 processed');
194
195
  }, { parentNodeId: pipelineId });
195
196
  (0, performance_util_1.withTimingSync)('Process Batch 3', () => {
196
197
  const start = performance.now();
197
198
  while (performance.now() < start + 90) {
198
199
  }
199
- console.log(' ✓ Batch 3 processed');
200
+ telemetry_1.logger.debug(' ✓ Batch 3 processed');
200
201
  }, { parentNodeId: pipelineId });
201
202
  (0, performance_util_1.withTimingSync)('Save Results', () => {
202
203
  const start = performance.now();
203
204
  while (performance.now() < start + 40) {
204
205
  }
205
- console.log(' ✓ Results saved');
206
+ telemetry_1.logger.debug(' ✓ Results saved');
206
207
  });
207
208
  });
208
209
  (0, performance_util_1.displayTimingTree)();
209
210
  }
210
211
  function demonstrateManualSpansWithParentId() {
211
- console.log('\n--- Demonstrating Manual Spans with parentNodeId ---\n');
212
+ telemetry_1.logger.debug('\n--- Demonstrating Manual Spans with parentNodeId ---\n');
212
213
  (0, performance_util_1.clearDefaultTimingProfile)();
213
- console.log('Example 8: Manual spans with explicit parent');
214
+ telemetry_1.logger.debug('Example 8: Manual spans with explicit parent');
214
215
  (0, performance_util_1.startSpan)('Service Request');
215
216
  const serviceId = (0, performance_util_1.getCurrentParentNodeId)();
216
- console.log(`Service Request ID: ${String(serviceId)}`);
217
+ telemetry_1.logger.debug(`Service Request ID: ${String(serviceId)}`);
217
218
  (0, performance_util_1.startSpan)('Authenticate User');
218
219
  const start1 = performance.now();
219
220
  while (performance.now() < start1 + 30) {
220
221
  }
221
222
  (0, performance_util_1.endSpan)('Authenticate User');
222
- console.log(' ✓ User authenticated');
223
+ telemetry_1.logger.debug(' ✓ User authenticated');
223
224
  (0, performance_util_1.startSpan)('Validate Input', { parentNodeId: serviceId });
224
225
  const start2 = performance.now();
225
226
  while (performance.now() < start2 + 20) {
226
227
  }
227
228
  (0, performance_util_1.endSpan)('Validate Input');
228
- console.log(' ✓ Input validated');
229
+ telemetry_1.logger.debug(' ✓ Input validated');
229
230
  (0, performance_util_1.startSpan)('Check Rate Limits', { parentNodeId: serviceId });
230
231
  const start3 = performance.now();
231
232
  while (performance.now() < start3 + 15) {
232
233
  }
233
234
  (0, performance_util_1.endSpan)('Check Rate Limits');
234
- console.log(' ✓ Rate limits checked');
235
+ telemetry_1.logger.debug(' ✓ Rate limits checked');
235
236
  (0, performance_util_1.startSpan)('Log Request', { parentNodeId: serviceId });
236
237
  const start4 = performance.now();
237
238
  while (performance.now() < start4 + 10) {
238
239
  }
239
240
  (0, performance_util_1.endSpan)('Log Request');
240
- console.log(' ✓ Request logged');
241
+ telemetry_1.logger.debug(' ✓ Request logged');
241
242
  (0, performance_util_1.startSpan)('Process Request');
242
243
  const start5 = performance.now();
243
244
  while (performance.now() < start5 + 60) {
244
245
  }
245
246
  (0, performance_util_1.endSpan)('Process Request');
246
- console.log(' ✓ Request processed');
247
+ telemetry_1.logger.debug(' ✓ Request processed');
247
248
  (0, performance_util_1.endSpan)('Service Request');
248
249
  (0, performance_util_1.displayTimingTree)();
249
250
  }
250
251
  function demonstrateNestingComparison() {
251
252
  return __awaiter(this, void 0, void 0, function* () {
252
- console.log('\n--- Demonstrating Natural vs Explicit Nesting ---\n');
253
- console.log('Natural Nesting (call stack based):');
253
+ telemetry_1.logger.debug('\n--- Demonstrating Natural vs Explicit Nesting ---\n');
254
+ telemetry_1.logger.debug('Natural Nesting (call stack based):');
254
255
  (0, performance_util_1.clearDefaultTimingProfile)();
255
256
  yield (0, performance_util_1.withTimingAsync)('Sequential Operations', () => __awaiter(this, void 0, void 0, function* () {
256
257
  yield (0, performance_util_1.withTimingAsync)('Operation 1', () => __awaiter(this, void 0, void 0, function* () {
@@ -264,7 +265,7 @@ function demonstrateNestingComparison() {
264
265
  }));
265
266
  }));
266
267
  (0, performance_util_1.displayTimingTree)();
267
- console.log('\nExplicit Parent Assignment (logical grouping):');
268
+ telemetry_1.logger.debug('\nExplicit Parent Assignment (logical grouping):');
268
269
  (0, performance_util_1.clearDefaultTimingProfile)();
269
270
  yield (0, performance_util_1.withTimingAsync)('Parallel Operations', () => __awaiter(this, void 0, void 0, function* () {
270
271
  const parentId = (0, performance_util_1.getCurrentParentNodeId)();
@@ -292,7 +293,7 @@ function runAllExamples() {
292
293
  demonstrateSyncWithParentId();
293
294
  demonstrateManualSpansWithParentId();
294
295
  yield demonstrateNestingComparison();
295
- console.log('\nAll examples completed. ');
296
+ telemetry_1.logger.debug('\nAll examples completed. ');
296
297
  });
297
298
  }
298
- runAllExamples().catch(console.error);
299
+ runAllExamples().catch((err) => telemetry_1.logger.error({ err }, 'Example run failed'));
@@ -17,6 +17,7 @@ exports.withTimingSync = withTimingSync;
17
17
  exports.displayTimingTree = displayTimingTree;
18
18
  exports.startSpan = startSpan;
19
19
  exports.endSpan = endSpan;
20
+ const telemetry_1 = require("@contrail/telemetry");
20
21
  const DEFAULT_TIMING_PROFILE = {
21
22
  activeSpans: new Map(),
22
23
  spansById: new Map(),
@@ -187,15 +188,15 @@ function displayTimingTree(nodes = DEFAULT_TIMING_PROFILE.timingSpans, depth = 0
187
188
  });
188
189
  const result = lines.join('\n');
189
190
  if (depth === 0) {
190
- console.log('\n--- Performance Timing Tree ---\n');
191
- console.log(result);
192
- console.log('\n--- End Timing ---\n');
191
+ telemetry_1.logger.debug('\n--- Performance Timing Tree ---\n');
192
+ telemetry_1.logger.debug(result);
193
+ telemetry_1.logger.debug('\n--- End Timing ---\n');
193
194
  }
194
195
  return result;
195
196
  }
196
197
  function startSpan(spanName, options) {
197
198
  if (DEFAULT_TIMING_PROFILE.activeSpans.has(spanName)) {
198
- console.warn(`Span "${spanName}" is already active. Please end it before starting a new one with the same name.`);
199
+ telemetry_1.logger.warn(`Span "${spanName}" is already active. Please end it before starting a new one with the same name.`);
199
200
  return;
200
201
  }
201
202
  const startTime = performance.now();
@@ -229,7 +230,7 @@ function startSpan(spanName, options) {
229
230
  function endSpan(spanName) {
230
231
  const activeSpan = DEFAULT_TIMING_PROFILE.activeSpans.get(spanName);
231
232
  if (!activeSpan) {
232
- console.warn(`No active span found with name "${spanName}". Make sure to call startSpan() first.`);
233
+ telemetry_1.logger.warn(`No active span found with name "${spanName}". Make sure to call startSpan() first.`);
233
234
  return;
234
235
  }
235
236
  const endTime = performance.now();
@@ -1,8 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.StringUtil = void 0;
4
+ const telemetry_1 = require("@contrail/telemetry");
4
5
  class StringUtil {
5
6
  static convertToHyphenCase(entityName, transformToLowerCase = true) {
7
+ console.log('console log within convertToHyphenCase👋');
8
+ telemetry_1.logger.info({ entityName, transformToLowerCase }, 'Converting entity name to hyphen case');
6
9
  const slugName = entityName === null || entityName === void 0 ? void 0 : entityName.split(/(?=[A-Z])/).join('-');
7
10
  if (slugName && transformToLowerCase) {
8
11
  return slugName.toLowerCase();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/util",
3
- "version": "1.2.0",
3
+ "version": "1.2.1-alpha-otel-logs-2",
4
4
  "description": "General JavaScript utilities",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -39,6 +39,7 @@
39
39
  "testEnvironment": "node"
40
40
  },
41
41
  "dependencies": {
42
+ "@contrail/telemetry": "^1.0.1-alpha-logger-1",
42
43
  "@contrail/types": "^3.1.3",
43
44
  "fflate": "^0.8.2",
44
45
  "lodash": "^4.17.21"