@edirect/trace 9.0.0 → 9.0.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/.editorconfig CHANGED
@@ -1,14 +1,14 @@
1
- root = true
2
-
3
- [*]
4
- end_of_line = lf
5
- insert_final_newline = true
6
- charset = utf-8
7
-
8
- [*.js]
9
- indent_style = space
10
- indent_size = 2
11
- trim_trailing_whitespace = true
12
-
13
- [*.md]
14
- trim_trailing_whitespace = false
1
+ root = true
2
+
3
+ [*]
4
+ end_of_line = lf
5
+ insert_final_newline = true
6
+ charset = utf-8
7
+
8
+ [*.js]
9
+ indent_style = space
10
+ indent_size = 2
11
+ trim_trailing_whitespace = true
12
+
13
+ [*.md]
14
+ trim_trailing_whitespace = false
package/.eslintignore CHANGED
@@ -1 +1 @@
1
- /node_modules
1
+ /node_modules
package/.eslintrc.js CHANGED
@@ -1,44 +1,44 @@
1
- module.exports = {
2
- env: {
3
- browser: true,
4
- es6: true,
5
- node: true,
6
- },
7
- extends: [
8
- 'plugin:@typescript-eslint/recommended',
9
- 'prettier'
10
- ],
11
- globals: {
12
- Atomics: 'readonly',
13
- SharedArrayBuffer: 'readonly',
14
- },
15
- parser: '@typescript-eslint/parser',
16
- parserOptions: {
17
- ecmaFeatures: {
18
- jsx: true,
19
- },
20
- ecmaVersion: 2018,
21
- sourceType: 'module',
22
- project: './tsconfig.json',
23
- tsconfigRootDir: __dirname,
24
- },
25
- plugins: ['@typescript-eslint', 'prettier'],
26
- rules: {
27
- 'no-unused-vars': 0,
28
- '@typescript-eslint/no-unused-vars': [
29
- 'error',
30
- { argsIgnorePattern: '^_', varsIgnorePattern: '^_' },
31
- ],
32
- '@typescript-eslint/no-explicit-any': 0,
33
- '@typescript-eslint/ban-ts-ignore': 0,
34
- '@typescript-eslint/explicit-function-return-type': [
35
- 'warn',
36
- {
37
- allowExpressions: true,
38
- allowTypedFunctionExpressions: true,
39
- allowHigherOrderFunctions: true,
40
- },
41
- ],
42
- '@typescript-eslint/no-floating-promises': 1,
43
- },
44
- };
1
+ module.exports = {
2
+ env: {
3
+ browser: true,
4
+ es6: true,
5
+ node: true,
6
+ },
7
+ extends: [
8
+ 'plugin:@typescript-eslint/recommended',
9
+ 'prettier'
10
+ ],
11
+ globals: {
12
+ Atomics: 'readonly',
13
+ SharedArrayBuffer: 'readonly',
14
+ },
15
+ parser: '@typescript-eslint/parser',
16
+ parserOptions: {
17
+ ecmaFeatures: {
18
+ jsx: true,
19
+ },
20
+ ecmaVersion: 2018,
21
+ sourceType: 'module',
22
+ project: './tsconfig.json',
23
+ tsconfigRootDir: __dirname,
24
+ },
25
+ plugins: ['@typescript-eslint', 'prettier'],
26
+ rules: {
27
+ 'no-unused-vars': 0,
28
+ '@typescript-eslint/no-unused-vars': [
29
+ 'error',
30
+ { argsIgnorePattern: '^_', varsIgnorePattern: '^_' },
31
+ ],
32
+ '@typescript-eslint/no-explicit-any': 0,
33
+ '@typescript-eslint/ban-ts-ignore': 0,
34
+ '@typescript-eslint/explicit-function-return-type': [
35
+ 'warn',
36
+ {
37
+ allowExpressions: true,
38
+ allowTypedFunctionExpressions: true,
39
+ allowHigherOrderFunctions: true,
40
+ },
41
+ ],
42
+ '@typescript-eslint/no-floating-promises': 1,
43
+ },
44
+ };
package/.eslintrc.json CHANGED
@@ -1,159 +1,159 @@
1
- {
2
- "extends": [
3
- "standard",
4
- "plugin:node/recommended",
5
- "plugin:promise/recommended",
6
- "plugin:import/errors",
7
- "plugin:import/warnings"
8
- ],
9
- "plugins": [
10
- "standard"
11
- ],
12
- "rules": {
13
- "camelcase": [
14
- 0
15
- ],
16
- "indent": [
17
- 2,
18
- 2,
19
- {
20
- "SwitchCase": 2
21
- }
22
- ],
23
- "object-curly-spacing": [
24
- "error",
25
- "always"
26
- ],
27
- "array-bracket-spacing": [
28
- "error",
29
- "always"
30
- ],
31
- "eqeqeq": [
32
- "error",
33
- "always"
34
- ],
35
- "no-else-return": [
36
- "error",
37
- {
38
- "allowElseIf": false
39
- }
40
- ],
41
- "no-multi-spaces": "error",
42
- "no-new-wrappers": "error",
43
- "no-redeclare": "error",
44
- "no-undef-init": "error",
45
- "no-unused-vars": "error",
46
- "no-use-before-define": [
47
- "error",
48
- {
49
- "functions": false
50
- }
51
- ],
52
- "comma-dangle": [
53
- "error",
54
- "never"
55
- ],
56
- "comma-spacing": [
57
- "error",
58
- {
59
- "before": false,
60
- "after": true
61
- }
62
- ],
63
- "comma-style": [
64
- "error",
65
- "last"
66
- ],
67
- "no-implied-eval": "error",
68
- "no-mixed-operators": "off",
69
- "node/exports-style": [
70
- "error",
71
- "module.exports"
72
- ],
73
- "node/no-unpublished-require": "off",
74
- "promise/no-callback-in-promise": "off",
75
- "promise/no-nesting": "off",
76
- "max-len": [
77
- "error",
78
- {
79
- "code": 120,
80
- "tabWidth": 2,
81
- "comments": 100,
82
- "ignoreTrailingComments": true,
83
- "ignoreUrls": true,
84
- "ignoreStrings": true,
85
- "ignoreTemplateLiterals": true,
86
- "ignoreRegExpLiterals": true
87
- }
88
- ],
89
- "max-lines": [
90
- "error",
91
- {
92
- "max": 350,
93
- "skipBlankLines": true,
94
- "skipComments": true
95
- }
96
- ],
97
- "complexity": [
98
- "error",
99
- {
100
- "max": 20
101
- }
102
- ],
103
- "prefer-arrow-callback": [
104
- "error",
105
- {
106
- "allowNamedFunctions": false,
107
- "allowUnboundThis": true
108
- }
109
- ],
110
- "arrow-parens": [
111
- 2,
112
- "as-needed"
113
- ],
114
- "dot-notation": [
115
- "error",
116
- {
117
- "allowKeywords": true
118
- }
119
- ],
120
- "require-atomic-updates": "error",
121
- "no-regex-spaces": "error",
122
- "no-template-curly-in-string": "error",
123
- "no-unreachable": "error",
124
- "no-return-await": "error",
125
- "no-return-assign": "error",
126
- "no-unused-expressions": "error",
127
- "no-useless-return": "error",
128
- "no-throw-literal": "error",
129
- "handle-callback-err": "error",
130
- "key-spacing": [
131
- "error",
132
- {
133
- "beforeColon": false,
134
- "afterColon": true,
135
- "mode": "strict"
136
- }
137
- ],
138
- "linebreak-style": [
139
- "error",
140
- "unix"
141
- ],
142
- "no-trailing-spaces": "error",
143
- "no-whitespace-before-property": "error",
144
- "no-unneeded-ternary": "error",
145
- "prefer-object-spread": "error",
146
- "array-callback-return": "error",
147
- "arrow-body-style": [
148
- "error",
149
- "as-needed"
150
- ],
151
- "semi": [
152
- "error",
153
- "always"
154
- ]
155
- },
156
- "globals": {
157
- "logs": true
158
- }
159
- }
1
+ {
2
+ "extends": [
3
+ "standard",
4
+ "plugin:node/recommended",
5
+ "plugin:promise/recommended",
6
+ "plugin:import/errors",
7
+ "plugin:import/warnings"
8
+ ],
9
+ "plugins": [
10
+ "standard"
11
+ ],
12
+ "rules": {
13
+ "camelcase": [
14
+ 0
15
+ ],
16
+ "indent": [
17
+ 2,
18
+ 2,
19
+ {
20
+ "SwitchCase": 2
21
+ }
22
+ ],
23
+ "object-curly-spacing": [
24
+ "error",
25
+ "always"
26
+ ],
27
+ "array-bracket-spacing": [
28
+ "error",
29
+ "always"
30
+ ],
31
+ "eqeqeq": [
32
+ "error",
33
+ "always"
34
+ ],
35
+ "no-else-return": [
36
+ "error",
37
+ {
38
+ "allowElseIf": false
39
+ }
40
+ ],
41
+ "no-multi-spaces": "error",
42
+ "no-new-wrappers": "error",
43
+ "no-redeclare": "error",
44
+ "no-undef-init": "error",
45
+ "no-unused-vars": "error",
46
+ "no-use-before-define": [
47
+ "error",
48
+ {
49
+ "functions": false
50
+ }
51
+ ],
52
+ "comma-dangle": [
53
+ "error",
54
+ "never"
55
+ ],
56
+ "comma-spacing": [
57
+ "error",
58
+ {
59
+ "before": false,
60
+ "after": true
61
+ }
62
+ ],
63
+ "comma-style": [
64
+ "error",
65
+ "last"
66
+ ],
67
+ "no-implied-eval": "error",
68
+ "no-mixed-operators": "off",
69
+ "node/exports-style": [
70
+ "error",
71
+ "module.exports"
72
+ ],
73
+ "node/no-unpublished-require": "off",
74
+ "promise/no-callback-in-promise": "off",
75
+ "promise/no-nesting": "off",
76
+ "max-len": [
77
+ "error",
78
+ {
79
+ "code": 120,
80
+ "tabWidth": 2,
81
+ "comments": 100,
82
+ "ignoreTrailingComments": true,
83
+ "ignoreUrls": true,
84
+ "ignoreStrings": true,
85
+ "ignoreTemplateLiterals": true,
86
+ "ignoreRegExpLiterals": true
87
+ }
88
+ ],
89
+ "max-lines": [
90
+ "error",
91
+ {
92
+ "max": 350,
93
+ "skipBlankLines": true,
94
+ "skipComments": true
95
+ }
96
+ ],
97
+ "complexity": [
98
+ "error",
99
+ {
100
+ "max": 20
101
+ }
102
+ ],
103
+ "prefer-arrow-callback": [
104
+ "error",
105
+ {
106
+ "allowNamedFunctions": false,
107
+ "allowUnboundThis": true
108
+ }
109
+ ],
110
+ "arrow-parens": [
111
+ 2,
112
+ "as-needed"
113
+ ],
114
+ "dot-notation": [
115
+ "error",
116
+ {
117
+ "allowKeywords": true
118
+ }
119
+ ],
120
+ "require-atomic-updates": "error",
121
+ "no-regex-spaces": "error",
122
+ "no-template-curly-in-string": "error",
123
+ "no-unreachable": "error",
124
+ "no-return-await": "error",
125
+ "no-return-assign": "error",
126
+ "no-unused-expressions": "error",
127
+ "no-useless-return": "error",
128
+ "no-throw-literal": "error",
129
+ "handle-callback-err": "error",
130
+ "key-spacing": [
131
+ "error",
132
+ {
133
+ "beforeColon": false,
134
+ "afterColon": true,
135
+ "mode": "strict"
136
+ }
137
+ ],
138
+ "linebreak-style": [
139
+ "error",
140
+ "unix"
141
+ ],
142
+ "no-trailing-spaces": "error",
143
+ "no-whitespace-before-property": "error",
144
+ "no-unneeded-ternary": "error",
145
+ "prefer-object-spread": "error",
146
+ "array-callback-return": "error",
147
+ "arrow-body-style": [
148
+ "error",
149
+ "as-needed"
150
+ ],
151
+ "semi": [
152
+ "error",
153
+ "always"
154
+ ]
155
+ },
156
+ "globals": {
157
+ "logs": true
158
+ }
159
+ }
package/.prettierrc CHANGED
@@ -1,5 +1,5 @@
1
- {
2
- "singleQuote": true,
3
- "tabWidth": 2,
4
- "trailingComma": "all"
1
+ {
2
+ "singleQuote": true,
3
+ "tabWidth": 2,
4
+ "trailingComma": "all"
5
5
  }
@@ -1,2 +1 @@
1
1
  export { default as HEADERS } from './headers';
2
- export { default as TRACE_SERVER } from './servers';
@@ -3,9 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.TRACE_SERVER = exports.HEADERS = void 0;
6
+ exports.HEADERS = void 0;
7
7
  var headers_1 = require("./headers");
8
8
  Object.defineProperty(exports, "HEADERS", { enumerable: true, get: function () { return __importDefault(headers_1).default; } });
9
- var servers_1 = require("./servers");
10
- Object.defineProperty(exports, "TRACE_SERVER", { enumerable: true, get: function () { return __importDefault(servers_1).default; } });
11
9
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/constants/index.ts"],"names":[],"mappings":";;;;;;AAAA,qCAA+C;AAAtC,mHAAA,OAAO,OAAW;AAC3B,qCAAmD;AAA1C,wHAAA,OAAO,OAAgB"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/constants/index.ts"],"names":[],"mappings":";;;;;;AAAA,qCAA+C;AAAtC,mHAAA,OAAO,OAAW"}
@@ -1,5 +1,7 @@
1
1
  import { NextFunction, Request, Response } from 'express';
