Skip to content

Commit 57ed9b4

Browse files
committed
removed lambda and sns tests, addressed PR comments
1 parent 229ab21 commit 57ed9b4

File tree

8 files changed

+24
-141
lines changed

8 files changed

+24
-141
lines changed

aws-distro-opentelemetry-node-autoinstrumentation/src/aws-metric-attribute-generator.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -580,13 +580,14 @@ export class AwsMetricAttributeGenerator implements MetricAttributeGenerator {
580580
return input.split('^').join('^^').split('|').join('^|');
581581
}
582582

583-
private static simplifyARNAttribute(attribute: AttributeValue | undefined) {
583+
// Extracts the name of the resource from an arn
584+
private static simplifyARNAttribute(attribute: AttributeValue | undefined): string | undefined {
584585
if (typeof attribute == 'string' && attribute.startsWith('arn:aws:')) {
585586
const split = attribute.split(':');
586587
return split[split.length - 1];
587588
}
588589

589-
return '';
590+
return undefined;
590591
}
591592

592593
/** Span kind is needed for differentiating metrics in the EMF exporter */

aws-distro-opentelemetry-node-autoinstrumentation/src/patches/aws/services/secretsmanager.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class SecretsManagerServiceExtension implements ServiceExtension {
1919

2020
const spanAttributes: Attributes = {};
2121

22-
if (secretId && secretId.startsWith('arn:aws:secretsmanager:')) {
22+
if (typeof secretId == 'string' && secretId.startsWith('arn:aws:secretsmanager:')) {
2323
spanAttributes[AWS_ATTRIBUTE_KEYS.AWS_SECRETSMANAGER_SECRET_ARN] = secretId;
2424
}
2525

@@ -34,10 +34,10 @@ export class SecretsManagerServiceExtension implements ServiceExtension {
3434
}
3535

3636
responseHook(response: NormalizedResponse, span: Span, tracer: Tracer, config: AwsSdkInstrumentationConfig): void {
37-
const secret_arn = response.data.ARN;
37+
const secretArn = response.data.ARN;
3838

39-
if (secret_arn) {
40-
span.setAttribute(AWS_ATTRIBUTE_KEYS.AWS_SECRETSMANAGER_SECRET_ARN, secret_arn);
39+
if (secretArn) {
40+
span.setAttribute(AWS_ATTRIBUTE_KEYS.AWS_SECRETSMANAGER_SECRET_ARN, secretArn);
4141
}
4242
}
4343
}

aws-distro-opentelemetry-node-autoinstrumentation/src/patches/instrumentation-patch.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ function patchSnsServiceExtension(snsServiceExtension: any): void {
176176
}
177177
return requestMetadata;
178178
};
179+
179180
snsServiceExtension.requestPreSpanHook = patchedRequestPreSpanHook;
180181
}
181182
}

