Skip to content
This repository was archived by the owner on Oct 31, 2024. It is now read-only.

Commit c191bb2

Browse files
author
Amir Blum
committed
fix: log if sqs unable to inject context propagation
1 parent d276dd7 commit c191bb2

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

packages/plugin-aws-sdk/src/aws-sdk.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ class AwsPlugin extends BasePlugin<typeof AWS> {
2929
}
3030

3131
protected patch() {
32-
this.servicesExtensions = new ServicesExtensions(this._tracer);
32+
this.servicesExtensions = new ServicesExtensions(
33+
this._tracer,
34+
this._logger
35+
);
3336

3437
this._logger.debug(
3538
"applying patch to %s@%s",

packages/plugin-aws-sdk/src/services/ServicesExtensions.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import { Tracer, Span } from "@opentelemetry/api";
1+
import { Tracer, Span, Logger } from "@opentelemetry/api";
22
import { ServiceExtension, RequestMetadata } from "./ServiceExtension";
33
import { SqsServiceExtension } from "./sqs";
44
import * as AWS from "aws-sdk";
55

66
export class ServicesExtensions implements ServiceExtension {
77
services: Map<string, ServiceExtension> = new Map();
88

9-
constructor(tracer: Tracer) {
10-
this.services.set("sqs", new SqsServiceExtension(tracer));
9+
constructor(tracer: Tracer, logger: Logger) {
10+
this.services.set("sqs", new SqsServiceExtension(tracer, logger));
1111
}
1212

1313
requestHook(request: AWS.Request<any, any>): RequestMetadata {

packages/plugin-aws-sdk/src/services/sqs.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
propagation,
66
Context,
77
Link,
8+
Logger,
89
} from "@opentelemetry/api";
910
import { RequestMetadata, ServiceExtension } from "./ServiceExtension";
1011
import * as AWS from "aws-sdk";
@@ -49,14 +50,16 @@ const contextGetterFunc = (
4950
messageAttributes: AWS.SQS.MessageBodyAttributeMap,
5051
key: string
5152
) => {
52-
return messageAttributes[key]?.StringValue;
53+
return messageAttributes?.[key]?.StringValue;
5354
};
5455

5556
export class SqsServiceExtension implements ServiceExtension {
5657
tracer: Tracer;
58+
logger: Logger;
5759

58-
constructor(tracer: Tracer) {
60+
constructor(tracer: Tracer, logger: Logger) {
5961
this.tracer = tracer;
62+
this.logger = logger;
6063
}
6164

6265
requestHook(request: AWS.Request<any, any>): RequestMetadata {
@@ -97,13 +100,14 @@ export class SqsServiceExtension implements ServiceExtension {
97100
spanName = queueName;
98101

99102
const params: Record<string, any> = (request as any).params;
100-
const attributes = params.MessageAttributes || {};
101-
if (attributes.length < SQS_MAX_MESSAGE_ATTRIBUTES) {
103+
const attributes = params.MessageAttributes ?? {};
104+
if (Object.keys(attributes).length < SQS_MAX_MESSAGE_ATTRIBUTES) {
102105
propagation.inject(attributes, contextSetterFunc);
103106
params.MessageAttributes = attributes;
104107
} else {
105-
// TODO: in this case we are not setting the context propagtion for consumers
106-
// how to log the issue?
108+
this.logger.warn(
109+
"OpenTelemetry aws-sdk plugin cannot set context propagation on SQS message due to maximum amount of MessageAttributes"
110+
);
107111
}
108112
}
109113
break;

0 commit comments

Comments
 (0)