@nivinjoseph/n-strument 1.0.4 → 2.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.
@@ -0,0 +1,328 @@
1
+ import eslint from "@eslint/js";
2
+ import tsEslint from "typescript-eslint";
3
+ import { defineConfig } from "eslint/config";
4
+ import importPlugin from "eslint-plugin-import";
5
+ import tsParser from "@typescript-eslint/parser";
6
+
7
+ import stylistic from "@stylistic/eslint-plugin";
8
+
9
+ export default defineConfig(
10
+ eslint.configs.recommended,
11
+ tsEslint.configs.recommended,
12
+ importPlugin.flatConfigs.recommended,
13
+ {
14
+ ignores: ["dist/**", "node_modules/**", "**/*.js", "**/*.map", "**/*.d.ts"]
15
+ },
16
+ {
17
+ files: ["**/*.ts"],
18
+ extends: [importPlugin.flatConfigs.recommended, importPlugin.flatConfigs.typescript],
19
+ languageOptions: {
20
+ parser: tsParser,
21
+ ecmaVersion: "latest",
22
+ sourceType: "module"
23
+ },
24
+ settings: {
25
+ "import/parsers": {
26
+ "@typescript-eslint/parser": [".ts", ".tsx"]
27
+ },
28
+ "import/resolver": {
29
+ node: {
30
+ extensions: [".js", ".jsx", ".ts", ".tsx"]
31
+ },
32
+ typescript: {
33
+ project: "./tsconfig.json"
34
+ }
35
+ },
36
+ },
37
+ rules: {
38
+ "import/no-extraneous-dependencies": ["error"]
39
+ }
40
+ },
41
+ {
42
+ files: ["**/*.ts"],
43
+ languageOptions: {
44
+ parserOptions: {
45
+ tsconfigRootDir: import.meta.dirname,
46
+ projectService: true
47
+ }
48
+ },
49
+ plugins: {
50
+ "@stylistic/ts": stylistic
51
+ },
52
+ "rules": {
53
+ "import/extensions": [
54
+ "error",
55
+ "always",
56
+ {
57
+ "ts": "never",
58
+ "js": "always"
59
+ }
60
+ ],
61
+ "quotes": [
62
+ "error",
63
+ "double",
64
+ {
65
+ "allowTemplateLiterals": true
66
+ }
67
+ ],
68
+ "no-eval": "error",
69
+ "no-void": "error",
70
+ "no-with": "error",
71
+ "@typescript-eslint/adjacent-overload-signatures": "error",
72
+ "@typescript-eslint/array-type": [
73
+ "error",
74
+ {
75
+ "default": "generic",
76
+ "readonly": "generic"
77
+ }
78
+ ],
79
+ "@typescript-eslint/await-thenable": "error",
80
+ "@typescript-eslint/ban-ts-comment": [
81
+ "error",
82
+ {
83
+ "ts-expect-error": "allow-with-description",
84
+ "ts-ignore": "allow-with-description",
85
+ "ts-nocheck": true,
86
+ "ts-check": true
87
+ }
88
+ ],
89
+ "@typescript-eslint/ban-tslint-comment": "error",
90
+ "@typescript-eslint/no-empty-object-type": "error",
91
+ "@typescript-eslint/no-unsafe-function-type": "error",
92
+ "@typescript-eslint/no-wrapper-object-types": "off",
93
+ "@typescript-eslint/no-restricted-types": [
94
+ "error",
95
+ {
96
+ "types": {
97
+ "String": {
98
+ "message": "Use string instead",
99
+ "fixWith": "string"
100
+ },
101
+ "Boolean": {
102
+ "message": "Use boolean instead",
103
+ "fixWith": "boolean"
104
+ },
105
+ "Number": {
106
+ "message": "Use number instead",
107
+ "fixWith": "number"
108
+ },
109
+ "Symbol": {
110
+ "message": "Use symbol instead",
111
+ "fixWith": "symbol"
112
+ }
113
+ }
114
+ }
115
+ ],
116
+ "brace-style": "off",
117
+ "@stylistic/ts/brace-style": [
118
+ "error",
119
+ "allman",
120
+ {
121
+ "allowSingleLine": true
122
+ }
123
+ ],
124
+ "@typescript-eslint/class-literal-property-style": [
125
+ "off",
126
+ "getters"
127
+ ],
128
+ "comma-dangle": "off",
129
+ "@stylistic/ts/comma-dangle": [
130
+ "error",
131
+ {
132
+ "arrays": "never",
133
+ "objects": "only-multiline",
134
+ "imports": "never",
135
+ "exports": "never",
136
+ "functions": "never",
137
+ "enums": "only-multiline"
138
+ }
139
+ ],
140
+ "default-param-last": "off",
141
+ "@typescript-eslint/default-param-last": "error",
142
+ "@typescript-eslint/explicit-function-return-type": [
143
+ "error",
144
+ {
145
+ "allowExpressions": true
146
+ }
147
+ ],
148
+ "@typescript-eslint/explicit-member-accessibility": "error",
149
+ "@typescript-eslint/explicit-module-boundary-types": "error",
150
+ "func-call-spacing": "off",
151
+ "@stylistic/ts/function-call-spacing": [
152
+ "error",
153
+ "never"
154
+ ],
155
+ "@stylistic/ts/member-delimiter-style": [
156
+ "error",
157
+ {
158
+ "multiline": {
159
+ "delimiter": "semi",
160
+ "requireLast": true
161
+ },
162
+ "singleline": {
163
+ "delimiter": "semi",
164
+ "requireLast": true
165
+ },
166
+ "multilineDetection": "brackets"
167
+ }
168
+ ],
169
+ "@typescript-eslint/member-ordering": [
170
+ "error",
171
+ {
172
+ "default": [
173
+ // Index signature
174
+ "signature",
175
+ // Fields
176
+ "private-static-field",
177
+ "protected-static-field",
178
+ "public-static-field",
179
+ "private-instance-field",
180
+ "protected-instance-field",
181
+ "public-instance-field",
182
+ // Getters / Setters
183
+ [
184
+ "private-static-get",
185
+ "private-static-set"
186
+ ],
187
+ [
188
+ "protected-static-get",
189
+ "protected-static-set"
190
+ ],
191
+ [
192
+ "public-static-get",
193
+ "public-static-set"
194
+ ],
195
+ [
196
+ "private-instance-get",
197
+ "private-instance-set"
198
+ ],
199
+ [
200
+ "protected-instance-get",
201
+ "protected-instance-set"
202
+ ],
203
+ [
204
+ "public-instance-get",
205
+ "public-instance-set"
206
+ ],
207
+ // Constructors
208
+ "public-constructor",
209
+ "protected-constructor",
210
+ "private-constructor",
211
+ // Methods
212
+ "public-static-method",
213
+ "protected-static-method",
214
+ "private-static-method",
215
+ "public-instance-method",
216
+ "protected-instance-method",
217
+ "private-instance-method"
218
+ ]
219
+ }
220
+ ],
221
+ "@typescript-eslint/method-signature-style": [
222
+ "error",
223
+ "method"
224
+ ],
225
+ "@typescript-eslint/naming-convention": [
226
+ "error",
227
+ {
228
+ "selector": "memberLike",
229
+ "modifiers": [
230
+ "private"
231
+ ],
232
+ "format": [
233
+ "camelCase"
234
+ ],
235
+ "leadingUnderscore": "require"
236
+ }
237
+ ],
238
+ "@typescript-eslint/no-confusing-non-null-assertion": "error",
239
+ "@typescript-eslint/no-confusing-void-expression": [
240
+ "error",
241
+ {
242
+ "ignoreArrowShorthand": true
243
+ }
244
+ ],
245
+ "no-dupe-class-members": "off",
246
+ "@typescript-eslint/no-dupe-class-members": "error",
247
+ "@typescript-eslint/no-duplicate-enum-values": "error",
248
+ "no-duplicate-imports": "error",
249
+ "no-empty-function": "off",
250
+ "@typescript-eslint/no-empty-function": [
251
+ "error",
252
+ {
253
+ "allow": [
254
+ "private-constructors"
255
+ ]
256
+ }
257
+ ],
258
+ "@typescript-eslint/no-explicit-any": "off",
259
+ "@typescript-eslint/no-extra-non-null-assertion": "error",
260
+ "no-extra-parens": "off",
261
+ "@stylistic/ts/no-extra-parens": [
262
+ "error",
263
+ "all",
264
+ {
265
+ "nestedBinaryExpressions": false
266
+ }
267
+ ],
268
+ "no-extra-semi": "off",
269
+ "@stylistic/ts/no-extra-semi": "error",
270
+ "@typescript-eslint/no-floating-promises": "error",
271
+ "@typescript-eslint/no-for-in-array": "error",
272
+ "no-implied-eval": "off",
273
+ "@typescript-eslint/no-implied-eval": "error",
274
+ "no-invalid-this": "off",
275
+ "@typescript-eslint/no-invalid-this": "error",
276
+ "@typescript-eslint/no-invalid-void-type": "error",
277
+ "no-loop-func": "off",
278
+ "@typescript-eslint/no-loop-func": "error",
279
+ "no-loss-of-precision": "off",
280
+ "@typescript-eslint/no-loss-of-precision": "error",
281
+ "@typescript-eslint/no-meaningless-void-operator": "error",
282
+ "@typescript-eslint/no-misused-new": "error",
283
+ "@typescript-eslint/no-misused-promises": "error",
284
+ "@typescript-eslint/no-non-null-asserted-nullish-coalescing": "error",
285
+ "@typescript-eslint/no-non-null-asserted-optional-chain": "error",
286
+ "@typescript-eslint/no-non-null-assertion": "off",
287
+ "no-redeclare": "off",
288
+ "@typescript-eslint/no-redeclare": "error",
289
+ "@typescript-eslint/no-this-alias": "error",
290
+ "no-throw-literal": "error",
291
+ "@typescript-eslint/no-unnecessary-condition": [
292
+ "error",
293
+ {
294
+ "allowConstantLoopConditions": true
295
+ }
296
+ ],
297
+ "@typescript-eslint/no-unnecessary-type-assertion": "error",
298
+ "@typescript-eslint/no-unnecessary-type-constraint": "error",
299
+ "@typescript-eslint/no-unsafe-call": "error",
300
+ "@typescript-eslint/no-unsafe-return": "error",
301
+ "no-unused-expressions": "off",
302
+ "@typescript-eslint/no-unused-expressions": "error",
303
+ "no-unused-vars": "off",
304
+ "@typescript-eslint/no-unused-vars": "off",
305
+ "no-use-before-define": "off",
306
+ "@typescript-eslint/no-use-before-define": "off",
307
+ "no-useless-constructor": "off",
308
+ "@typescript-eslint/no-useless-constructor": "error",
309
+ "@typescript-eslint/no-useless-empty-export": "error",
310
+ "@typescript-eslint/no-var-requires": "off",
311
+ "@typescript-eslint/parameter-properties": "error",
312
+ "@typescript-eslint/prefer-enum-initializers": "error",
313
+ "@typescript-eslint/prefer-includes": "error",
314
+ "@typescript-eslint/prefer-literal-enum-member": "error",
315
+ "@typescript-eslint/prefer-readonly": "error",
316
+ "@typescript-eslint/prefer-reduce-type-parameter": "error",
317
+ "@typescript-eslint/prefer-string-starts-ends-with": "error",
318
+ "@typescript-eslint/prefer-ts-expect-error": "error",
319
+ "@typescript-eslint/require-array-sort-compare": "error",
320
+ "no-return-await": "off",
321
+ "@typescript-eslint/return-await": "error",
322
+ "semi": "off",
323
+ "@stylistic/ts/semi": "error",
324
+ "@typescript-eslint/unbound-method": "error",
325
+ "@typescript-eslint/no-require-imports": "error"
326
+ }
327
+ }
328
+ );
package/package.json CHANGED
@@ -1,21 +1,20 @@
1
1
  {
2
2
  "name": "@nivinjoseph/n-strument",
3
- "version": "1.0.4",
3
+ "version": "2.0.1",
4
4
  "description": "Instrumentation helper library",
5
- "main": "./dist/index.js",
5
+ "type": "module",
6
+ "exports": "./dist/index.js",
6
7
  "types": "./dist/index.d.ts",
8
+ "packageManager": "yarn@4.16.0",
7
9
  "scripts": {
8
10
  "ts-compile": "tsc -p .",
9
11
  "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
+ "ts-build": "yarn ts-compile && yarn ts-lint",
13
+ "ts-build-dist": "yarn ts-build && tsc -p ./dist",
12
14
  "clean-src": "find ./src -name '*.js' -delete -o -name '*.map' -delete",
13
15
  "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"
16
+ "test": "yarn ts-build && node --test --enable-source-maps './test/**.test.js' || true",
17
+ "publish-package": "yarn ts-build-dist && git add . && git commit -m 'preparing to publish new version' && yarn version patch && git add . && git commit -m 'new version' && git push && npm publish --access=public"
19
18
  },
20
19
  "repository": {
21
20
  "type": "git",
@@ -33,23 +32,34 @@
33
32
  },
34
33
  "homepage": "https://github.com/nivinjoseph/n-strument#readme",
35
34
  "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"
35
+ "@eslint/js": "10.0.1",
36
+ "@stylistic/eslint-plugin": "5.10.0",
37
+ "@types/node": "24.10",
38
+ "@typescript-eslint/parser": "8.58.2",
39
+ "eslint": "10.2.1",
40
+ "eslint-import-resolver-typescript": "4.4.4",
41
+ "eslint-plugin-import": "2.32.0",
42
+ "typescript": "6.0.3",
43
+ "typescript-eslint": "8.58.2"
44
44
  },
