@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/.eslintrc +13 -4
- package/.gitattributes +4 -0
- package/.vscode/settings.json +30 -0
- package/.yarn/install-state.gz +0 -0
- package/.yarn/releases/yarn-4.4.1.cjs +925 -0
- package/.yarnrc.yml +3 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +35 -34
- package/dist/index.js.map +1 -1
- package/dist/tsconfig.json +2 -1
- package/package.json +22 -25
- package/src/index.ts +15 -8
- package/test/dummy.test.ts +12 -0
- package/tsconfig.json +8 -5
package/.yarnrc.yml
ADDED
package/dist/index.d.ts
CHANGED
|
@@ -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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
17
|
+
diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.INFO);
|
|
19
18
|
// This registers all instrumentation packages
|
|
20
|
-
|
|
19
|
+
registerInstrumentations({
|
|
21
20
|
instrumentations: [
|
|
22
|
-
|
|
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: [
|
|
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 =
|
|
34
|
+
const env = ConfigurationManager.requireStringConfig("env");
|
|
36
35
|
const isDev = env === "dev";
|
|
37
|
-
const resource =
|
|
38
|
-
[
|
|
39
|
-
[
|
|
40
|
-
[
|
|
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 =
|
|
43
|
-
const enableXrayTracing =
|
|
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
|
|
47
|
+
sampler: new ParentBasedSampler({ root: new TraceIdRatioBasedSampler(samplingRate) })
|
|
47
48
|
};
|
|
48
49
|
if (enableXrayTracing)
|
|
49
|
-
tracerConfig.idGenerator = new
|
|
50
|
-
let traceHost =
|
|
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
|
|
54
|
+
const provider = new NodeTracerProvider();
|
|
54
55
|
// const exporter = new ConsoleSpanExporter();
|
|
55
|
-
const exporter = new
|
|
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
|
|
62
|
+
const processor = new BatchSpanProcessor(exporter);
|
|
62
63
|
provider.addSpanProcessor(processor);
|
|
63
|
-
provider.register(enableXrayTracing ? { propagator: new
|
|
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":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,2CAA2C,CAAC;AACxF,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OACI;AACI,8BAA8B;AAC9B,iBAAiB,EAAE,oBAAoB,EAC1C,MAAM,qCAAqC,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACjH,OAAO,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AAC1E,OAAO,EAAE,kBAAkB,EAAgB,MAAM,+BAA+B,CAAC;AACjF,OAAO,EAAE,IAAI,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC3E,OAAO,EAAE,iBAAiB,EAAE,MAAM,yCAAyC,CAAC;AAC5E,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;AACvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,sC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GAAiB;IAC/B,QAAQ,EAAE,QAAQ;IAClB,OAAO,EAAE,IAAI,kBAAkB,CAAC,EAAE,IAAI,EAAE,IAAI,wBAAwB,CAAC,YAAY,CAAC,EAAE,CAAC;CACxF,CAAC;AAEF,IAAI,iBAAiB;IACjB,YAAY,CAAC,WAAW,GAAG,IAAI,kBAAkB,EAAE,CAAC;AAExD,IAAI,SAAS,GAAG,oBAAoB,CAAC,SAAS,CAAgB,eAAe,CAAC,CAAC;AAC/E,IAAI,SAAS,IAAI,IAAI,IAAI,OAAO,SAAS,KAAK,QAAQ,IAAI,SAAS,CAAC,mBAAmB,EAAE;IACrF,SAAS,GAAG,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC;AAEhD,MAAM,QAAQ,GAAG,IAAI,kBAAkB,EAAE,CAAC;AAC1C,8CAA8C;AAC9C,MAAM,QAAQ,GAAG,IAAI,iBAAiB,CAAC;IACnC,4DAA4D;IAE5D,GAAG,EAAE,UAAU,SAAS,iBAAiB;IACzC,yFAAyF;IACzF,OAAO,EAAE,EAAE;CACd,CAAC,CAAC;AACH,MAAM,SAAS,GAAG,IAAI,kBAAkB,CAAC,QAAQ,CAAC,CAAC;AACnD,QAAQ,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC;AAErC,QAAQ,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,IAAI,iBAAiB,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC"}
|
package/dist/tsconfig.json
CHANGED
package/package.json
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nivinjoseph/n-strument",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "Instrumentation helper library",
|
|
5
|
-
"
|
|
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": "
|
|
11
|
-
"ts-build-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
|
-
"
|
|
15
|
-
"
|
|
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/
|
|
37
|
-
"@
|
|
38
|
-
"@typescript-eslint/
|
|
39
|
-
"
|
|
40
|
-
"eslint": "^
|
|
41
|
-
"
|
|
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": "^
|
|
47
|
-
"@nivinjoseph/n-util": "^
|
|
48
|
-
"@opentelemetry/api": "^1.
|
|
49
|
-
"@opentelemetry/auto-instrumentations-node": "^0.
|
|
50
|
-
"@opentelemetry/id-generator-aws-xray": "^1.
|
|
51
|
-
"@opentelemetry/propagator-aws-xray": "^1.
|
|
52
|
-
"@opentelemetry/sdk-node": "^0.
|
|
53
|
-
"tslib": "^2.
|
|
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
|
|
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
|
|
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.
|
|
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({
|
package/tsconfig.json
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
-
"module": "
|
|
4
|
-
"target": "
|
|
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
|
}
|