From 8491a0c32b88f591e29ee16f6e8d595b5068909f Mon Sep 17 00:00:00 2001 From: Guy Moses Date: Wed, 19 Jun 2024 13:45:25 +0300 Subject: [PATCH 1/2] fix: TypeError on empty span attributes --- src/spans/awsSpan.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/spans/awsSpan.ts b/src/spans/awsSpan.ts index ae91ca24..9c9e3b25 100644 --- a/src/spans/awsSpan.ts +++ b/src/spans/awsSpan.ts @@ -55,7 +55,7 @@ export const getAwsServiceData = (requestData, responseData, span: Span): AwsSer if (host?.includes('amazonaws.com')) { serviceType = getAwsServiceFromHost(host); } else if ( - span.attributes[SemanticAttributes.HTTP_USER_AGENT]?.toString().startsWith('aws-sqsd') + span.attributes?.[SemanticAttributes.HTTP_USER_AGENT]?.toString().startsWith('aws-sqsd') ) { /* * Workaround for Elastic Beanstalk, where a local proxy called "AWS SQS Daemon" From 12f4294008bf7977418896e1ab1035c946fda96c Mon Sep 17 00:00:00 2001 From: Guy Moses Date: Wed, 19 Jun 2024 16:11:49 +0300 Subject: [PATCH 2/2] adding u.t --- src/spans/awsSpan.test.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/spans/awsSpan.test.ts b/src/spans/awsSpan.test.ts index c2ddbbfd..62847efe 100644 --- a/src/spans/awsSpan.test.ts +++ b/src/spans/awsSpan.test.ts @@ -1,7 +1,7 @@ import { getAwsServiceData, getAwsServiceFromHost } from './awsSpan'; import { Span } from '@opentelemetry/sdk-trace-base'; import { AwsOtherService, AwsParsedService } from './types'; -import { rootSpanWithAttributes } from '../../test/utils/spans'; +import { rootSpanWithAttributes, rootSpanWithoutAttributes } from '../../test/utils/spans'; import { LumigoAwsSdkLibInstrumentation } from '../instrumentations/aws-sdk/LumigoAwsSdkLibInstrumentation'; describe('awsSpan', () => { @@ -46,6 +46,15 @@ describe('awsSpan', () => { }); }); + test('do not raise when span attributes are undefined', () => { + const requestData = { + body: '', + host: 'anything', + }; + const awsServiceAttributes = getAwsServiceData(requestData, undefined, {} as Span); + expect(awsServiceAttributes).toEqual({}); + }); + test('does not mark Elastic Beanstalk SQS Daemon spans as skipped', () => { const requestData = { host: 'localhost',