45
45
  "dependencies": {
46
- "@nivinjoseph/n-config": "^1.0.38",
47
- "@nivinjoseph/n-util": "^1.0.81",
48
- "@opentelemetry/api": "^1.9.0",
49
- "@opentelemetry/auto-instrumentations-node": "^0.50.0",
50
- "@opentelemetry/id-generator-aws-xray": "^1.2.2",
51
- "@opentelemetry/propagator-aws-xray": "^1.26.0",
52
- "@opentelemetry/sdk-node": "^0.53.0",
53
- "tslib": "^2.4.0"
46
+ "@nivinjoseph/n-config": "2.0.5",
47
+ "@nivinjoseph/n-util": "4.0.2",
48
+ "@opentelemetry/api": "1.9.1",
49
+ "@opentelemetry/auto-instrumentations-node": "0.76.0",
50
+ "@opentelemetry/exporter-trace-otlp-http": "0.218.0",
51
+ "@opentelemetry/id-generator-aws-xray": "2.1.0",
52
+ "@opentelemetry/instrumentation": "0.218.0",
53
+ "@opentelemetry/instrumentation-koa": "0.66.0",
54
+ "@opentelemetry/propagator-aws-xray": "2.2.0",
55
+ "@opentelemetry/resources": "2.7.1",
56
+ "@opentelemetry/sdk-node": "0.218.0",
57
+ "@opentelemetry/sdk-trace-base": "2.7.1",
58
+ "@opentelemetry/sdk-trace-node": "2.7.1",
59
+ "@opentelemetry/semantic-conventions": "1.41.1",
60
+ "tslib": "2.8.1"
61
+ },
62
+ "engines": {
63
+ "node": ">=24.10"
54
64
  }
