@contrail/telemetry 1.1.0-alpha-refactor-telemetry-1 → 2.0.0-dev-telemetry-own-otel-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.
@@ -16,7 +16,7 @@ const resources_1 = require("@opentelemetry/resources");
16
16
  const api_1 = require("@opentelemetry/api");
17
17
  const stream_1 = require("stream");
18
18
  const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
19
- const flatten_object_1 = require("./flatten-object");
19
+ const util_1 = require("@contrail/util");
20
20
  const logger_config_1 = require("./logger-config");
21
21
  const parse_otel_resource_attributes_1 = require("./parse-otel-resource-attributes");
22
22
  const semantic_conventions_2 = require("./semantic-conventions");
@@ -115,7 +115,7 @@ function createOtelStream() {
115
115
  const lambdaEnvAttributes = LAMBDA_ENV_OTEL_ATTRIBUTES;
116
116
  let safeAttributes;
117
117
  try {
118
- safeAttributes = (0, flatten_object_1.flattenObject)(attributes);
118
+ safeAttributes = util_1.ObjectUtil.flattenObject(attributes);
119
119
  }
120
120
  catch {
121
121
  // Fallback in case flattening fails somehow. This is not expected.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/telemetry",
3
- "version": "1.1.0-alpha-refactor-telemetry-1",
3
+ "version": "2.0.0-dev-telemetry-own-otel-1",
4
4
  "description": "Telemetry and monitoring utilities for contrail services",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -15,6 +15,7 @@
15
15
  "license": "ISC",
16
16
  "dependencies": {
17
17
  "@codegenie/serverless-express": "^4.16.0",
18
+ "@contrail/util": "^1.2.1",
18
19
  "@opentelemetry/api": "^1.9.0",
19
20
  "@opentelemetry/api-logs": "^0.211.0",
20
21
  "@opentelemetry/core": "^2.5.0",
@@ -34,7 +35,7 @@
34
35
  }
35
36
  },
36
37
  "devDependencies": {
37
- "@types/aws-lambda": "^8.10.161",
38
+ "@types/aws-lambda": "^8.10.145",
38
39
  "@types/jest": "^29.5.2",
39
40
  "@types/node": "^20.0.0",
40
41
  "jest": "^29.5.0",
@@ -1,4 +0,0 @@
1
- type PrimitiveValue = string | number | boolean;
2
- type FlattenedObject = Record<string, PrimitiveValue>;
3
- export declare function flattenObject(obj: Record<string, unknown>): FlattenedObject;
4
- export {};
@@ -1,60 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.flattenObject = flattenObject;
4
- const MAX_DEPTH = 10;
5
- function flattenObject(obj) {
6
- const seen = new WeakSet();
7
- return flattenRecursive(obj, '', seen, 0);
8
- }
9
- function flattenRecursive(obj, prefix, ancestors, depth) {
10
- const result = {};
11
- if (depth > MAX_DEPTH) {
12
- result[prefix || 'value'] = '[max depth exceeded]';
13
- return result;
14
- }
15
- ancestors.add(obj);
16
- for (const [key, value] of Object.entries(obj)) {
17
- const fullKey = prefix ? `${prefix}.${key}` : key;
18
- if (value === null || value === undefined) {
19
- continue;
20
- }
21
- if (typeof value === 'object') {
22
- if (ancestors.has(value)) {
23
- result[fullKey] = '[circular reference]';
24
- continue;
25
- }
26
- if (Array.isArray(value)) {
27
- result[fullKey] = JSON.stringify(value);
28
- }
29
- else if (value instanceof Date) {
30
- result[fullKey] = value.toISOString();
31
- }
32
- else if (value instanceof Error) {
33
- result[fullKey] = value.message;
34
- if (value.stack) {
35
- result[`${fullKey}.stack`] = value.stack;
36
- }
37
- }
38
- else {
39
- Object.assign(result, flattenRecursive(value, fullKey, ancestors, depth + 1));
40
- }
41
- }
42
- else if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
43
- result[fullKey] = value;
44
- }
45
- else if (typeof value === 'bigint') {
46
- result[fullKey] = value.toString();
47
- }
48
- else if (typeof value === 'symbol') {
49
- result[fullKey] = value.toString();
50
- }
51
- else if (typeof value === 'function') {
52
- result[fullKey] = '[function]';
53
- }
54
- else {
55
- result[fullKey] = String(value);
56
- }
57
- }
58
- ancestors.delete(obj);
59
- return result;
60
- }