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', 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"