55
65
  }
package/src/index.ts CHANGED
@@ -1,13 +1,18 @@
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";
1
+ import { getNodeAutoInstrumentations, InstrumentationConfigMap } from "@opentelemetry/auto-instrumentations-node";
5
2
  import { registerInstrumentations } from "@opentelemetry/instrumentation";
3
+ import { diag, DiagConsoleLogger, DiagLogLevel } from "@opentelemetry/api";
4
+ import { KoaLayerType } from "@opentelemetry/instrumentation-koa";
5
+ import { defaultResource, resourceFromAttributes } from "@opentelemetry/resources";
6
+ import
7
+ {
8
+ // SemanticResourceAttributes,
9
+ ATTR_SERVICE_NAME, ATTR_SERVICE_VERSION
10
+ } from "@opentelemetry/semantic-conventions";
11
+ import { NodeTracerProvider, ParentBasedSampler, TraceIdRatioBasedSampler } from "@opentelemetry/sdk-trace-node";
6
12
  import { BatchSpanProcessor, TracerConfig } from "@opentelemetry/sdk-trace-base";
7
- import { diag, DiagConsoleLogger, DiagLogLevel } from '@opentelemetry/api';
13
+
8
14
  import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
9
15
  import { ConfigurationManager } from "@nivinjoseph/n-config";