aws-distro-opentelemetry-node-autoinstrumentation/test/aws-metric-attribute-generator.test.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -782,14 +782,14 @@ describe('AwsMetricAttributeGeneratorTest', () => {
782782
// Validate behaviour of AWS_STEPFUNCTIONS_STATEMACHINE_ARN and AWS_STEPFUNCTIONS_ACTIVITY_ARN attributes then remove them.
783783
mockAttribute(
784784
AWS_ATTRIBUTE_KEYS.AWS_STEPFUNCTIONS_STATEMACHINE_ARN,
785-
'arn:aws:states:us-east-1:007003123456789012:stateMachine:testStateMachine'
785+
'arn:aws:states:us-east-1:123456789123:stateMachine:testStateMachine'
786786
);
787787
validateRemoteResourceAttributes('AWS::StepFunctions::StateMachine', 'testStateMachine');
788788
mockAttribute(AWS_ATTRIBUTE_KEYS.AWS_STEPFUNCTIONS_STATEMACHINE_ARN, undefined);
789789

790790
mockAttribute(
791791
AWS_ATTRIBUTE_KEYS.AWS_STEPFUNCTIONS_ACTIVITY_ARN,
792-
'arn:aws:states:us-east-1:007003123456789012:activity:testActivity'
792+
'arn:aws:states:us-east-1:123456789123:activity:testActivity'
793793
);
794794
validateRemoteResourceAttributes('AWS::StepFunctions::Activity', 'testActivity');
795795
mockAttribute(AWS_ATTRIBUTE_KEYS.AWS_STEPFUNCTIONS_ACTIVITY_ARN, undefined);
@@ -839,12 +839,10 @@ describe('AwsMetricAttributeGeneratorTest', () => {
839839
validateRemoteResourceAttributes('AWS::Bedrock::DataSource', 'test_datasource_^^id');
840840
mockAttribute(AWS_ATTRIBUTE_KEYS.AWS_BEDROCK_DATA_SOURCE_ID, undefined);
841841

842-
// Validate behaviour of AWS_BEDROCK_GUARDRAIL_ID and AWS_BEDROCK_GUARDRAIL_ARN attribute, then remove it.
842+
// Validate behaviour of AWS_BEDROCK_GUARDRAIL_ID attribute, then remove it.
843843
mockAttribute(AWS_ATTRIBUTE_KEYS.AWS_BEDROCK_GUARDRAIL_ID, 'test_guardrail_id');
844-
mockAttribute(AWS_ATTRIBUTE_KEYS.AWS_BEDROCK_GUARDRAIL_ARN, 'test_guardrail_arn');
845844
validateRemoteResourceAttributes('AWS::Bedrock::Guardrail', 'test_guardrail_id');
846845
mockAttribute(AWS_ATTRIBUTE_KEYS.AWS_BEDROCK_GUARDRAIL_ID, undefined);
847-
mockAttribute(AWS_ATTRIBUTE_KEYS.AWS_BEDROCK_GUARDRAIL_ARN, undefined);
848846

849847
// Validate behaviour of AWS_BEDROCK_GUARDRAIL_ID attribute with special chars(^), then remove it.
850848
mockAttribute(AWS_ATTRIBUTE_KEYS.AWS_BEDROCK_GUARDRAIL_ID, 'test_guardrail_^id');

aws-distro-opentelemetry-node-autoinstrumentation/test/patches/aws/services/lamba.test.ts

Lines changed: 0 additions & 59 deletions
This file was deleted.

aws-distro-opentelemetry-node-autoinstrumentation/test/patches/aws/services/sns.test.ts

Lines changed: 0 additions & 59 deletions
This file was deleted.

aws-distro-opentelemetry-node-autoinstrumentation/test/patches/aws/services/step-functions.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe('SFN', () => {
3333

3434
describe('DescribeStateMachine', () => {
3535
it('span has stateMachineArn in its attributes', async () => {
36-
const stateMachineArn: string = 'arn:aws:states:us-east-1:007003123456789012:stateMachine:testStateMachine';
36+
const stateMachineArn: string = 'arn:aws:states:us-east-1:123456789123:stateMachine:testStateMachine';
3737

3838
nock(`https://states.${region}.amazonaws.com/`).post('/').reply(200, 'null');
3939

@@ -64,7 +64,7 @@ describe('SFN', () => {
6464

6565
describe('DescribeActivity', () => {
6666
it('span has activityArn in its attributes', async () => {
67-
const activityArn: string = 'arn:aws:states:us-east-1:007003123456789012:activity:testActivity';
67+
const activityArn: string = 'arn:aws:states:us-east-1:123456789123:activity:testActivity';
6868

6969
nock(`https://states.${region}.amazonaws.com/`).post('/').reply(200, 'null');
7070

aws-distro-opentelemetry-node-autoinstrumentation/test/patches/instrumentation-patch.test.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ import { SinonStub } from 'sinon';
2727
const _STREAM_NAME: string = 'streamName';
2828
const _BUCKET_NAME: string = 'bucketName';
2929
const _QUEUE_NAME: string = 'queueName';
30-
const _ACTIVITY_ARN: string = 'arn:aws:states:us-east-1:007003123456789012:activity:testActivity';
31-
const _STATE_MACHINE_ARN: string = 'arn:aws:states:us-east-1:007003123456789012:stateMachine:testStateMachine';
30+
const _ACTIVITY_ARN: string = 'arn:aws:states:us-east-1:123456789123:activity:testActivity';
31+
const _STATE_MACHINE_ARN: string = 'arn:aws:states:us-east-1:123456789123:stateMachine:testStateMachine';
3232
const _SECRETS_ARN: string = 'arn:aws:secretsmanager:us-east-1:123456789123:secret:testId123456';
3333
const _UUID: string = 'random-uuid';
3434
const _TOPIC_ARN: string = 'arn:aws:sns:us-east-1:123456789012:mystack-mytopic-NZJ5JSMVGFIE';
@@ -60,17 +60,17 @@ describe('InstrumentationPatchTest', () => {
6060
expect(services.has('SQS')).toBeTruthy();
6161
expect(services.has('SNS')).toBeTruthy();
6262
expect(services.has('Lambda')).toBeTruthy();
63-
expect(services.get('SNS')._requestPreSpanHook).toBeFalsy();
64-
expect(services.get('SNS').requestPreSpanHook).toBeTruthy();
65-
expect(services.get('Lambda')._requestPreSpanHook).toBeFalsy();
66-
expect(services.get('Lambda').requestPreSpanHook).toBeTruthy();
6763

6864
expect(services.has('DynamoDB')).toBeTruthy();
6965
// From patching but shouldn't be applied
7066
expect(services.get('SecretsManager')).toBeFalsy();
7167
expect(services.get('SFN')).toBeFalsy();
7268
expect(services.has('S3')).toBeFalsy();
7369
expect(services.has('Kinesis')).toBeFalsy();
70+
expect(services.get('SNS')._requestPreSpanHook).toBeFalsy();
71+
expect(services.get('SNS').requestPreSpanHook).toBeTruthy();
72+
expect(services.get('Lambda')._requestPreSpanHook).toBeFalsy();
73+
expect(services.get('Lambda').requestPreSpanHook).toBeTruthy();
7474
expect(services.get('SQS')._requestPreSpanHook).toBeFalsy();
7575
expect(services.get('SQS').requestPreSpanHook).toBeTruthy();
7676
expect(services.has('Bedrock')).toBeFalsy();
@@ -91,15 +91,16 @@ describe('InstrumentationPatchTest', () => {
9191
expect(services.has('SNS')).toBeTruthy();
9292
expect(services.has('DynamoDB')).toBeTruthy();
9393
expect(services.has('Lambda')).toBeTruthy();
94-
expect(services.get('SNS')._requestPreSpanHook).toBeTruthy();
95-
expect(services.get('SNS').requestPreSpanHook).toBeTruthy();
96-
expect(services.get('Lambda')._requestPreSpanHook).toBeTruthy();
97-
expect(services.get('Lambda').requestPreSpanHook).toBeTruthy();
94+
9895
// From patching
9996
expect(services.has('SecretsManager')).toBeTruthy();
10097
expect(services.has('SFN')).toBeTruthy();
10198
expect(services.has('S3')).toBeTruthy();
10299
expect(services.has('Kinesis')).toBeTruthy();
100+
expect(services.get('SNS')._requestPreSpanHook).toBeTruthy();
101+
expect(services.get('SNS').requestPreSpanHook).toBeTruthy();
102+
expect(services.get('Lambda')._requestPreSpanHook).toBeTruthy();
103+
expect(services.get('Lambda').requestPreSpanHook).toBeTruthy();
103104
expect(services.get('SQS')._requestPreSpanHook).toBeTruthy();
104105
expect(services.get('SQS').requestPreSpanHook).toBeTruthy();
105106
expect(services.has('Bedrock')).toBeTruthy();

0 commit comments

Comments
 (0)