2
2
  declare class Body {
3
+ private propertiesToArray;
4
+ private getValue;
3
5
  body: (req: Request, _: Response, next: NextFunction) => void;
4
6
  }
5
7
  export default Body;
@@ -6,20 +6,30 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const api_1 = __importDefault(require("@opentelemetry/api"));
7
7
  class Body {
8
8
  constructor() {
9
+ this.propertiesToArray = (obj) => {
10
+ const isObject = (val) => val && typeof val === "object" && !Array.isArray(val);
11
+ const addDelimiter = (a, b) => (a ? `${a}.${b}` : b);
12
+ const paths = (obj, head = "") => {
13
+ return Object.entries(obj).reduce((product, [key, value]) => {
14
+ const fullPath = addDelimiter(head, key);
15
+ return isObject(value)
16
+ ? product.concat(paths(value, fullPath))
17
+ : product.concat(fullPath);
18
+ }, []);
19
+ };
20
+ return paths(obj);
21
+ };
22
+ this.getValue = (path, obj) => path.split(".").reduce((acc, c) => acc && acc[c], obj);
9
23
  this.body = (req, _, next) => {
24
+ var _a, _b;
10
25
  let span = api_1.default.trace.getSpan(api_1.default.context.active());
26
+ const url = ((_b = (_a = req === null || req === void 0 ? void 0 : req.originalUrl) === null || _a === void 0 ? void 0 : _a.split("?")) === null || _b === void 0 ? void 0 : _b.shift()) || "";
11
27
  if (!span)
12
- span = api_1.default.trace.getTracer("edirect/trace", "1").startSpan(req.originalUrl.split('?').shift());
13
- const bodyString = JSON.stringify(req.body);
14
- const charsLength = bodyString.length;
15
- const chunks = [];
16
- for (let i = 0; i < charsLength; i += 1000) {
17
- chunks.push(bodyString.substring(i, i + 1000));
28
+ span = api_1.default.trace.getTracer("edirect/trace", "1").startSpan(url);
29
+ const attrs = this.propertiesToArray(req.body);
30
+ for (let x = 0; x < attrs.length; x++) {
31
+ span.setAttribute(`http@body.${attrs[x]}`, this.getValue(attrs[x], req.body));
18
32
  }
19
- span.setAttribute('http_request_body', chunks);
20
- if (req.query)
21
- span.setAttribute('http_request_url_query', new URLSearchParams(req.query).toString());
22
- span.setAttribute('http_request_url_full', req.originalUrl);
23
33
  next();
24
34
  };
25
35
  }
@@ -1 +1 @@
1
- {"version":3,"file":"body.js","sourceRoot":"","sources":["../../src/middlewares/body.ts"],"names":[],"mappings":";;;;;AACA,6DAA+C;AAE/C,MAAM,IAAI;IAAV;QAOS,SAAI,GAAG,CAAC,GAAY,EAAE,CAAW,EAAE,IAAkB,EAAQ,EAAE;YACpE,IAAI,IAAI,GAAG,aAAa,CAAC,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;YACvE,IAAI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AAK,CAAC,GAAG,CAAC,0CAAE,KAAK,EAAE,KAAI,EAAE,CAAC;YACxD,IAAI,CAAC,IAAI;gBACP,IAAI,GAAG,aAAa,CAAC,KAAK,CAAC,SAAS,CAAC,eAAe,EAAE,GAAG,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;YAE5E,MAAM,KAAK,GAAG,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YAC/C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;gBACrC,IAAI,CAAC,YAAY,CAAC,aAAa,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;aAC/E;YAED,IAAI,EAAE,CAAC;QACT,CAAC,CAAC;IACJ,CAAC;CAAA;AAED,kBAAe,IAAI,CAAC"}
@@ -1,10 +1,14 @@
1
1
  declare class APM {
2
- serviceName: string;
3
- serverUrl: string;
4
- traceServer: string;
5
- constructor(serviceName?: string, serverUrl?: string, traceServer?: string);
6
- private startElastic;
7
- private startOtlp;
2
+ private serverUrl;
3
+ private scope;
4
+ private environment;
5
+ private cluster;
6
+ private tenant;
7
+ private service;
8
+ private version;
9
+ private owner;
10
+ private serviceName;
11
+ constructor(serverUrl?: string, scope?: string, environment?: string, cluster?: string, tenant?: string, service?: string, version?: string, owner?: string, serviceName?: string);
8
12
  startTrace(): void;
9
13
  }
10
14
  export default APM;