@nivinjoseph/n-strument 1.0.3 → 1.0.5

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/.yarnrc.yml ADDED
@@ -0,0 +1,3 @@
1
+ nodeLinker: node-modules
2
+
3
+ yarnPath: .yarn/releases/yarn-4.4.1.cjs
package/dist/index.d.ts CHANGED
@@ -1 +1,2 @@
1
1
  export {};
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
package/dist/index.js CHANGED
@@ -1,64 +1,65 @@
1
- "use strict";
2
- var _a, _b;
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
- const propagator_aws_xray_1 = require("@opentelemetry/propagator-aws-xray");
16
- const id_generator_aws_xray_1 = require("@opentelemetry/id-generator-aws-xray");
1
+ import { getNodeAutoInstrumentations } from "@opentelemetry/auto-instrumentations-node";
2
+ import { Resource } from "@opentelemetry/resources";
3
+ import {
4
+ // SemanticResourceAttributes,
5
+ ATTR_SERVICE_NAME, ATTR_SERVICE_VERSION } from "@opentelemetry/semantic-conventions";
6
+ import { NodeTracerProvider, ParentBasedSampler, TraceIdRatioBasedSampler } from "@opentelemetry/sdk-trace-node";
7
+ import { registerInstrumentations } from "@opentelemetry/instrumentation";
8
+ import { BatchSpanProcessor } from "@opentelemetry/sdk-trace-base";
9
+ import { diag, DiagConsoleLogger, DiagLogLevel } from "@opentelemetry/api";
10
+ import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
11
+ import { ConfigurationManager } from "@nivinjoseph/n-config";
12
+ import { KoaLayerType } from "@opentelemetry/instrumentation-koa";
13
+ import { TypeHelper } from "@nivinjoseph/n-util";
14
+ import { AWSXRayPropagator } from "@opentelemetry/propagator-aws-xray";
15
+ import { AWSXRayIdGenerator } from "@opentelemetry/id-generator-aws-xray";
17
16
  // For troubleshooting, set the log level to DiagLogLevel.DEBUG
18
- api_1.diag.setLogger(new api_1.DiagConsoleLogger(), api_1.DiagLogLevel.INFO);
17
+ diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.INFO);
19
18
  // This registers all instrumentation packages
