|
| 1 | +/* |
| 2 | + * Copyright The OpenTelemetry Authors |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +import { getTestSpans } from '@opentelemetry/contrib-test-utils'; |
| 18 | +import { SpanKind } from '@opentelemetry/api'; |
| 19 | +import { ReadableSpan } from '@opentelemetry/sdk-trace-base'; |
| 20 | +import { |
| 21 | + ATTR_AWS_STEP_FUNCTIONS_ACTIVITY_ARN, |
| 22 | + ATTR_AWS_STEP_FUNCTIONS_STATE_MACHINE_ARN, |
| 23 | +} from '@opentelemetry/semantic-conventions/incubating'; |
| 24 | + |
| 25 | +import { SFN } from '@aws-sdk/client-sfn'; |
| 26 | + |
| 27 | +import { expect } from 'expect'; |
| 28 | +import * as nock from 'nock'; |
| 29 | + |
| 30 | +const region = 'us-east-1'; |
| 31 | + |
| 32 | +describe('SFN', () => { |
| 33 | + let sfn: SFN; |
| 34 | + beforeEach(() => { |
| 35 | + sfn = new SFN({ |
| 36 | + region: region, |
| 37 | + credentials: { |
| 38 | + accessKeyId: 'abcde', |
| 39 | + secretAccessKey: 'abcde', |
| 40 | + }, |
| 41 | + }); |
| 42 | + }); |
| 43 | + |
| 44 | + describe('DescribeStateMachine', () => { |
| 45 | + it('span has stateMachineArn in its attributes', async () => { |
| 46 | + const stateMachineArn = |
| 47 | + 'arn:aws:states:us-east-1:123456789123:stateMachine:testStateMachine'; |
| 48 | + |
| 49 | + nock(`https://states.${region}.amazonaws.com/`) |
| 50 | + .post('/') |
| 51 | + .reply(200, '{}'); |
| 52 | + |
| 53 | + await sfn.describeStateMachine({ |
| 54 | + stateMachineArn: stateMachineArn, |
| 55 | + }); |
| 56 | + |
| 57 | + const testSpans: ReadableSpan[] = getTestSpans(); |
| 58 | + const getStateMachineAttributeSpans: ReadableSpan[] = testSpans.filter( |
| 59 | + (s: ReadableSpan) => { |
| 60 | + return s.name === 'SFN.DescribeStateMachine'; |
| 61 | + } |
| 62 | + ); |
| 63 | + |
| 64 | + expect(getStateMachineAttributeSpans.length).toBe(1); |
| 65 | + |
| 66 | + const stateMachineAttributeSpan = getStateMachineAttributeSpans[0]; |
| 67 | + expect( |
| 68 | + ATTR_AWS_STEP_FUNCTIONS_STATE_MACHINE_ARN in |
| 69 | + stateMachineAttributeSpan.attributes |
| 70 | + ); |
| 71 | + expect( |
| 72 | + stateMachineAttributeSpan.attributes[ |
| 73 | + ATTR_AWS_STEP_FUNCTIONS_STATE_MACHINE_ARN |
| 74 | + ] |
| 75 | + ).toBe(stateMachineArn); |
| 76 | + expect(stateMachineAttributeSpan.kind).toBe(SpanKind.CLIENT); |
| 77 | + }); |
| 78 | + }); |
| 79 | + |
| 80 | + describe('DescribeActivity', () => { |
| 81 | + it('span has activityArn in its attributes', async () => { |
| 82 | + const activityArn = |
| 83 | + 'arn:aws:states:us-east-1:123456789123:activity:testActivity'; |
| 84 | + |
| 85 | + nock(`https://states.${region}.amazonaws.com/`) |
| 86 | + .post('/') |
| 87 | + .reply(200, '{}'); |
| 88 | + |
| 89 | + await sfn.describeActivity({ |
| 90 | + activityArn: activityArn, |
| 91 | + }); |
| 92 | + |
| 93 | + const testSpans: ReadableSpan[] = getTestSpans(); |
| 94 | + const getActivityAttributeSpans: ReadableSpan[] = testSpans.filter( |
| 95 | + (s: ReadableSpan) => { |
| 96 | + return s.name === 'SFN.DescribeActivity'; |
| 97 | + } |
| 98 | + ); |
| 99 | + |
| 100 | + expect(getActivityAttributeSpans.length).toBe(1); |
| 101 | + |
| 102 | + const activityAttributeSpan = getActivityAttributeSpans[0]; |
| 103 | + expect( |
| 104 | + ATTR_AWS_STEP_FUNCTIONS_ACTIVITY_ARN in activityAttributeSpan.attributes |
| 105 | + ); |
| 106 | + expect( |
| 107 | + activityAttributeSpan.attributes[ATTR_AWS_STEP_FUNCTIONS_ACTIVITY_ARN] |
| 108 | + ).toBe(activityArn); |
| 109 | + expect(activityAttributeSpan.kind).toBe(SpanKind.CLIENT); |
| 110 | + }); |
| 111 | + }); |
| 112 | +}); |
0 commit comments