10
- import { KoaLayerType } from "@opentelemetry/instrumentation-koa";
11
16
  import { TypeHelper } from "@nivinjoseph/n-util";
12
17
  import { AWSXRayPropagator } from "@opentelemetry/propagator-aws-xray";
13
18
  import { AWSXRayIdGenerator } from "@opentelemetry/id-generator-aws-xray";
@@ -15,39 +20,89 @@ import { AWSXRayIdGenerator } from "@opentelemetry/id-generator-aws-xray";
15
20
  // For troubleshooting, set the log level to DiagLogLevel.DEBUG
16
21
  diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.INFO);
17
22
 
23
+ // Every key in the InstrumentationConfigMap is listed explicitly with an `enabled` flag. The
24
+ // config object is an *override map*, not an allow-list: any instrumentation left out (or set to
25
+ // `undefined`) runs at its own default, which for this library version means ~39 of 40 are on.
26
+ // Listing all of them makes the enabled set unambiguous and makes a future library version that
27
+ // adds a new instrumentation conspicuous by its absence here, instead of silently turning on.
28
+ //
29
+ // Enabled: http, grpc, pg, knex, redis, ioredis, koa, amqplib, kafkajs, socket.io, aws-sdk,
30
+ // aws-lambda. Everything else off.
31
+ // Entries are kept in the library's own InstrumentationMap order for easy auditing on upgrade.
32
+ // `Required<...>` strips the optional modifier off every key, so this literal must list every
33
+ // instrumentation the library knows about. When an OTel upgrade adds a new one, the missing key
34
+ // becomes a compile error here — forcing a deliberate enabled/disabled decision rather than a
35
+ // silent default-on.
36
+ const instrumentationConfig: Required<InstrumentationConfigMap> = {
37
+ "@opentelemetry/instrumentation-amqplib": { enabled: true },
38
+ "@opentelemetry/instrumentation-aws-lambda": { enabled: true },
39
+ "@opentelemetry/instrumentation-aws-sdk": { enabled: true },
40
+ "@opentelemetry/instrumentation-bunyan": { enabled: false },
41
+ "@opentelemetry/instrumentation-cassandra-driver": { enabled: false },
42
+ "@opentelemetry/instrumentation-connect": { enabled: false },
43
+ "@opentelemetry/instrumentation-cucumber": { enabled: false },
44
+ "@opentelemetry/instrumentation-dataloader": { enabled: false },
45
+ "@opentelemetry/instrumentation-dns": { enabled: false },
46
+ "@opentelemetry/instrumentation-express": { enabled: false },
47
+ "@opentelemetry/instrumentation-fs": { enabled: false },
48
+ "@opentelemetry/instrumentation-generic-pool": { enabled: false },
49
+ "@opentelemetry/instrumentation-graphql": { enabled: false },
50
+ "@opentelemetry/instrumentation-grpc": { enabled: true },
51
+ "@opentelemetry/instrumentation-hapi": { enabled: false },
52
+ "@opentelemetry/instrumentation-http": { enabled: true },
53
+ "@opentelemetry/instrumentation-ioredis": { enabled: true },
54
+ "@opentelemetry/instrumentation-kafkajs": { enabled: true },
55
+ "@opentelemetry/instrumentation-knex": { enabled: true },
56
+ "@opentelemetry/instrumentation-koa": { enabled: true, ignoreLayersType: [KoaLayerType.MIDDLEWARE] },
57
+ "@opentelemetry/instrumentation-lru-memoizer": { enabled: false },
58
+ "@opentelemetry/instrumentation-memcached": { enabled: false },
59
+ "@opentelemetry/instrumentation-mongodb": { enabled: false },
60
+ "@opentelemetry/instrumentation-mongoose": { enabled: false },
61
+ "@opentelemetry/instrumentation-mysql2": { enabled: false },
62
+ "@opentelemetry/instrumentation-mysql": { enabled: false },
63
+ "@opentelemetry/instrumentation-nestjs-core": { enabled: false },
64
+ "@opentelemetry/instrumentation-net": { enabled: false },
65
+ "@opentelemetry/instrumentation-openai": { enabled: false },
66
+ "@opentelemetry/instrumentation-oracledb": { enabled: false },
67
+ "@opentelemetry/instrumentation-pg": { enabled: true },
68
+ "@opentelemetry/instrumentation-pino": { enabled: false },
69
+ "@opentelemetry/instrumentation-redis": { enabled: true },
70
+ "@opentelemetry/instrumentation-restify": { enabled: false },
71
+ "@opentelemetry/instrumentation-router": { enabled: false },
72
+ "@opentelemetry/instrumentation-runtime-node": { enabled: false },
73
+ "@opentelemetry/instrumentation-socket.io": { enabled: true },
74
+ "@opentelemetry/instrumentation-tedious": { enabled: false },
75
+ "@opentelemetry/instrumentation-undici": { enabled: false },
76
+ "@opentelemetry/instrumentation-winston": { enabled: false }
77
+ };
78
+
18
79
  // This registers all instrumentation packages
