MCPcopy Create free account
hub / github.com/apache/skywalking-nodejs / AWS2SNSPlugin

Class AWS2SNSPlugin

src/plugins/AWS2SNSPlugin.ts:30–99  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28import { getAWS, execute } from '../aws/SDK2';
29
30class AWS2SNSPlugin implements SwPlugin {
31 readonly module = 'aws-sdk';
32 readonly versions = '2.*';
33
34 install(installer: PluginInstaller): void {
35 const AWS = getAWS(installer);
36 const _SNS = AWS.SNS;
37
38 function SNS(this: any) {
39 const sns = _SNS.apply(this, arguments);
40
41 function instrument(name: string, addTraceId: any): void {
42 const _func = sns[name];
43
44 sns[name] = function (params: any, callback: any) {
45 const to = params.TopicArn
46 ? `Topic/${params.TopicArn.slice(params.TopicArn.lastIndexOf(':') + 1)}`
47 : params.TargetArn
48 ? `Target/${params.TargetArn.slice(params.TargetArn.lastIndexOf(':') + 1)}`
49 : params.PhoneNumber
50 ? `Phone/${params.PhoneNumber}`
51 : '???';
52 const operation = `AWS/SNS/${name}/${to}`;
53 const span = ContextManager.current.newExitSpan(operation, Component.AWS_SNS, Component.HTTP);
54 const arn = params.TopicArn || params.TargetArn;
55
56 span.component = Component.AWS_SNS;
57 span.layer = SpanLayer.MQ;
58
59 if (arn) span.tag(Tag.arn(arn));
60
61 if (params.TopicArn) params = addTraceId(params, span);
62
63 return execute(span, this, _func, params, callback, 'mqBroker');
64 };
65 }
66
67 instrument('publish', (params: any, span: Span) => {
68 params = Object.assign({}, params);
69 params.MessageAttributes = params.MessageAttributes ? Object.assign({}, params.MessageAttributes) : {};
70 params.MessageAttributes.__revdTraceId = {
71 DataType: 'String',
72 StringValue: `${span.inject().value}/${hostname()}`,
73 };
74
75 return params;
76 });
77
78 instrument('publishBatch', (params: any, span: Span) => {
79 const traceId = { __revdTraceId: { DataType: 'String', StringValue: `${span.inject().value}/${hostname()}` } };
80 params = Object.assign({}, params);
81 params.PublishBatchRequestEntries = params.PublishBatchRequestEntries.map(
82 (e: any) =>
83 (e = Object.assign({}, e, {
84 MessageAttributes: e.MessageAttributes ? Object.assign({}, e.MessageAttributes, traceId) : traceId,
85 })),
86 );
87

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected