Skip to content

Commit

Permalink
fix: TypeError on empty span attributes (#409)
Browse files Browse the repository at this point in the history
  • Loading branch information
GuyMoses authored Jun 19, 2024
1 parent 6fe6ba2 commit 6b8fdad
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/spans/awsSpan.test.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion src/spans/awsSpan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 6b8fdad

Please sign in to comment.