@nivinjoseph/n-strument 1.0.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.
- package/.editorconfig +14 -0
- package/.eslintignore +2 -0
- package/.eslintrc +335 -0
- package/.vscode/launch.json +56 -0
- package/.vscode/tasks.json +12 -0
- package/LICENSE +21 -0
- package/README.md +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +55 -0
- package/dist/index.js.map +1 -0
- package/dist/tsconfig.json +11 -0
- package/package.json +53 -0
- package/src/index.ts +62 -0
- package/tsconfig.json +26 -0
package/.editorconfig
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# EditorConfig is awesome: http://EditorConfig.org
|
|
2
|
+
|
|
3
|
+
# top-most EditorConfig file
|
|
4
|
+
root = true
|
|
5
|
+
|
|
6
|
+
# Unix-style newlines with a newline ending every file
|
|
7
|
+
[*]
|
|
8
|
+
end_of_line = lf
|
|
9
|
+
# insert_final_newline = true
|
|
10
|
+
charset = utf-8
|
|
11
|
+
indent_style = space
|
|
12
|
+
indent_size = 4
|
|
13
|
+
tab_width = 4
|
|
14
|
+
trim_trailing_whitespace = false
|
package/.eslintignore
ADDED
package/.eslintrc
ADDED
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
{
|
|
2
|
+
"root": true,
|
|
3
|
+
"parser": "@typescript-eslint/parser",
|
|
4
|
+
"plugins": [
|
|
5
|
+
"@typescript-eslint"
|
|
6
|
+
],
|
|
7
|
+
"extends": [
|
|
8
|
+
"eslint:recommended",
|
|
9
|
+
"plugin:@typescript-eslint/eslint-recommended",
|
|
10
|
+
"plugin:@typescript-eslint/recommended"
|
|
11
|
+
],
|
|
12
|
+
"parserOptions": {
|
|
13
|
+
"project": "tsconfig.json"
|
|
14
|
+
},
|
|
15
|
+
"rules": {
|
|
16
|
+
"no-eval": "error",
|
|
17
|
+
"no-void": "error",
|
|
18
|
+
"no-with": "error",
|
|
19
|
+
"@typescript-eslint/adjacent-overload-signatures": "error",
|
|
20
|
+
"@typescript-eslint/array-type": [
|
|
21
|
+
"error",
|
|
22
|
+
{
|
|
23
|
+
"default": "generic",
|
|
24
|
+
"readonly": "generic"
|
|
25
|
+
}
|
|
26
|
+
],
|
|
27
|
+
"@typescript-eslint/await-thenable": "error",
|
|
28
|
+
"@typescript-eslint/ban-ts-comment": [
|
|
29
|
+
"error",
|
|
30
|
+
{
|
|
31
|
+
"ts-expect-error": "allow-with-description",
|
|
32
|
+
"ts-ignore": "allow-with-description",
|
|
33
|
+
"ts-nocheck": true,
|
|
34
|
+
"ts-check": true
|
|
35
|
+
}
|
|
36
|
+
],
|
|
37
|
+
"@typescript-eslint/ban-tslint-comment": "error",
|
|
38
|
+
"@typescript-eslint/ban-types": [
|
|
39
|
+
"error",
|
|
40
|
+
{
|
|
41
|
+
"extendDefaults": false,
|
|
42
|
+
"types": {
|
|
43
|
+
"String": {
|
|
44
|
+
"message": "Use string instead",
|
|
45
|
+
"fixWith": "string"
|
|
46
|
+
},
|
|
47
|
+
"Boolean": {
|
|
48
|
+
"message": "Use boolean instead",
|
|
49
|
+
"fixWith": "boolean"
|
|
50
|
+
},
|
|
51
|
+
"Number": {
|
|
52
|
+
"message": "Use number instead",
|
|
53
|
+
"fixWith": "number"
|
|
54
|
+
},
|
|
55
|
+
"Symbol": {
|
|
56
|
+
"message": "Use symbol instead",
|
|
57
|
+
"fixWith": "symbol"
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
],
|
|
62
|
+
"brace-style": "off",
|
|
63
|
+
"@typescript-eslint/brace-style": [
|
|
64
|
+
"error",
|
|
65
|
+
"allman",
|
|
66
|
+
{
|
|
67
|
+
"allowSingleLine": true
|
|
68
|
+
}
|
|
69
|
+
],
|
|
70
|
+
"@typescript-eslint/class-literal-property-style": [
|
|
71
|
+
"off",
|
|
72
|
+
"getters"
|
|
73
|
+
],
|
|
74
|
+
"comma-dangle": "off",
|
|
75
|
+
"@typescript-eslint/comma-dangle": [
|
|
76
|
+
"error",
|
|
77
|
+
"never"
|
|
78
|
+
],
|
|
79
|
+
"default-param-last": "off",
|
|
80
|
+
"@typescript-eslint/default-param-last": "error",
|
|
81
|
+
"@typescript-eslint/explicit-function-return-type": "error",
|
|
82
|
+
"@typescript-eslint/explicit-member-accessibility": "error",
|
|
83
|
+
"@typescript-eslint/explicit-module-boundary-types": "error",
|
|
84
|
+
"func-call-spacing": "off",
|
|
85
|
+
"@typescript-eslint/func-call-spacing": [
|
|
86
|
+
"error",
|
|
87
|
+
"never"
|
|
88
|
+
],
|
|
89
|
+
"@typescript-eslint/member-delimiter-style": [
|
|
90
|
+
"error",
|
|
91
|
+
{
|
|
92
|
+
"multiline": {
|
|
93
|
+
"delimiter": "semi",
|
|
94
|
+
"requireLast": true
|
|
95
|
+
},
|
|
96
|
+
"singleline": {
|
|
97
|
+
"delimiter": "semi",
|
|
98
|
+
"requireLast": true
|
|
99
|
+
},
|
|
100
|
+
"multilineDetection": "brackets"
|
|
101
|
+
}
|
|
102
|
+
],
|
|
103
|
+
"@typescript-eslint/member-ordering": [
|
|
104
|
+
"error",
|
|
105
|
+
{
|
|
106
|
+
"default": [
|
|
107
|
+
// Index signature
|
|
108
|
+
"signature",
|
|
109
|
+
// Fields
|
|
110
|
+
"private-static-field",
|
|
111
|
+
"protected-static-field",
|
|
112
|
+
"public-static-field",
|
|
113
|
+
// "private-decorated-field",
|
|
114
|
+
// "protected-decorated-field",
|
|
115
|
+
// "public-decorated-field",
|
|
116
|
+
"private-instance-field",
|
|
117
|
+
"protected-instance-field",
|
|
118
|
+
"public-instance-field",
|
|
119
|
+
// "public-abstract-field",
|
|
120
|
+
// "protected-abstract-field",
|
|
121
|
+
// "private-abstract-field",
|
|
122
|
+
// "private-field",
|
|
123
|
+
// "protected-field",
|
|
124
|
+
// "public-field",
|
|
125
|
+
// "static-field",
|
|
126
|
+
// "instance-field",
|
|
127
|
+
// "abstract-field",
|
|
128
|
+
// "decorated-field",
|
|
129
|
+
// "field",
|
|
130
|
+
// Getters
|
|
131
|
+
// "public-static-get",
|
|
132
|
+
// "protected-static-get",
|
|
133
|
+
// "private-static-get",
|
|
134
|
+
// "public-decorated-get",
|
|
135
|
+
// "protected-decorated-get",
|
|
136
|
+
// "private-decorated-get",
|
|
137
|
+
// "public-instance-get",
|
|
138
|
+
// "protected-instance-get",
|
|
139
|
+
// "private-instance-get",
|
|
140
|
+
// "public-abstract-get",
|
|
141
|
+
// "protected-abstract-get",
|
|
142
|
+
// "private-abstract-get",
|
|
143
|
+
// "public-get",
|
|
144
|
+
// "protected-get",
|
|
145
|
+
// "private-get",
|
|
146
|
+
// "static-get",
|
|
147
|
+
// "instance-get",
|
|
148
|
+
// "abstract-get",
|
|
149
|
+
// "decorated-get",
|
|
150
|
+
// "get",
|
|
151
|
+
// Setters
|
|
152
|
+
// "public-static-set",
|
|
153
|
+
// "protected-static-set",
|
|
154
|
+
// "private-static-set",
|
|
155
|
+
// "public-decorated-set",
|
|
156
|
+
// "protected-decorated-set",
|
|
157
|
+
// "private-decorated-set",
|
|
158
|
+
// "public-instance-set",
|
|
159
|
+
// "protected-instance-set",
|
|
160
|
+
// "private-instance-set",
|
|
161
|
+
// "public-abstract-set",
|
|
162
|
+
// "protected-abstract-set",
|
|
163
|
+
// "private-abstract-set",
|
|
164
|
+
// "public-set",
|
|
165
|
+
// "protected-set",
|
|
166
|
+
// "private-set",
|
|
167
|
+
// "static-set",
|
|
168
|
+
// "instance-set",
|
|
169
|
+
// "abstract-set",
|
|
170
|
+
// "decorated-set",
|
|
171
|
+
// "set",
|
|
172
|
+
// [
|
|
173
|
+
// "get",
|
|
174
|
+
// "set"
|
|
175
|
+
// ],
|
|
176
|
+
[
|
|
177
|
+
"private-static-get",
|
|
178
|
+
"private-static-set"
|
|
179
|
+
],
|
|
180
|
+
[
|
|
181
|
+
"protected-static-get",
|
|
182
|
+
"protected-static-set"
|
|
183
|
+
],
|
|
184
|
+
[
|
|
185
|
+
"public-static-get",
|
|
186
|
+
"public-static-set"
|
|
187
|
+
],
|
|
188
|
+
[
|
|
189
|
+
"private-instance-get",
|
|
190
|
+
"private-instance-set"
|
|
191
|
+
],
|
|
192
|
+
[
|
|
193
|
+
"protected-instance-get",
|
|
194
|
+
"protected-instance-set"
|
|
195
|
+
],
|
|
196
|
+
[
|
|
197
|
+
"public-instance-get",
|
|
198
|
+
"public-instance-set"
|
|
199
|
+
],
|
|
200
|
+
// Constructors
|
|
201
|
+
"public-constructor",
|
|
202
|
+
"protected-constructor",
|
|
203
|
+
"private-constructor",
|
|
204
|
+
// "constructor",
|
|
205
|
+
// Methods
|
|
206
|
+
"public-static-method",
|
|
207
|
+
"protected-static-method",
|
|
208
|
+
"private-static-method",
|
|
209
|
+
// "public-decorated-method",
|
|
210
|
+
// "protected-decorated-method",
|
|
211
|
+
// "private-decorated-method",
|
|
212
|
+
"public-instance-method",
|
|
213
|
+
"protected-instance-method",
|
|
214
|
+
"private-instance-method",
|
|
215
|
+
// "public-abstract-method",
|
|
216
|
+
// "protected-abstract-method",
|
|
217
|
+
// "private-abstract-method",
|
|
218
|
+
// "public-method",
|
|
219
|
+
// "protected-method",
|
|
220
|
+
// "private-method",
|
|
221
|
+
// "static-method",
|
|
222
|
+
// "instance-method",
|
|
223
|
+
// "abstract-method",
|
|
224
|
+
// "decorated-method",
|
|
225
|
+
// "method"
|
|
226
|
+
]
|
|
227
|
+
}
|
|
228
|
+
],
|
|
229
|
+
"@typescript-eslint/method-signature-style": [
|
|
230
|
+
"error",
|
|
231
|
+
"method"
|
|
232
|
+
],
|
|
233
|
+
"@typescript-eslint/naming-convention": [
|
|
234
|
+
"error",
|
|
235
|
+
{
|
|
236
|
+
"selector": "memberLike",
|
|
237
|
+
"modifiers": [
|
|
238
|
+
"private"
|
|
239
|
+
],
|
|
240
|
+
"format": [
|
|
241
|
+
"camelCase"
|
|
242
|
+
],
|
|
243
|
+
"leadingUnderscore": "require"
|
|
244
|
+
}
|
|
245
|
+
],
|
|
246
|
+
"@typescript-eslint/no-confusing-non-null-assertion": "error",
|
|
247
|
+
"@typescript-eslint/no-confusing-void-expression": [
|
|
248
|
+
"error",
|
|
249
|
+
{
|
|
250
|
+
"ignoreArrowShorthand": true
|
|
251
|
+
}
|
|
252
|
+
],
|
|
253
|
+
"no-dupe-class-members": "off",
|
|
254
|
+
"@typescript-eslint/no-dupe-class-members": "error",
|
|
255
|
+
"@typescript-eslint/no-duplicate-enum-values": "error",
|
|
256
|
+
"no-duplicate-imports": "off",
|
|
257
|
+
"@typescript-eslint/no-duplicate-imports": "error",
|
|
258
|
+
"no-empty-function": "off",
|
|
259
|
+
"@typescript-eslint/no-empty-function": [
|
|
260
|
+
"error",
|
|
261
|
+
{
|
|
262
|
+
"allow": [
|
|
263
|
+
"private-constructors"
|
|
264
|
+
]
|
|
265
|
+
}
|
|
266
|
+
],
|
|
267
|
+
"@typescript-eslint/no-explicit-any": "off",
|
|
268
|
+
"@typescript-eslint/no-extra-non-null-assertion": "error",
|
|
269
|
+
"no-extra-parens": "off",
|
|
270
|
+
"@typescript-eslint/no-extra-parens": [
|
|
271
|
+
"error",
|
|
272
|
+
"all",
|
|
273
|
+
{
|
|
274
|
+
"nestedBinaryExpressions": false
|
|
275
|
+
}
|
|
276
|
+
],
|
|
277
|
+
"no-extra-semi": "off",
|
|
278
|
+
"@typescript-eslint/no-extra-semi": "error",
|
|
279
|
+
"@typescript-eslint/no-floating-promises": "error",
|
|
280
|
+
"@typescript-eslint/no-for-in-array": "error",
|
|
281
|
+
"no-implied-eval": "off",
|
|
282
|
+
"@typescript-eslint/no-implied-eval": "error",
|
|
283
|
+
"no-invalid-this": "off",
|
|
284
|
+
"@typescript-eslint/no-invalid-this": "error",
|
|
285
|
+
"@typescript-eslint/no-invalid-void-type": "error",
|
|
286
|
+
"no-loop-func": "off",
|
|
287
|
+
"@typescript-eslint/no-loop-func": "error",
|
|
288
|
+
"no-loss-of-precision": "off",
|
|
289
|
+
"@typescript-eslint/no-loss-of-precision": "error",
|
|
290
|
+
"@typescript-eslint/no-meaningless-void-operator": "error",
|
|
291
|
+
"@typescript-eslint/no-misused-new": "error",
|
|
292
|
+
"@typescript-eslint/no-misused-promises": "error",
|
|
293
|
+
"@typescript-eslint/no-non-null-asserted-nullish-coalescing": "error",
|
|
294
|
+
"@typescript-eslint/no-non-null-asserted-optional-chain": "error",
|
|
295
|
+
"@typescript-eslint/no-non-null-assertion": "off",
|
|
296
|
+
"no-redeclare": "off",
|
|
297
|
+
"@typescript-eslint/no-redeclare": "error",
|
|
298
|
+
"@typescript-eslint/no-this-alias": "error",
|
|
299
|
+
"@typescript-eslint/no-throw-literal": "error",
|
|
300
|
+
"@typescript-eslint/no-unnecessary-condition": [
|
|
301
|
+
"error",
|
|
302
|
+
{
|
|
303
|
+
"allowConstantLoopConditions": true
|
|
304
|
+
}
|
|
305
|
+
],
|
|
306
|
+
"@typescript-eslint/no-unnecessary-type-assertion": "error",
|
|
307
|
+
"@typescript-eslint/no-unnecessary-type-constraint": "error",
|
|
308
|
+
"@typescript-eslint/no-unsafe-call": "error",
|
|
309
|
+
"@typescript-eslint/no-unsafe-return": "error",
|
|
310
|
+
"no-unused-expressions": "off",
|
|
311
|
+
"@typescript-eslint/no-unused-expressions": "error",
|
|
312
|
+
"no-unused-vars": "off",
|
|
313
|
+
"@typescript-eslint/no-unused-vars": "off",
|
|
314
|
+
"no-use-before-define": "off",
|
|
315
|
+
"@typescript-eslint/no-use-before-define": "off",
|
|
316
|
+
"no-useless-constructor": "off",
|
|
317
|
+
"@typescript-eslint/no-useless-constructor": "error",
|
|
318
|
+
"@typescript-eslint/no-useless-empty-export": "error",
|
|
319
|
+
"@typescript-eslint/no-var-requires": "off",
|
|
320
|
+
"@typescript-eslint/parameter-properties": "error",
|
|
321
|
+
"@typescript-eslint/prefer-enum-initializers": "error",
|
|
322
|
+
"@typescript-eslint/prefer-includes": "error",
|
|
323
|
+
"@typescript-eslint/prefer-literal-enum-member": "error",
|
|
324
|
+
"@typescript-eslint/prefer-readonly": "error",
|
|
325
|
+
"@typescript-eslint/prefer-reduce-type-parameter": "error",
|
|
326
|
+
"@typescript-eslint/prefer-string-starts-ends-with": "error",
|
|
327
|
+
"@typescript-eslint/prefer-ts-expect-error": "error",
|
|
328
|
+
"@typescript-eslint/require-array-sort-compare": "error",
|
|
329
|
+
"no-return-await": "off",
|
|
330
|
+
"@typescript-eslint/return-await": "error",
|
|
331
|
+
"semi": "off",
|
|
332
|
+
"@typescript-eslint/semi": "error",
|
|
333
|
+
"@typescript-eslint/unbound-method": "error"
|
|
334
|
+
}
|
|
335
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
// Use IntelliSense to learn about possible Node.js debug attributes.
|
|
3
|
+
// Hover to view descriptions of existing attributes.
|
|
4
|
+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
|
5
|
+
"version": "0.2.0",
|
|
6
|
+
"configurations": [
|
|
7
|
+
{
|
|
8
|
+
"type": "node",
|
|
9
|
+
"request": "launch",
|
|
10
|
+
"name": "Debug Mocha tests",
|
|
11
|
+
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
|
|
12
|
+
"stopOnEntry": false,
|
|
13
|
+
"args": [
|
|
14
|
+
"-t",
|
|
15
|
+
"10000",
|
|
16
|
+
"--reporter",
|
|
17
|
+
"spec",
|
|
18
|
+
"--ui",
|
|
19
|
+
"tdd",
|
|
20
|
+
"--require",
|
|
21
|
+
"ts-node/register",
|
|
22
|
+
"./test/**/*.test.js"
|
|
23
|
+
],
|
|
24
|
+
"cwd": "${workspaceRoot}",
|
|
25
|
+
"preLaunchTask": "ts-build",
|
|
26
|
+
"runtimeArgs": [
|
|
27
|
+
"--nolazy"
|
|
28
|
+
],
|
|
29
|
+
"console": "internalConsole",
|
|
30
|
+
"sourceMaps": true
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"type": "node",
|
|
34
|
+
"request": "attach",
|
|
35
|
+
"name": "Debug running App",
|
|
36
|
+
"address": "localhost",
|
|
37
|
+
"port": 5858,
|
|
38
|
+
"sourceMaps": true,
|
|
39
|
+
"restart": true
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"type": "node",
|
|
43
|
+
"request": "launch",
|
|
44
|
+
"name": "Debug launch app",
|
|
45
|
+
"program": "${workspaceRoot}/src/index.js",
|
|
46
|
+
"stopOnEntry": false,
|
|
47
|
+
"cwd": "${workspaceRoot}",
|
|
48
|
+
"preLaunchTask": "ts-build",
|
|
49
|
+
"runtimeArgs": [
|
|
50
|
+
"--nolazy"
|
|
51
|
+
],
|
|
52
|
+
"console": "internalConsole",
|
|
53
|
+
"sourceMaps": true
|
|
54
|
+
}
|
|
55
|
+
]
|
|
56
|
+
}
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Nivin Joseph
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const auto_instrumentations_node_1 = require("@opentelemetry/auto-instrumentations-node");
|
|
5
|
+
const resources_1 = require("@opentelemetry/resources");
|
|
6
|
+
const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
|
|
7
|
+
const sdk_trace_node_1 = require("@opentelemetry/sdk-trace-node");
|
|
8
|
+
const instrumentation_1 = require("@opentelemetry/instrumentation");
|
|
9
|
+
const sdk_trace_base_1 = require("@opentelemetry/sdk-trace-base");
|
|
10
|
+
const api_1 = require("@opentelemetry/api");
|
|
11
|
+
const exporter_trace_otlp_http_1 = require("@opentelemetry/exporter-trace-otlp-http");
|
|
12
|
+
const n_config_1 = require("@nivinjoseph/n-config");
|
|
13
|
+
const instrumentation_koa_1 = require("@opentelemetry/instrumentation-koa");
|
|
14
|
+
const n_util_1 = require("@nivinjoseph/n-util");
|
|
15
|
+
// For troubleshooting, set the log level to DiagLogLevel.DEBUG
|
|
16
|
+
api_1.diag.setLogger(new api_1.DiagConsoleLogger(), api_1.DiagLogLevel.INFO);
|
|
17
|
+
// This registers all instrumentation packages
|
|
18
|
+
(0, instrumentation_1.registerInstrumentations)({
|
|
19
|
+
instrumentations: [
|
|
20
|
+
(0, auto_instrumentations_node_1.getNodeAutoInstrumentations)({
|
|
21
|
+
"@opentelemetry/instrumentation-http": undefined,
|
|
22
|
+
"@opentelemetry/instrumentation-grpc": undefined,
|
|
23
|
+
"@opentelemetry/instrumentation-redis": undefined,
|
|
24
|
+
"@opentelemetry/instrumentation-ioredis": undefined,
|
|
25
|
+
"@opentelemetry/instrumentation-pg": undefined,
|
|
26
|
+
"@opentelemetry/instrumentation-knex": undefined,
|
|
27
|
+
"@opentelemetry/instrumentation-koa": { ignoreLayersType: [instrumentation_koa_1.KoaLayerType.MIDDLEWARE] },
|
|
28
|
+
"@opentelemetry/instrumentation-aws-sdk": undefined,
|
|
29
|
+
"@opentelemetry/instrumentation-aws-lambda": undefined
|
|
30
|
+
})
|
|
31
|
+
]
|
|
32
|
+
});
|
|
33
|
+
const env = n_config_1.ConfigurationManager.getConfig("env");
|
|
34
|
+
const isDev = env === "dev";
|
|
35
|
+
const resource = resources_1.Resource.default().merge(new resources_1.Resource({
|
|
36
|
+
[semantic_conventions_1.SemanticResourceAttributes.SERVICE_NAME]: n_config_1.ConfigurationManager.getConfig("package.name"),
|
|
37
|
+
[semantic_conventions_1.SemanticResourceAttributes.SERVICE_VERSION]: n_config_1.ConfigurationManager.getConfig("package.version"),
|
|
38
|
+
[semantic_conventions_1.SemanticResourceAttributes.DEPLOYMENT_ENVIRONMENT]: env
|
|
39
|
+
}));
|
|
40
|
+
const samplingRate = (_a = n_util_1.TypeHelper.parseNumber(n_config_1.ConfigurationManager.getConfig("otelTraceSamplingRate"))) !== null && _a !== void 0 ? _a : 1;
|
|
41
|
+
const provider = new sdk_trace_node_1.NodeTracerProvider({
|
|
42
|
+
resource: resource,
|
|
43
|
+
sampler: new sdk_trace_node_1.ParentBasedSampler({ root: new sdk_trace_node_1.TraceIdRatioBasedSampler(samplingRate) })
|
|
44
|
+
});
|
|
45
|
+
// const exporter = new ConsoleSpanExporter();
|
|
46
|
+
const exporter = new exporter_trace_otlp_http_1.OTLPTraceExporter({
|
|
47
|
+
// optional - default url is http://localhost:4318/v1/traces
|
|
48
|
+
url: `http://${isDev ? "localhost" : "0.0.0.0"}:4318/v1/traces`,
|
|
49
|
+
// optional - collection of custom headers to be sent with each request, empty by default
|
|
50
|
+
headers: {}
|
|
51
|
+
});
|
|
52
|
+
const processor = new sdk_trace_base_1.BatchSpanProcessor(exporter);
|
|
53
|
+
provider.addSpanProcessor(processor);
|
|
54
|
+
provider.register();
|
|
55
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,0FAAwF;AACxF,wDAAoD;AACpD,8EAAiF;AACjF,kEAAiH;AACjH,oEAA0E;AAC1E,kEAAmE;AACnE,4CAA2E;AAC3E,sFAA4E;AAC5E,oDAA6D;AAC7D,4EAAkE;AAClE,gDAAiD;AAEjD,+DAA+D;AAC/D,UAAI,CAAC,SAAS,CAAC,IAAI,uBAAiB,EAAE,EAAE,kBAAY,CAAC,IAAI,CAAC,CAAC;AAE3D,8CAA8C;AAC9C,IAAA,0CAAwB,EAAC;IACrB,gBAAgB,EAAE;QACd,IAAA,wDAA2B,EAAC;YACxB,qCAAqC,EAAE,SAAS;YAChD,qCAAqC,EAAE,SAAS;YAChD,sCAAsC,EAAE,SAAS;YACjD,wCAAwC,EAAE,SAAS;YACnD,mCAAmC,EAAE,SAAS;YAC9C,qCAAqC,EAAE,SAAS;YAChD,oCAAoC,EAAE,EAAE,gBAAgB,EAAE,CAAC,kCAAY,CAAC,UAAU,CAAC,EAAE;YACrF,wCAAwC,EAAE,SAAS;YACnD,2CAA2C,EAAE,SAAS;SACzD,CAAC;KACL;CACJ,CAAC,CAAC;AAEH,MAAM,GAAG,GAAG,+BAAoB,CAAC,SAAS,CAAS,KAAK,CAAC,CAAC;AAC1D,MAAM,KAAK,GAAG,GAAG,KAAK,KAAK,CAAC;AAE5B,MAAM,QAAQ,GACV,oBAAQ,CAAC,OAAO,EAAE,CAAC,KAAK,CACpB,IAAI,oBAAQ,CAAC;IACT,CAAC,iDAA0B,CAAC,YAAY,CAAC,EAAE,+BAAoB,CAAC,SAAS,CAAC,cAAc,CAAC;IACzF,CAAC,iDAA0B,CAAC,eAAe,CAAC,EAAE,+BAAoB,CAAC,SAAS,CAAC,iBAAiB,CAAC;IAC/F,CAAC,iDAA0B,CAAC,sBAAsB,CAAC,EAAE,GAAG;CAC3D,CAAC,CACL,CAAC;AAEN,MAAM,YAAY,GAAG,MAAA,mBAAU,CAAC,WAAW,CAAC,+BAAoB,CAAC,SAAS,CAAC,uBAAuB,CAAC,CAAC,mCAAI,CAAC,CAAC;AAE1G,MAAM,QAAQ,GAAG,IAAI,mCAAkB,CAAC;IACpC,QAAQ,EAAE,QAAQ;IAClB,OAAO,EAAE,IAAI,mCAAkB,CAAC,EAAE,IAAI,EAAE,IAAI,yCAAwB,CAAC,YAAY,CAAC,EAAE,CAAC;CACxF,CAAC,CAAC;AACH,8CAA8C;AAC9C,MAAM,QAAQ,GAAG,IAAI,4CAAiB,CAAC;IACnC,4DAA4D;IAE5D,GAAG,EAAE,UAAU,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,iBAAiB;IAC/D,yFAAyF;IACzF,OAAO,EAAE,EAAE;CACd,CAAC,CAAC;AACH,MAAM,SAAS,GAAG,IAAI,mCAAkB,CAAC,QAAQ,CAAC,CAAC;AACnD,QAAQ,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC;AAErC,QAAQ,CAAC,QAAQ,EAAE,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nivinjoseph/n-strument",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "Instrumentation helper library",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"ts-compile": "tsc -p .",
|
|
9
|
+
"ts-lint": "eslint . --ext .ts",
|
|
10
|
+
"ts-build": "npm run ts-compile && npm run ts-lint",
|
|
11
|
+
"ts-build-dist": "npm run ts-build && tsc -p ./dist",
|
|
12
|
+
"clean-src": "find ./src -name '*.js' -delete -o -name '*.map' -delete",
|
|
13
|
+
"clean-test": "find ./test -name '*.js' -delete -o -name '*.map' -delete",
|
|
14
|
+
"pretest": "npm run ts-build",
|
|
15
|
+
"test": "mocha --timeout 100000 --reporter spec --ui tdd --require ts-node/register './test/**/*.test.js' || true",
|
|
16
|
+
"pretest-ci": "npm run pretest",
|
|
17
|
+
"test-ci": "mocha --reporter spec --ui tdd --require ts-node/register './test/**/*.test.js'",
|
|
18
|
+
"publish-package": "npm run ts-build-dist && git add . && git commit -m 'preparing to publish new version' && npm version patch && git push && npm publish --access=public"
|
|
19
|
+
},
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/nivinjoseph/n-strument.git"
|
|
23
|
+
},
|
|
24
|
+
"keywords": [
|
|
25
|
+
"instrumentation",
|
|
26
|
+
"observability",
|
|
27
|
+
"otel"
|
|
28
|
+
],
|
|
29
|
+
"author": "NiviN",
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"bugs": {
|
|
32
|
+
"url": "https://github.com/nivinjoseph/n-strument/issues"
|
|
33
|
+
},
|
|
34
|
+
"homepage": "https://github.com/nivinjoseph/n-strument#readme",
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@types/mocha": "^9.1.1",
|
|
37
|
+
"@types/node": "^18.11.18",
|
|
38
|
+
"@typescript-eslint/eslint-plugin": "^5.25.0",
|
|
39
|
+
"@typescript-eslint/parser": "^5.25.0",
|
|
40
|
+
"eslint": "^8.15.0",
|
|
41
|
+
"mocha": "^10.0.0",
|
|
42
|
+
"ts-node": "^10.7.0",
|
|
43
|
+
"typescript": "^4.6.4"
|
|
44
|
+
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"@nivinjoseph/n-config": "^1.0.36",
|
|
47
|
+
"@nivinjoseph/n-util": "^1.0.81",
|
|
48
|
+
"@opentelemetry/api": "^1.3.0",
|
|
49
|
+
"@opentelemetry/auto-instrumentations-node": "^0.36.0",
|
|
50
|
+
"@opentelemetry/sdk-node": "^0.34.0",
|
|
51
|
+
"tslib": "^2.4.0"
|
|
52
|
+
}
|
|
53
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { getNodeAutoInstrumentations } from "@opentelemetry/auto-instrumentations-node";
|
|
2
|
+
import { Resource } from "@opentelemetry/resources";
|
|
3
|
+
import { SemanticResourceAttributes } from "@opentelemetry/semantic-conventions";
|
|
4
|
+
import { NodeTracerProvider, ParentBasedSampler, TraceIdRatioBasedSampler } from "@opentelemetry/sdk-trace-node";
|
|
5
|
+
import { registerInstrumentations } from "@opentelemetry/instrumentation";
|
|
6
|
+
import { BatchSpanProcessor } from "@opentelemetry/sdk-trace-base";
|
|
7
|
+
import { diag, DiagConsoleLogger, DiagLogLevel } from '@opentelemetry/api';
|
|
8
|
+
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
|
|
9
|
+
import { ConfigurationManager } from "@nivinjoseph/n-config";
|
|
10
|
+
import { KoaLayerType } from "@opentelemetry/instrumentation-koa";
|
|
11
|
+
import { TypeHelper } from "@nivinjoseph/n-util";
|
|
12
|
+
|
|
13
|
+
// For troubleshooting, set the log level to DiagLogLevel.DEBUG
|
|
14
|
+
diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.INFO);
|
|
15
|
+
|
|
16
|
+
// This registers all instrumentation packages
|
|
17
|
+
registerInstrumentations({
|
|
18
|
+
instrumentations: [
|
|
19
|
+
getNodeAutoInstrumentations({
|
|
20
|
+
"@opentelemetry/instrumentation-http": undefined,
|
|
21
|
+
"@opentelemetry/instrumentation-grpc": undefined,
|
|
22
|
+
"@opentelemetry/instrumentation-redis": undefined,
|
|
23
|
+
"@opentelemetry/instrumentation-ioredis": undefined,
|
|
24
|
+
"@opentelemetry/instrumentation-pg": undefined,
|
|
25
|
+
"@opentelemetry/instrumentation-knex": undefined,
|
|
26
|
+
"@opentelemetry/instrumentation-koa": { ignoreLayersType: [KoaLayerType.MIDDLEWARE] },
|
|
27
|
+
"@opentelemetry/instrumentation-aws-sdk": undefined,
|
|
28
|
+
"@opentelemetry/instrumentation-aws-lambda": undefined
|
|
29
|
+
})
|
|
30
|
+
]
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const env = ConfigurationManager.getConfig<string>("env");
|
|
34
|
+
const isDev = env === "dev";
|
|
35
|
+
|
|
36
|
+
const resource =
|
|
37
|
+
Resource.default().merge(
|
|
38
|
+
new Resource({
|
|
39
|
+
[SemanticResourceAttributes.SERVICE_NAME]: ConfigurationManager.getConfig("package.name"),
|
|
40
|
+
[SemanticResourceAttributes.SERVICE_VERSION]: ConfigurationManager.getConfig("package.version"),
|
|
41
|
+
[SemanticResourceAttributes.DEPLOYMENT_ENVIRONMENT]: env
|
|
42
|
+
})
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
const samplingRate = TypeHelper.parseNumber(ConfigurationManager.getConfig("otelTraceSamplingRate")) ?? 1;
|
|
46
|
+
|
|
47
|
+
const provider = new NodeTracerProvider({
|
|
48
|
+
resource: resource,
|
|
49
|
+
sampler: new ParentBasedSampler({ root: new TraceIdRatioBasedSampler(samplingRate) })
|
|
50
|
+
});
|
|
51
|
+
// const exporter = new ConsoleSpanExporter();
|
|
52
|
+
const exporter = new OTLPTraceExporter({
|
|
53
|
+
// optional - default url is http://localhost:4318/v1/traces
|
|
54
|
+
|
|
55
|
+
url: `http://${isDev ? "localhost" : "0.0.0.0"}:4318/v1/traces`,
|
|
56
|
+
// optional - collection of custom headers to be sent with each request, empty by default
|
|
57
|
+
headers: {}
|
|
58
|
+
});
|
|
59
|
+
const processor = new BatchSpanProcessor(exporter);
|
|
60
|
+
provider.addSpanProcessor(processor);
|
|
61
|
+
|
|
62
|
+
provider.register();
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "commonjs",
|
|
4
|
+
"target": "es2015",
|
|
5
|
+
"strict": true,
|
|
6
|
+
"strictNullChecks": true,
|
|
7
|
+
"strictFunctionTypes": true,
|
|
8
|
+
"noImplicitThis": true,
|
|
9
|
+
"noImplicitReturns": true,
|
|
10
|
+
"noUnusedLocals": true,
|
|
11
|
+
"noUnusedParameters": true,
|
|
12
|
+
"noFallthroughCasesInSwitch": true,
|
|
13
|
+
"noEmitOnError": true,
|
|
14
|
+
"sourceMap": true,
|
|
15
|
+
"experimentalDecorators": true,
|
|
16
|
+
"emitDecoratorMetadata": true,
|
|
17
|
+
"removeComments": false,
|
|
18
|
+
"forceConsistentCasingInFileNames": true,
|
|
19
|
+
"incremental": false,
|
|
20
|
+
"skipLibCheck": true,
|
|
21
|
+
"importHelpers": true,
|
|
22
|
+
"noEmitHelpers": true,
|
|
23
|
+
"noImplicitOverride": true,
|
|
24
|
+
"pretty": true
|
|
25
|
+
}
|
|
26
|
+
}
|