sm-utility 2.4.26 → 2.4.27
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.
|
|
3
|
+
"version": "2.4.27",
|
|
4
4
|
"description": "reusable utility codes for sm projects",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "./index.d.ts",
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@aws-sdk/client-secrets-manager": "3.758.0",
|
|
31
|
+
"@aws-sdk/client-sqs": "3.758.0",
|
|
31
32
|
"@elastic/ecs-winston-format": "^1.3.1",
|
|
32
33
|
"@opentelemetry/auto-instrumentations-node": "0.55.3",
|
|
33
34
|
"@opentelemetry/exporter-trace-otlp-http": "0.57.1",
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { SendMessageCommandInput, Message } from '@aws-sdk/client-sqs';
|
|
2
|
+
export declare class SQSOtelContextHandler {
|
|
3
|
+
static injectContext(params: SendMessageCommandInput): SendMessageCommandInput;
|
|
4
|
+
static extractContext(message: Message): import("@opentelemetry/api").Context;
|
|
5
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SQSOtelContextHandler = void 0;
|
|
4
|
+
const api_1 = require("@opentelemetry/api");
|
|
5
|
+
class SQSOtelContextHandler {
|
|
6
|
+
static injectContext(params) {
|
|
7
|
+
var _a;
|
|
8
|
+
const carrier = {};
|
|
9
|
+
// Inject current active trace context into carrier
|
|
10
|
+
api_1.propagation.inject(api_1.context.active(), carrier, {
|
|
11
|
+
set: (c, k, v) => {
|
|
12
|
+
c[k] = String(v);
|
|
13
|
+
},
|
|
14
|
+
});
|
|
15
|
+
// Convert carrier to SQS MessageAttributes
|
|
16
|
+
const otelAttributes = {};
|
|
17
|
+
for (const [key, value] of Object.entries(carrier)) {
|
|
18
|
+
otelAttributes[key] = {
|
|
19
|
+
DataType: 'String',
|
|
20
|
+
StringValue: value,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
...params,
|
|
25
|
+
MessageAttributes: {
|
|
26
|
+
...((_a = params.MessageAttributes) !== null && _a !== void 0 ? _a : {}),
|
|
27
|
+
...otelAttributes,
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
static extractContext(message) {
|
|
32
|
+
var _a;
|
|
33
|
+
const attrs = (_a = message.MessageAttributes) !== null && _a !== void 0 ? _a : {};
|
|
34
|
+
const carrier = {};
|
|
35
|
+
for (const [key, val] of Object.entries(attrs)) {
|
|
36
|
+
if (val === null || val === void 0 ? void 0 : val.StringValue)
|
|
37
|
+
carrier[key] = val.StringValue;
|
|
38
|
+
}
|
|
39
|
+
return api_1.propagation.extract(api_1.context.active(), carrier, {
|
|
40
|
+
get: (c, k) => c[k],
|
|
41
|
+
keys: (c) => Object.keys(c),
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.SQSOtelContextHandler = SQSOtelContextHandler;
|