@nivinjoseph/n-strument 1.0.1 → 1.0.3

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,5 @@
1
+ {
2
+ "cSpell.words": [
3
+ "otel"
4
+ ]
5
+ }
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- var _a;
2
+ var _a, _b;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  const auto_instrumentations_node_1 = require("@opentelemetry/auto-instrumentations-node");
5
5
  const resources_1 = require("@opentelemetry/resources");
@@ -12,6 +12,8 @@ const exporter_trace_otlp_http_1 = require("@opentelemetry/exporter-trace-otlp-h
12
12
  const n_config_1 = require("@nivinjoseph/n-config");
13
13
  const instrumentation_koa_1 = require("@opentelemetry/instrumentation-koa");
14
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");
15
17
  // For troubleshooting, set the log level to DiagLogLevel.DEBUG
16
18
  api_1.diag.setLogger(new api_1.DiagConsoleLogger(), api_1.DiagLogLevel.INFO);
17
19
  // This registers all instrumentation packages
@@ -38,18 +40,25 @@ const resource = resources_1.Resource.default().merge(new resources_1.Resource({
38
40
  [semantic_conventions_1.SemanticResourceAttributes.DEPLOYMENT_ENVIRONMENT]: env
39
41
  }));
40
42
  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({
43
+ const enableXrayTracing = (_b = n_util_1.TypeHelper.parseBoolean(n_config_1.ConfigurationManager.getConfig("enableXrayTracing"))) !== null && _b !== void 0 ? _b : false;
44
+ const tracerConfig = {
42
45
  resource: resource,
43
46
  sampler: new sdk_trace_node_1.ParentBasedSampler({ root: new sdk_trace_node_1.TraceIdRatioBasedSampler(samplingRate) })
44
- });
47
+ };
48
+ if (enableXrayTracing)
49
+ tracerConfig.idGenerator = new id_generator_aws_xray_1.AWSXRayIdGenerator();
50
+ let traceHost = n_config_1.ConfigurationManager.getConfig("otelTraceHost");
51
+ if (traceHost == null || typeof traceHost !== "string" || traceHost.isEmptyOrWhiteSpace())
52
+ traceHost = isDev ? "localhost" : "0.0.0.0";
53
+ const provider = new sdk_trace_node_1.NodeTracerProvider();
45
54
  // const exporter = new ConsoleSpanExporter();
46
55
  const exporter = new exporter_trace_otlp_http_1.OTLPTraceExporter({
47
56
  // optional - default url is http://localhost:4318/v1/traces
48
- url: `http://${isDev ? "localhost" : "0.0.0.0"}:4318/v1/traces`,
57
+ url: `http://${traceHost}:4318/v1/traces`,
49
58
  // optional - collection of custom headers to be sent with each request, empty by default
50
59
  headers: {}
51
60
  });
52
61
  const processor = new sdk_trace_base_1.BatchSpanProcessor(exporter);
53
62
  provider.addSpanProcessor(processor);
54
- provider.register();
63
+ provider.register(enableXrayTracing ? { propagator: new propagator_aws_xray_1.AWSXRayPropagator() } : undefined);
55
64
  //# 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,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;Y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C,SAAS,CAAC,CAAC;AAErC,QAAQ,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,IAAI,uCAAiB,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nivinjoseph/n-strument",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Instrumentation helper library",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -43,10 +43,12 @@
43
43
  "typescript": "^4.6.4"
44
44
  },
45
45
  "dependencies": {
46
- "@nivinjoseph/n-config": "^1.0.36",
46
+ "@nivinjoseph/n-config": "^1.0.38",
47
47
  "@nivinjoseph/n-util": "^1.0.81",
48
48
  "@opentelemetry/api": "^1.3.0",
49
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",
50
52
  "@opentelemetry/sdk-node": "^0.34.0",
51
53
  "tslib": "^2.4.0"
52
54
  }
package/src/index.ts CHANGED
@@ -3,12 +3,14 @@ import { Resource } from "@opentelemetry/resources";
3
3
  import { SemanticResourceAttributes } from "@opentelemetry/semantic-conventions";
4
4
  import { NodeTracerProvider, ParentBasedSampler, TraceIdRatioBasedSampler } from "@opentelemetry/sdk-trace-node";
5
5
  import { registerInstrumentations } from "@opentelemetry/instrumentation";
6
- import { BatchSpanProcessor } from "@opentelemetry/sdk-trace-base";
6
+ import { BatchSpanProcessor, TracerConfig } from "@opentelemetry/sdk-trace-base";
7
7
  import { diag, DiagConsoleLogger, DiagLogLevel } from '@opentelemetry/api';
8
8
  import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
9
9
  import { ConfigurationManager } from "@nivinjoseph/n-config";
10
10
  import { KoaLayerType } from "@opentelemetry/instrumentation-koa";
11
11
  import { TypeHelper } from "@nivinjoseph/n-util";
12
+ import { AWSXRayPropagator } from "@opentelemetry/propagator-aws-xray";
13
+ import { AWSXRayIdGenerator } from "@opentelemetry/id-generator-aws-xray";
12
14
 
13
15
  // For troubleshooting, set the log level to DiagLogLevel.DEBUG
14
16
  diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.INFO);
@@ -43,20 +45,31 @@ const resource =
43
45
  );
44
46
 
45
47
  const samplingRate = TypeHelper.parseNumber(ConfigurationManager.getConfig("otelTraceSamplingRate")) ?? 1;
46
-
47
- const provider = new NodeTracerProvider({
48
+
49
+ const enableXrayTracing = TypeHelper.parseBoolean(ConfigurationManager.getConfig("enableXrayTracing")) ?? false;
50
+
51
+ const tracerConfig: TracerConfig = {
48
52
  resource: resource,
49
53
  sampler: new ParentBasedSampler({ root: new TraceIdRatioBasedSampler(samplingRate) })
50
- });
54
+ };
55
+
56
+ if (enableXrayTracing)
57
+ tracerConfig.idGenerator = new AWSXRayIdGenerator();
58
+
59
+ let traceHost = ConfigurationManager.getConfig<string | null>("otelTraceHost");
60
+ if (traceHost == null || typeof traceHost !== "string" || traceHost.isEmptyOrWhiteSpace())
61
+ traceHost = isDev ? "localhost" : "0.0.0.0";
62
+
63
+ const provider = new NodeTracerProvider();
51
64
  // const exporter = new ConsoleSpanExporter();
52
65
  const exporter = new OTLPTraceExporter({
53
66
  // optional - default url is http://localhost:4318/v1/traces
54
67
 
55
- url: `http://${isDev ? "localhost" : "0.0.0.0"}:4318/v1/traces`,
68
+ url: `http://${traceHost}:4318/v1/traces`,
56
69
  // optional - collection of custom headers to be sent with each request, empty by default
57
70
  headers: {}
58
71
  });
59
72
  const processor = new BatchSpanProcessor(exporter);
60
73
  provider.addSpanProcessor(processor);
61
74
 
62
- provider.register();
75
+ provider.register(enableXrayTracing ? { propagator: new AWSXRayPropagator() } : undefined);