20
- (0, instrumentation_1.registerInstrumentations)({
19
+ registerInstrumentations({
21
20
  instrumentations: [
22
- (0, auto_instrumentations_node_1.getNodeAutoInstrumentations)({
21
+ getNodeAutoInstrumentations({
23
22
  "@opentelemetry/instrumentation-http": undefined,
24
23
  "@opentelemetry/instrumentation-grpc": undefined,
25
24
  "@opentelemetry/instrumentation-redis": undefined,
26
25
  "@opentelemetry/instrumentation-ioredis": undefined,
27
26
  "@opentelemetry/instrumentation-pg": undefined,
28
27
  "@opentelemetry/instrumentation-knex": undefined,
29
- "@opentelemetry/instrumentation-koa": { ignoreLayersType: [instrumentation_koa_1.KoaLayerType.MIDDLEWARE] },
28
+ "@opentelemetry/instrumentation-koa": { ignoreLayersType: [KoaLayerType.MIDDLEWARE] },
30
29
  "@opentelemetry/instrumentation-aws-sdk": undefined,
31
30
  "@opentelemetry/instrumentation-aws-lambda": undefined
32
31
  })
33
32
  ]
34
33
  });
35
- const env = n_config_1.ConfigurationManager.getConfig("env");
34
+ const env = ConfigurationManager.requireStringConfig("env");
36
35
  const isDev = env === "dev";
37
- const resource = resources_1.Resource.default().merge(new resources_1.Resource({
38
- [semantic_conventions_1.SemanticResourceAttributes.SERVICE_NAME]: n_config_1.ConfigurationManager.getConfig("package.name"),
39
- [semantic_conventions_1.SemanticResourceAttributes.SERVICE_VERSION]: n_config_1.ConfigurationManager.getConfig("package.version"),
40
- [semantic_conventions_1.SemanticResourceAttributes.DEPLOYMENT_ENVIRONMENT]: env
36
+ const resource = Resource.default().merge(new Resource({
37
+ // [SemanticResourceAttributes.SERVICE_NAME]: ConfigurationManager.getConfig("package.name"),
38
+ // [SemanticResourceAttributes.SERVICE_VERSION]: ConfigurationManager.getConfig("package.version"),
39
+ // [SemanticResourceAttributes.DEPLOYMENT_ENVIRONMENT]: env
40
+ [ATTR_SERVICE_NAME]: ConfigurationManager.getConfig("package_name") ?? ConfigurationManager.getConfig("package.name"),
41
+ [ATTR_SERVICE_VERSION]: ConfigurationManager.getConfig("package.version")
41
42
  }));
42
- const samplingRate = (_a = n_util_1.TypeHelper.parseNumber(n_config_1.ConfigurationManager.getConfig("otelTraceSamplingRate"))) !== null && _a !== void 0 ? _a : 1;
43
- const enableXrayTracing = (_b = n_util_1.TypeHelper.parseBoolean(n_config_1.ConfigurationManager.getConfig("enableXrayTracing"))) !== null && _b !== void 0 ? _b : false;
43
+ const samplingRate = TypeHelper.parseNumber(ConfigurationManager.getConfig("otelTraceSamplingRate")) ?? 1;
44
+ const enableXrayTracing = TypeHelper.parseBoolean(ConfigurationManager.getConfig("enableXrayTracing")) ?? false;
44
45
  const tracerConfig = {
45
46
  resource: resource,
46
- sampler: new sdk_trace_node_1.ParentBasedSampler({ root: new sdk_trace_node_1.TraceIdRatioBasedSampler(samplingRate) })
47
+ sampler: new ParentBasedSampler({ root: new TraceIdRatioBasedSampler(samplingRate) })
47
48
  };
48
49
  if (enableXrayTracing)
49
- tracerConfig.idGenerator = new id_generator_aws_xray_1.AWSXRayIdGenerator();
50
- let traceHost = n_config_1.ConfigurationManager.getConfig("otelTraceHost");
50
+ tracerConfig.idGenerator = new AWSXRayIdGenerator();
51
+ let traceHost = ConfigurationManager.getConfig("otelTraceHost");
51
52
  if (traceHost == null || typeof traceHost !== "string" || traceHost.isEmptyOrWhiteSpace())
52
53
  traceHost = isDev ? "localhost" : "0.0.0.0";
53
- const provider = new sdk_trace_node_1.NodeTracerProvider();
54
+ const provider = new NodeTracerProvider();
54
55
  // const exporter = new ConsoleSpanExporter();
55
- const exporter = new exporter_trace_otlp_http_1.OTLPTraceExporter({
56
+ const exporter = new OTLPTraceExporter({
56
57
  // optional - default url is http://localhost:4318/v1/traces
57
58
  url: `http://${traceHost}:4318/v1/traces`,
58
59
  // optional - collection of custom headers to be sent with each request, empty by default
59
60
  headers: {}
60
61
  });
61
- const processor = new sdk_trace_base_1.BatchSpanProcessor(exporter);
62
+ const processor = new BatchSpanProcessor(exporter);
62
63
  provider.addSpanProcessor(processor);
63
- provider.register(enableXrayTracing ? { propagator: new propagator_aws_xray_1.AWSXRayPropagator() } : undefined);
64
+ provider.register(enableXrayTracing ? { propagator: new AWSXRayPropagator() } : undefined);
64
65
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +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,kEAAiF;AACjF,4CAA2E;AAC3E,sFAA4E;AAC5E,oDAA6D;AAC7D,4EAAkE;AAClE,gDAAiD;AACjD,4EAAuE;AACvE,gFAA0E;AAE1E,+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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,CAAC"}
@@ -3,7 +3,8 @@
3
3
  "compilerOptions": {
4
4
  "outDir": ".",
5
5
  "declaration": true,
6
- "declarationDir": "."
6
+ "declarationDir": ".",
7
+ "declarationMap": true
7
8
  },
8
9
  "include": [
9
10
  "../src/**/*.ts"
package/package.json CHANGED
@@ -1,21 +1,20 @@
1
1
  {
2
2
  "name": "@nivinjoseph/n-strument",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
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.4.1",
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' && npm version patch && git push && npm publish --access=public"
19
18
  },
20
19
  "repository": {
21
20
  "type": "git",
@@ -33,23 +32,21 @@
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
+ "@types/node": "^20.10",
36
+ "@typescript-eslint/eslint-plugin": "^6.15.0",
37
+ "@typescript-eslint/parser": "^6.15.0",
38
+ "eslint": "^8.56.0",
39
+ "eslint-plugin-require-extensions": "^0.1.3",
40
+ "typescript": "5.3.3"
44
41
  },
45
42
  "dependencies": {
46
- "@nivinjoseph/n-config": "^1.0.38",
47
- "@nivinjoseph/n-util": "^1.0.81",
48
- "@opentelemetry/api": "^1.3.0",
49
- "@opentelemetry/auto-instrumentations-node": "^0.36.0",
50
- "@opentelemetry/id-generator-aws-xray": "^1.1.1",
51
- "@opentelemetry/propagator-aws-xray": "^1.1.1",
52
- "@opentelemetry/sdk-node": "^0.34.0",
53
- "tslib": "^2.4.0"
43
+ "@nivinjoseph/n-config": "^2.0.1",
44
+ "@nivinjoseph/n-util": "^2.0.1",
45
+ "@opentelemetry/api": "^1.9.0",
46
+ "@opentelemetry/auto-instrumentations-node": "^0.50.0",
47
+ "@opentelemetry/id-generator-aws-xray": "^1.2.2",
48
+ "@opentelemetry/propagator-aws-xray": "^1.26.0",
49
+ "@opentelemetry/sdk-node": "^0.53.0",
50
+ "tslib": "^2.7.0"
54
51
  }
55
52
  }
package/src/index.ts CHANGED
@@ -1,10 +1,14 @@
1
1
  import { getNodeAutoInstrumentations } from "@opentelemetry/auto-instrumentations-node";
2
2
  import { Resource } from "@opentelemetry/resources";
3
- import { SemanticResourceAttributes } from "@opentelemetry/semantic-conventions";
3
+ import
4
+ {
5
+ // SemanticResourceAttributes,
6
+ ATTR_SERVICE_NAME, ATTR_SERVICE_VERSION
7
+ } from "@opentelemetry/semantic-conventions";
4
8
  import { NodeTracerProvider, ParentBasedSampler, TraceIdRatioBasedSampler } from "@opentelemetry/sdk-trace-node";
5
9
  import { registerInstrumentations } from "@opentelemetry/instrumentation";
6
10
  import { BatchSpanProcessor, TracerConfig } from "@opentelemetry/sdk-trace-base";
7
- import { diag, DiagConsoleLogger, DiagLogLevel } from '@opentelemetry/api';
11
+ import { diag, DiagConsoleLogger, DiagLogLevel } from "@opentelemetry/api";
8
12
  import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
9
13
  import { ConfigurationManager } from "@nivinjoseph/n-config";
10
14
  import { KoaLayerType } from "@opentelemetry/instrumentation-koa";
@@ -32,22 +36,25 @@ registerInstrumentations({
32
36
  ]
33
37
  });
34
38
 
35
- const env = ConfigurationManager.getConfig<string>("env");
39
+ const env = ConfigurationManager.requireStringConfig("env");
36
40
  const isDev = env === "dev";
37
41
 
38
42
  const resource =
39
43
  Resource.default().merge(
40
44
  new Resource({
41
- [SemanticResourceAttributes.SERVICE_NAME]: ConfigurationManager.getConfig("package.name"),
42
- [SemanticResourceAttributes.SERVICE_VERSION]: ConfigurationManager.getConfig("package.version"),
43
- [SemanticResourceAttributes.DEPLOYMENT_ENVIRONMENT]: env
45
+ // [SemanticResourceAttributes.SERVICE_NAME]: ConfigurationManager.getConfig("package.name"),
46
+ // [SemanticResourceAttributes.SERVICE_VERSION]: ConfigurationManager.getConfig("package.version"),
47
+ // [SemanticResourceAttributes.DEPLOYMENT_ENVIRONMENT]: env
48
+
49
+ [ATTR_SERVICE_NAME]: ConfigurationManager.getConfig("package_name") ?? ConfigurationManager.getConfig("package.name"),
50
+ [ATTR_SERVICE_VERSION]: ConfigurationManager.getConfig("package.version")
44
51
  })
45
52
  );
46
53
 
47
54
  const samplingRate = TypeHelper.parseNumber(ConfigurationManager.getConfig("otelTraceSamplingRate")) ?? 1;
48
55
 
49
56
  const enableXrayTracing = TypeHelper.parseBoolean(ConfigurationManager.getConfig("enableXrayTracing")) ?? false;
50
-
57
+
51
58
  const tracerConfig: TracerConfig = {
52
59
  resource: resource,
53
60
  sampler: new ParentBasedSampler({ root: new TraceIdRatioBasedSampler(samplingRate) })
@@ -59,7 +66,7 @@ if (enableXrayTracing)
59
66
  let traceHost = ConfigurationManager.getConfig<string | null>("otelTraceHost");
60
67
  if (traceHost == null || typeof traceHost !== "string" || traceHost.isEmptyOrWhiteSpace())
61
68
  traceHost = isDev ? "localhost" : "0.0.0.0";
62
-
69
+
63
70
  const provider = new NodeTracerProvider();
64
71
  // const exporter = new ConsoleSpanExporter();
65
72
  const exporter = new OTLPTraceExporter({
@@ -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,10 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "module": "commonjs",
4
- "target": "es2015",
3
+ "module": "NodeNext",
4
+ "target": "ES2022",
5
+ "lib": [
6
+ "ES2023"
7
+ ],
5
8
  "strict": true,
6
9
  "strictNullChecks": true,
7
10
  "strictFunctionTypes": true,
@@ -12,8 +15,6 @@
12
15
  "noFallthroughCasesInSwitch": true,
13
16
  "noEmitOnError": true,
14
17
  "sourceMap": true,
15
- "experimentalDecorators": true,
16
- "emitDecoratorMetadata": true,
17
18
  "removeComments": false,
18
19
  "forceConsistentCasingInFileNames": true,
19
20
  "incremental": false,
@@ -21,6 +22,8 @@
21
22
  "importHelpers": true,
22
23
  "noEmitHelpers": true,
23
24
  "noImplicitOverride": true,
24
- "pretty": true
25
+ "pretty": true,
26
+ "esModuleInterop": true,
27
+ "allowSyntheticDefaultImports": true
25
28
  }
26
29
  }