Skip to content
This repository has been archived by the owner on Jul 10, 2023. It is now read-only.

Commit

Permalink
Add check for inject span context to header process
Browse files Browse the repository at this point in the history
  • Loading branch information
bcaglayan committed Dec 7, 2021
1 parent 5c84de8 commit c02e2a8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/integrations/AWSIntegration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ export class AWSIntegration implements Integration {

activeSpan = AWSServiceIntegration.doCreateSpan(tracer, request, config);

if (request.httpRequest) {
if (request.httpRequest
&& AWSServiceIntegration.isSpanContextInjectableToHeader(request)) {
const httpRequest = request.httpRequest;
const headers = httpRequest.headers ? httpRequest.headers : {};
tracer.inject(activeSpan.spanContext, opentracing.FORMAT_TEXT_MAP, headers);
Expand Down
17 changes: 17 additions & 0 deletions src/integrations/AWSServiceIntegration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,23 @@ export class AWSServiceIntegration {
return messageAttributes;
}

public static isSpanContextInjectableToHeader(request: any): boolean {
let result = true;
const service = AWSServiceIntegration.getServiceFromReq(request);
if (service) {
if (service.name !== AWSServiceIntegration.name
&& service.isSpanContextInjectableToHeader) {
result = service.isSpanContextInjectableToHeader(request);
} else {
if (service.name === AWSS3Integration.name) {
result = false;
}
}
}

return result;
}

public static serviceFactory(serviceName: string): any {
switch (serviceName) {
case 'sqs':
Expand Down
3 changes: 2 additions & 1 deletion src/integrations/AWSv3Integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ export class AWSv3Integration implements Integration {

ThundraLogger.debug('<AWSv3Integration> Build middleware working...');

if (args && args.request) {
if (args && args.request
&& AWSServiceIntegration.isSpanContextInjectableToHeader(request)) {
const httpRequest = args.request;
const headers = httpRequest.headers ? httpRequest.headers : {};
tracer.inject(activeSpan.spanContext, opentracing.FORMAT_TEXT_MAP, headers);
Expand Down

0 comments on commit c02e2a8

Please sign in to comment.