sm-utility 2.4.0 → 2.4.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sm-utility",
3
- "version": "2.4.0",
3
+ "version": "2.4.2",
4
4
  "description": "reusable utility codes for sm projects",
5
5
  "main": "index.js",
6
6
  "types": "./index.d.ts",
@@ -30,6 +30,7 @@
30
30
  "@opentelemetry/auto-instrumentations-node": "0.55.3",
31
31
  "@opentelemetry/exporter-trace-otlp-http": "0.57.1",
32
32
  "@opentelemetry/id-generator-aws-xray": "1.2.2",
33
+ "@opentelemetry/instrumentation-express": "0.47.0",
33
34
  "@opentelemetry/propagator-aws-xray": "1.26.1",
34
35
  "@opentelemetry/resources": "1.30.1",
35
36
  "@opentelemetry/sdk-node": "0.57.1",
@@ -2,12 +2,13 @@ export interface TracingConfig {
2
2
  serviceName: string;
3
3
  environment: string;
4
4
  otelEndpoint: string;
5
- samplingRatio?: number;
6
5
  maxQueueSize?: number;
7
6
  scheduledDelayMillis?: number;
7
+ ignoredPaths?: (string | RegExp | ((url: string) => boolean))[];
8
8
  }
9
9
  export declare class OpenTelemetryTracer {
10
10
  private sdk;
11
+ private handleIgnoreRequest;
11
12
  constructor(config: TracingConfig);
12
13
  start(): void;
13
14
  private setupGracefulShutdown;
@@ -10,11 +10,27 @@ const id_generator_aws_xray_1 = require("@opentelemetry/id-generator-aws-xray");
10
10
  const propagator_aws_xray_1 = require("@opentelemetry/propagator-aws-xray");
11
11
  const logger_1 = require("../logger");
12
12
  const DEFAULT_CONFIG = {
13
- samplingRatio: 0.1,
14
13
  maxQueueSize: 50,
15
14
  scheduledDelayMillis: 1000,
16
15
  };
17
16
  class OpenTelemetryTracer {
17
+ handleIgnoreRequest(url, finalConfig) {
18
+ var _a, _b;
19
+ if (!url)
20
+ return false;
21
+ return ((_b = (_a = finalConfig.ignoredPaths) === null || _a === void 0 ? void 0 : _a.some((path) => {
22
+ if (typeof path === "string") {
23
+ return url === path;
24
+ }
25
+ if (path instanceof RegExp) {
26
+ return path.test(url);
27
+ }
28
+ if (typeof path === "function") {
29
+ return path(url);
30
+ }
31
+ return false;
32
+ })) !== null && _b !== void 0 ? _b : false);
33
+ }
18
34
  constructor(config) {
19
35
  const finalConfig = { ...DEFAULT_CONFIG, ...config };
20
36
  const resource = resources_1.Resource.default().merge(new resources_1.Resource({
@@ -31,10 +47,20 @@ class OpenTelemetryTracer {
31
47
  this.sdk = new sdk_node_1.NodeSDK({
32
48
  resource,
33
49
  spanProcessors: [spanProcessor],
34
- instrumentations: [(0, auto_instrumentations_node_1.getNodeAutoInstrumentations)()],
50
+ instrumentations: [
51
+ (0, auto_instrumentations_node_1.getNodeAutoInstrumentations)({
52
+ "@opentelemetry/instrumentation-http": {
53
+ enabled: true,
54
+ ignoreIncomingRequestHook: (req) => this.handleIgnoreRequest(req.url, finalConfig),
55
+ },
56
+ "@opentelemetry/instrumentation-express": {
57
+ enabled: true,
58
+ ignoreLayers: finalConfig.ignoredPaths,
59
+ },
60
+ }),
61
+ ],
35
62
  textMapPropagator: new propagator_aws_xray_1.AWSXRayPropagator(),
36
63
  idGenerator: new id_generator_aws_xray_1.AWSXRayIdGenerator(),
37
- sampler: new sdk_trace_base_1.TraceIdRatioBasedSampler(finalConfig.samplingRatio),
38
64
  });
39
65
  }
40
66
  start() {