Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jj22ee committed Aug 19, 2024
1 parent ce592e5 commit ed94e6c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ describe('instrumentation-aws-sdk-v3', () => {
expect(span.attributes[SEMATTRS_RPC_SYSTEM]).toEqual('aws-api');
expect(span.attributes[SEMATTRS_RPC_METHOD]).toEqual('PutObject');
expect(span.attributes[SEMATTRS_RPC_SERVICE]).toEqual('S3');
expect(span.attributes[AttributeNames.AWS_S3_BUCKET]).toEqual(
'ot-demo-test'
);
expect(span.attributes[AttributeNames.AWS_REGION]).toEqual(region);
expect(span.name).toEqual('S3.PutObject');
expect(span.kind).toEqual(SpanKind.CLIENT);
Expand All @@ -108,6 +111,9 @@ describe('instrumentation-aws-sdk-v3', () => {
expect(span.attributes[SEMATTRS_RPC_SYSTEM]).toEqual('aws-api');
expect(span.attributes[SEMATTRS_RPC_METHOD]).toEqual('PutObject');
expect(span.attributes[SEMATTRS_RPC_SERVICE]).toEqual('S3');
expect(span.attributes[AttributeNames.AWS_S3_BUCKET]).toEqual(
'ot-demo-test'
);
expect(span.attributes[AttributeNames.AWS_REGION]).toEqual(region);
expect(span.name).toEqual('S3.PutObject');
expect(span.attributes[SEMATTRS_HTTP_STATUS_CODE]).toEqual(200);
Expand All @@ -134,6 +140,9 @@ describe('instrumentation-aws-sdk-v3', () => {
expect(span.attributes[SEMATTRS_RPC_SYSTEM]).toEqual('aws-api');
expect(span.attributes[SEMATTRS_RPC_METHOD]).toEqual('PutObject');
expect(span.attributes[SEMATTRS_RPC_SERVICE]).toEqual('S3');
expect(span.attributes[AttributeNames.AWS_S3_BUCKET]).toEqual(
'ot-demo-test'
);
expect(span.attributes[AttributeNames.AWS_REGION]).toEqual(region);
expect(span.name).toEqual('S3.PutObject');
expect(span.attributes[SEMATTRS_HTTP_STATUS_CODE]).toEqual(200);
Expand Down Expand Up @@ -167,6 +176,9 @@ describe('instrumentation-aws-sdk-v3', () => {
expect(span.attributes[SEMATTRS_RPC_SYSTEM]).toEqual('aws-api');
expect(span.attributes[SEMATTRS_RPC_METHOD]).toEqual('PutObject');
expect(span.attributes[SEMATTRS_RPC_SERVICE]).toEqual('S3');
expect(span.attributes[AttributeNames.AWS_S3_BUCKET]).toEqual(
'invalid-bucket-name'
);
expect(span.attributes[SEMATTRS_HTTP_STATUS_CODE]).toEqual(403);
expect(span.attributes[AttributeNames.AWS_REGION]).toEqual(region);
expect(span.attributes[AttributeNames.AWS_REQUEST_ID]).toEqual(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { AwsInstrumentation } from '../src';
import { AttributeNames } from '../src/enums';
registerInstrumentationTesting(new AwsInstrumentation());

import { Kinesis } from '@aws-sdk/client-kinesis';
import { DescribeStreamCommand, KinesisClient } from '@aws-sdk/client-kinesis';
import * as AWS from 'aws-sdk';
import { AWSError } from 'aws-sdk';
import * as nock from 'nock';
Expand Down Expand Up @@ -80,28 +80,19 @@ describe('Kinesis - v2', () => {
});

describe('Kinesis - v3', () => {
let kinesis: Kinesis;
beforeEach(() => {
kinesis = new Kinesis({
region: region,
credentials: {
accessKeyId: 'abcde',
secretAccessKey: 'abcde',
},
});
});

describe('DescribeStream', () => {
it('adds Stream Name', async () => {
const dummyStreamName = 'dummy-stream-name';

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

await kinesis
.describeStream({
StreamName: dummyStreamName,
})
.catch((err: any) => {});
const params = {
StreamName: dummyStreamName,
};
const client = new KinesisClient({ region });
await client.send(new DescribeStreamCommand(params)).catch(() => {});

const testSpans: ReadableSpan[] = getTestSpans();
const describeSpans: ReadableSpan[] = testSpans.filter(
Expand Down
38 changes: 17 additions & 21 deletions plugins/node/opentelemetry-instrumentation-aws-sdk/test/s3.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ import { AwsInstrumentation } from '../src';
import { AttributeNames } from '../src/enums';
registerInstrumentationTesting(new AwsInstrumentation());

import { S3 } from '@aws-sdk/client-s3';
import { PutObjectCommand, S3Client } from '@aws-sdk/client-s3';
import * as AWS from 'aws-sdk';
import { AWSError } from 'aws-sdk';
import * as fs from 'fs';
import * as nock from 'nock';

import { SpanKind } from '@opentelemetry/api';
Expand Down Expand Up @@ -78,33 +79,28 @@ describe('S3 - v2', () => {
});

describe('S3 - v3', () => {
let s3: S3;
beforeEach(() => {
s3 = new S3({
region: region,
credentials: {
accessKeyId: 'abcde',
secretAccessKey: 'abcde',
},
});
});

describe('ListObjects', () => {
describe('PutObject', () => {
it('adds bucket Name', async () => {
const dummyBucketName = 'dummy-bucket-name';
const dummyBucketName = 'ot-demo-test';

nock(`https://s3.${region}.amazonaws.com/`).post('/').reply(200, 'null');
nock(`https://${dummyBucketName}.s3.${region}.amazonaws.com/`)
.put('/aws-ot-s3-test-object.txt?x-id=PutObject')
.reply(
200,
fs.readFileSync('./test/mock-responses/s3-put-object.xml', 'utf8')
);

await s3
.listObjects({
Bucket: dummyBucketName,
})
.catch((err: any) => {});
const params = {
Bucket: dummyBucketName,
Key: 'aws-ot-s3-test-object.txt',
};
const client = new S3Client({ region });
await client.send(new PutObjectCommand(params));

const testSpans: ReadableSpan[] = getTestSpans();
const listObjectsSpans: ReadableSpan[] = testSpans.filter(
(s: ReadableSpan) => {
return s.name === 'S3.ListObjects';
return s.name === 'S3.PutObject';
}
);
expect(listObjectsSpans.length).toBe(1);
Expand Down

0 comments on commit ed94e6c

Please sign in to comment.