19
80
  registerInstrumentations({
20
81
  instrumentations: [
21
- getNodeAutoInstrumentations({
22
- "@opentelemetry/instrumentation-http": undefined,
23
- "@opentelemetry/instrumentation-grpc": undefined,
24
- "@opentelemetry/instrumentation-redis": undefined,
25
- "@opentelemetry/instrumentation-ioredis": undefined,
26
- "@opentelemetry/instrumentation-pg": undefined,
27
- "@opentelemetry/instrumentation-knex": undefined,
28
- "@opentelemetry/instrumentation-koa": { ignoreLayersType: [KoaLayerType.MIDDLEWARE] },
29
- "@opentelemetry/instrumentation-aws-sdk": undefined,
30
- "@opentelemetry/instrumentation-aws-lambda": undefined
31
- })
82
+ getNodeAutoInstrumentations(instrumentationConfig)
32
83
  ]
33
84
  });
34
85
 
35
- const env = ConfigurationManager.getConfig<string>("env");
86
+
87
+ const env = ConfigurationManager.requireStringConfig("env");
36
88
  const isDev = env === "dev";
37
89
 
38
90
  const resource =
39
- Resource.default().merge(
40
- new Resource({
41
- [SemanticResourceAttributes.SERVICE_NAME]: ConfigurationManager.getConfig("package.name"),
42
- [SemanticResourceAttributes.SERVICE_VERSION]: ConfigurationManager.getConfig("package.version"),
43
- [SemanticResourceAttributes.DEPLOYMENT_ENVIRONMENT]: env
91
+ defaultResource().merge(
92
+ resourceFromAttributes({
93
+ // [SemanticResourceAttributes.SERVICE_NAME]: ConfigurationManager.getConfig("package.name"),
94
+ // [SemanticResourceAttributes.SERVICE_VERSION]: ConfigurationManager.getConfig("package.version"),
95
+ // [SemanticResourceAttributes.DEPLOYMENT_ENVIRONMENT]: env
96
+
97
+ [ATTR_SERVICE_NAME]: ConfigurationManager.getConfig("package_name") ?? ConfigurationManager.getConfig("package.name") ?? undefined,
98
+ [ATTR_SERVICE_VERSION]: ConfigurationManager.getConfig("package.version") ?? undefined
44
99
  })
45
100
  );
46
101
 
47
102
  const samplingRate = TypeHelper.parseNumber(ConfigurationManager.getConfig("otelTraceSamplingRate")) ?? 1;
48
103
 
49
104
  const enableXrayTracing = TypeHelper.parseBoolean(ConfigurationManager.getConfig("enableXrayTracing")) ?? false;
50
-
105
+
51
106
  const tracerConfig: TracerConfig = {
52
107
  resource: resource,
53
108
  sampler: new ParentBasedSampler({ root: new TraceIdRatioBasedSampler(samplingRate) })
@@ -59,8 +114,7 @@ if (enableXrayTracing)
59
114
  let traceHost = ConfigurationManager.getConfig<string | null>("otelTraceHost");
60
115
  if (traceHost == null || typeof traceHost !== "string" || traceHost.isEmptyOrWhiteSpace())
61
116
  traceHost = isDev ? "localhost" : "0.0.0.0";
62
-
63
- const provider = new NodeTracerProvider();
117
+
64
118
  // const exporter = new ConsoleSpanExporter();
65
119
  const exporter = new OTLPTraceExporter({
66
120
  // optional - default url is http://localhost:4318/v1/traces
@@ -70,6 +124,40 @@ const exporter = new OTLPTraceExporter({
70
124
  headers: {}
71
125
  });
72
126
  const processor = new BatchSpanProcessor(exporter);
73
- provider.addSpanProcessor(processor);
74
127
 
75
- provider.register(enableXrayTracing ? { propagator: new AWSXRayPropagator() } : undefined);
128
+ // Span processors are now supplied via the constructor (addSpanProcessor was removed in the OTel SDK 2.x line).
129
+ const provider = new NodeTracerProvider({
130
+ ...tracerConfig,
131
+ spanProcessors: [processor]
132
+ });
133
+
134
+ provider.register(enableXrayTracing ? { propagator: new AWSXRayPropagator() } : undefined);
135
+
136
+ // The BatchSpanProcessor buffers finished spans in memory and only flushes periodically (or once a
137
+ // batch fills); its flush timer is unref'd, so the process can exit with spans still buffered, and
138
+ // the Node processor registers no exit handlers of its own. Rather than have this library grab
139
+ // SIGTERM/SIGINT — which would race with, and process.exit() out of, the host service's own
140
+ // graceful-shutdown sequence — we export a drain function for the host to invoke as part of its
141
+ // shutdown. provider.shutdown() flushes the buffer and shuts the exporter down.
142
+ let shutdownPromise: Promise<void> | null = null;
143
+
144
+ /**
145
+ * Flushes any buffered spans and shuts the tracer exporter down.
146
+ *
147
+ * Call this from your service's graceful-shutdown sequence — after it has stopped accepting work
148
+ * and finished in-flight requests, so their spans are captured — to avoid losing the spans the
149
+ * BatchSpanProcessor is still holding in memory. Safe to call more than once: repeat calls return
150
+ * the same in-flight (or completed) shutdown.
151
+ */
152
+ export function shutdownTracing(): Promise<void>
153
+ {
154
+ if (shutdownPromise != null)
155
+ return shutdownPromise;
156
+
157
+ shutdownPromise = provider.shutdown().catch((e: unknown) =>
158
+ {
159
+ diag.error("Error shutting down tracer provider", e);
160
+ });
161
+
162
+ return shutdownPromise;
163
+ }
@@ -0,0 +1,12 @@
1
+ import "../src/index.js";
2
+ import assert from "node:assert";
3
+ import test, { describe } from "node:test";
4
+
5
+
6
+ await describe("dummy", async () =>
7
+ {
8
+ await test("dummy", () =>
9
+ {
10
+ assert.ok(true);
11
+ });
12
+ });
package/tsconfig.json CHANGED
@@ -1,7 +1,13 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "module": "commonjs",
4
- "target": "es2015",
3
+ "module": "NodeNext",
4
+ "target": "ES2023",
5
+ "lib": [
6
+ "ES2023"
7
+ ],
8
+ "types": [
9
+ "node"
10
+ ],
5
11
  "strict": true,
6
12
  "strictNullChecks": true,
7
13
  "strictFunctionTypes": true,
@@ -12,8 +18,6 @@
12
18
  "noFallthroughCasesInSwitch": true,
13
19
  "noEmitOnError": true,
14
20
  "sourceMap": true,
15
- "experimentalDecorators": true,
16
- "emitDecoratorMetadata": true,
17
21
  "removeComments": false,
18
22
  "forceConsistentCasingInFileNames": true,
19
23
  "incremental": false,
@@ -21,6 +25,8 @@
21
25
  "importHelpers": true,
22
26
  "noEmitHelpers": true,
23
27
  "noImplicitOverride": true,
24
- "pretty": true
28
+ "pretty": true,
29
+ "esModuleInterop": true,
30
+ "allowSyntheticDefaultImports": true
25
31
  }
26
32
  }
package/.eslintignore DELETED
@@ -1,2 +0,0 @@
1
- node_modules
2
- dist