sm-utility 2.4.1 → 2.4.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.
package/package.json
CHANGED
|
@@ -2,13 +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;
|
|
8
7
|
ignoredPaths?: (string | RegExp | ((url: string) => boolean))[];
|
|
9
8
|
}
|
|
10
9
|
export declare class OpenTelemetryTracer {
|
|
11
10
|
private sdk;
|
|
11
|
+
private handleIgnoreRequest;
|
|
12
12
|
constructor(config: TracingConfig);
|
|
13
13
|
start(): void;
|
|
14
14
|
private setupGracefulShutdown;
|
|
@@ -8,13 +8,30 @@ const exporter_trace_otlp_http_1 = require("@opentelemetry/exporter-trace-otlp-h
|
|
|
8
8
|
const resources_1 = require("@opentelemetry/resources");
|
|
9
9
|
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
|
+
const http_1 = require("http");
|
|
11
12
|
const logger_1 = require("../logger");
|
|
12
13
|
const DEFAULT_CONFIG = {
|
|
13
|
-
samplingRatio: 0.1,
|
|
14
14
|
maxQueueSize: 50,
|
|
15
15
|
scheduledDelayMillis: 1000,
|
|
16
16
|
};
|
|
17
17
|
class OpenTelemetryTracer {
|
|
18
|
+
handleIgnoreRequest(url, finalConfig) {
|
|
19
|
+
var _a, _b;
|
|
20
|
+
if (!url)
|
|
21
|
+
return false;
|
|
22
|
+
return ((_b = (_a = finalConfig.ignoredPaths) === null || _a === void 0 ? void 0 : _a.some((path) => {
|
|
23
|
+
if (typeof path === "string") {
|
|
24
|
+
return url === path;
|
|
25
|
+
}
|
|
26
|
+
if (path instanceof RegExp) {
|
|
27
|
+
return path.test(url);
|
|
28
|
+
}
|
|
29
|
+
if (typeof path === "function") {
|
|
30
|
+
return path(url);
|
|
31
|
+
}
|
|
32
|
+
return false;
|
|
33
|
+
})) !== null && _b !== void 0 ? _b : false);
|
|
34
|
+
}
|
|
18
35
|
constructor(config) {
|
|
19
36
|
const finalConfig = { ...DEFAULT_CONFIG, ...config };
|
|
20
37
|
const resource = resources_1.Resource.default().merge(new resources_1.Resource({
|
|
@@ -33,17 +50,35 @@ class OpenTelemetryTracer {
|
|
|
33
50
|
spanProcessors: [spanProcessor],
|
|
34
51
|
instrumentations: [
|
|
35
52
|
(0, auto_instrumentations_node_1.getNodeAutoInstrumentations)({
|
|
53
|
+
"@opentelemetry/instrumentation-http": {
|
|
54
|
+
enabled: true,
|
|
55
|
+
ignoreIncomingRequestHook: (req) => this.handleIgnoreRequest(req.url, finalConfig),
|
|
56
|
+
requestHook: (span, request) => {
|
|
57
|
+
if (request instanceof http_1.IncomingMessage && "headers" in request) {
|
|
58
|
+
const traceId = request.headers["x-amzn-trace-id"];
|
|
59
|
+
if (traceId) {
|
|
60
|
+
span.setAttribute("aws.trace.id", traceId);
|
|
61
|
+
logger_1.logger.debug("X-Amzn-Trace-Id captured", { traceId });
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
},
|
|
36
66
|
"@opentelemetry/instrumentation-express": {
|
|
37
67
|
enabled: true,
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
68
|
+
ignoreLayers: finalConfig.ignoredPaths,
|
|
69
|
+
requestHook: (span, req) => {
|
|
70
|
+
var _a;
|
|
71
|
+
const traceId = (_a = req.headers) === null || _a === void 0 ? void 0 : _a["x-amzn-trace-id"];
|
|
72
|
+
if (traceId) {
|
|
73
|
+
span.setAttribute("aws.trace.id", traceId);
|
|
74
|
+
logger_1.logger.debug("Express: X-Amzn-Trace-Id captured", { traceId });
|
|
75
|
+
}
|
|
76
|
+
},
|
|
41
77
|
},
|
|
42
78
|
}),
|
|
43
79
|
],
|
|
44
80
|
textMapPropagator: new propagator_aws_xray_1.AWSXRayPropagator(),
|
|
45
81
|
idGenerator: new id_generator_aws_xray_1.AWSXRayIdGenerator(),
|
|
46
|
-
sampler: new sdk_trace_base_1.TraceIdRatioBasedSampler(finalConfig.samplingRatio),
|
|
47
82
|
});
|
|
48
83
|
}
|
|
49
84
|
start() {
|