Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
112 commits
Select commit Hold shift + click to select a range
8b5a06b
first pass + basic test
Feb 15, 2024
df31311
Merge branch 'master' into chris.agocs/inject_trace_context_into_step…
Feb 15, 2024
288c281
Add intentionally failing tests so we can see if they're running
Feb 16, 2024
c1cd88a
fix Stepfunctions test
Feb 16, 2024
4f954f0
rename Stepfunctions to Sfn
Feb 16, 2024
ceaf348
Remove purposeful failure in eventbridge test
Feb 16, 2024
fbd7d7f
Fix generate tags?
Feb 16, 2024
a5c7161
Set resource.name on stepfunction input
Feb 16, 2024
1e0e415
Fix capitalization on statemachinearn, add a test
Feb 16, 2024
3cf43be
vscode doesn't auto-save
Feb 16, 2024
950caca
Test request injection for a step function start execution
Feb 19, 2024
295c3a8
Change start_Execution to startExecution
Feb 19, 2024
a4d00b5
Move operation to request instead of params
Feb 19, 2024
33ee901
Add expected output to the test
Feb 19, 2024
8e41b0d
Rename Sfn to Stepfunctions
Feb 19, 2024
a11cea7
remove extra semicolon
Feb 19, 2024
9d30d3e
Add more test cases
Feb 19, 2024
9b380bb
Merge branch 'master' into chris.agocs/inject_trace_context_into_step…
agocs Feb 19, 2024
80313e5
Update packages/datadog-plugin-aws-sdk/src/services/stepfunctions.js
agocs Mar 6, 2024
8382a7b
Document why we have a code snippet
Mar 6, 2024
b97664a
Apply Jordi's patch and start fixing it
Mar 11, 2024
741ee94
Remove implicit return?
Mar 11, 2024
1bd8936
Add aws-sdk/client-sfn to dependencies
Mar 11, 2024
17dc837
Undo changes to package.json and yarn.lock
Mar 11, 2024
21daf7b
* injection behaviour spy tests run once
Mar 12, 2024
68edc25
Try loading aws-sdk
Mar 12, 2024
1759b08
Remove loading aws-sdk, make stateMachineArn a string literal
Mar 12, 2024
3e8358d
idk maybe?
Mar 12, 2024
55abe2e
Try to log arguments
Mar 12, 2024
9a5c17c
enable stepfunctions in localstack
Mar 13, 2024
0efb987
remove console logs
Mar 13, 2024
f9d10bb
Log a span
Mar 13, 2024
3e12e32
Make the test fail so the log line will print
Mar 13, 2024
dbbeabc
Remove the first expect
Mar 13, 2024
54d2042
wtf
Mar 13, 2024
298c174
wtf wtf
Mar 13, 2024
9ddeba1
Try logging the span now
Mar 13, 2024
ca0d735
Force the test to fail in a different way
Mar 13, 2024
7fc4487
Try moving the expect?
Mar 13, 2024
ef562f6
Try awaiting the agent.use callback
Mar 13, 2024
8260093
try checking traces like Jordan said:
Mar 13, 2024
5192a2d
add some parens
Mar 13, 2024
a0fd155
try moving await client.startExecution
Mar 13, 2024
2ea4b27
Maybe I need to 'register the callback' or some js nonsense first
Mar 13, 2024
c44dcde
Try adding env vars
Mar 13, 2024
9eb452b
try short circuiting isEnables
Mar 13, 2024
b6145dd
try calling tracer.init and agent.load like in s3.spec.js
Mar 13, 2024
51d695b
Apply Jordi's patch
Mar 14, 2024
0962a9f
re-enable isEnabled
Mar 14, 2024
546535f
Export stepfunctions as a plugin
Mar 18, 2024
e5976e7
try adding sfn and states as aliases for stepfunctions
Mar 28, 2024
760bdb7
first pass + basic test
Feb 15, 2024
2642b37
Add intentionally failing tests so we can see if they're running
Feb 16, 2024
558392c
fix Stepfunctions test
Feb 16, 2024
88c7834
rename Stepfunctions to Sfn
Feb 16, 2024
7386813
Remove purposeful failure in eventbridge test
Feb 16, 2024
fae65ae
Fix generate tags?
Feb 16, 2024
8948b68
Set resource.name on stepfunction input
Feb 16, 2024
b421e3a
Fix capitalization on statemachinearn, add a test
Feb 16, 2024
762f43e
vscode doesn't auto-save
Feb 16, 2024
a3b6702
Test request injection for a step function start execution
Feb 19, 2024
5a4a826
Change start_Execution to startExecution
Feb 19, 2024
1e5602f
Move operation to request instead of params
Feb 19, 2024
8d60bbb
Add expected output to the test
Feb 19, 2024
86a241e
Rename Sfn to Stepfunctions
Feb 19, 2024
5d674ea
remove extra semicolon
Feb 19, 2024
302e981
Add more test cases
Feb 19, 2024
529547c
Update packages/datadog-plugin-aws-sdk/src/services/stepfunctions.js
agocs Mar 6, 2024
accd175
Document why we have a code snippet
Mar 6, 2024
785d4c8
Apply Jordi's patch and start fixing it
Mar 11, 2024
0b4c4bc
Remove implicit return?
Mar 11, 2024
3ae086c
Add aws-sdk/client-sfn to dependencies
Mar 11, 2024
f81eabb
* injection behaviour spy tests run once
Mar 12, 2024
75159fa
Try loading aws-sdk
Mar 12, 2024
49f7c63
Remove loading aws-sdk, make stateMachineArn a string literal
Mar 12, 2024
f95fc9c
idk maybe?
Mar 12, 2024
3bbaa4a
Try to log arguments
Mar 12, 2024
d297f10
enable stepfunctions in localstack
Mar 13, 2024
8e20015
remove console logs
Mar 13, 2024
dbbe143
Log a span
Mar 13, 2024
17470b6
Make the test fail so the log line will print
Mar 13, 2024
247c714
Remove the first expect
Mar 13, 2024
4b6d789
wtf
Mar 13, 2024
684fb49
wtf wtf
Mar 13, 2024
9adf740
Try logging the span now
Mar 13, 2024
01e9f1b
Force the test to fail in a different way
Mar 13, 2024
74bec35
Try moving the expect?
Mar 13, 2024
75c8d98
Try awaiting the agent.use callback
Mar 13, 2024
2e840ea
try checking traces like Jordan said:
Mar 13, 2024
679cbb6
add some parens
Mar 13, 2024
cf26b7d
try moving await client.startExecution
Mar 13, 2024
cadcd0f
Maybe I need to 'register the callback' or some js nonsense first
Mar 13, 2024
c5400ea
Try adding env vars
Mar 13, 2024
a5c070b
try short circuiting isEnables
Mar 13, 2024
3b51167
try calling tracer.init and agent.load like in s3.spec.js
Mar 13, 2024
7eb415b
Apply Jordi's patch
Mar 14, 2024
e3349d1
re-enable isEnabled
Mar 14, 2024
d023cf3
Export stepfunctions as a plugin
Mar 18, 2024
110f484
try adding sfn and states as aliases for stepfunctions
Mar 28, 2024
7011213
Fix integration tests, integration with Smithy client
Apr 15, 2024
bb2337c
Merge
Apr 15, 2024
dd26219
Merge branch 'master' into chris.agocs/inject_trace_context_into_step…
Apr 15, 2024
e0763b0
lint
Apr 15, 2024
cdead80
lint?
Apr 15, 2024
6f0cad9
more linting
Apr 15, 2024
ab77424
revert changes to yarn.lock
Apr 16, 2024
4c42897
move functionality testing to localstack
Apr 17, 2024
7700a33
Remove old import to Stepfunctions
Apr 17, 2024
13914e4
try testing execution input
Apr 22, 2024
78e8e34
Test for trace-id and parent-id in SF input object
Apr 22, 2024
c819350
DescribeExecution and assert the input has trace-id and parent-id
Apr 24, 2024
21971fc
Merge branch 'master' into chris.agocs/inject_trace_context_into_step…
tlhunter Apr 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/plugins.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
majorVersion=$(echo "$version" | cut -d '.' -f 1)
echo "Major Version: $majorVersion"
echo "MAJOR_VERSION=$majorVersion" >> $GITHUB_ENV
- name: Install dependencies and run tests
- name: Install dependencies and run tests
if: env.MAJOR_VERSION == '3'
run: |
apt-get update && \
Expand Down Expand Up @@ -95,7 +95,7 @@ jobs:
echo "Major Version: $majorVersion"
echo "MAJOR_VERSION=$majorVersion" >> $GITHUB_ENV
- uses: ./.github/actions/node/oldest
- name: Install dependencies and run tests
- name: Install dependencies and run tests
if: env.MAJOR_VERSION == '4'
run: |
yarn install --ignore-engines
Expand Down Expand Up @@ -139,7 +139,7 @@ jobs:
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Install dependencies and run tests
- name: Install dependencies and run tests
if: env.MAJOR_VERSION >= '5'
run: |
yarn install --ignore-engines
Expand Down Expand Up @@ -227,7 +227,7 @@ jobs:
localstack:
image: localstack/localstack:3.0.2
env:
LOCALSTACK_SERVICES: dynamodb,kinesis,s3,sqs,sns,redshift,route53,logs,serverless,lambda
LOCALSTACK_SERVICES: dynamodb,kinesis,s3,sqs,sns,redshift,route53,logs,serverless,lambda,stepfunctions,events
EXTRA_CORS_ALLOWED_HEADERS: x-amz-request-id,x-amzn-requestid,x-amz-id-2
EXTRA_CORS_EXPOSE_HEADERS: x-amz-request-id,x-amzn-requestid,x-amz-id-2
AWS_DEFAULT_REGION: us-east-1
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ services:
ports:
- "127.0.0.1:4566:4566" # Edge
environment:
- LOCALSTACK_SERVICES=dynamodb,kinesis,s3,sqs,sns,redshift,route53,logs,serverless,lambda
- LOCALSTACK_SERVICES=dynamodb,kinesis,s3,sqs,sns,redshift,route53,logs,serverless,lambda,stepfunctions,events
- EXTRA_CORS_ALLOWED_HEADERS=x-amz-request-id,x-amzn-requestid,x-amz-id-2
- EXTRA_CORS_EXPOSE_HEADERS=x-amz-request-id,x-amzn-requestid,x-amz-id-2
- AWS_DEFAULT_REGION=us-east-1
Expand Down
5 changes: 4 additions & 1 deletion packages/datadog-instrumentations/src/aws-sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,11 @@ function getChannelSuffix (name) {
'lambda',
'redshift',
's3',
'sfn',
'sns',
'sqs'
'sqs',
'states',
'stepfunctions'
].includes(name)
? name
: 'default'
Expand Down
3 changes: 3 additions & 0 deletions packages/datadog-plugin-aws-sdk/src/services/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ exports.kinesis = require('./kinesis')
exports.lambda = require('./lambda')
exports.redshift = require('./redshift')
exports.s3 = require('./s3')
exports.sfn = require('./sfn')
exports.sns = require('./sns')
exports.sqs = require('./sqs')
exports.states = require('./states')
exports.stepfunctions = require('./stepfunctions')
exports.default = require('./default')
7 changes: 7 additions & 0 deletions packages/datadog-plugin-aws-sdk/src/services/sfn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict'
const Stepfunctions = require('./stepfunctions')
class Sfn extends Stepfunctions {
static get id () { return 'sfn' }
}

module.exports = Sfn
7 changes: 7 additions & 0 deletions packages/datadog-plugin-aws-sdk/src/services/states.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict'
const Stepfunctions = require('./stepfunctions')
class States extends Stepfunctions {
static get id () { return 'states' }
}

module.exports = States
64 changes: 64 additions & 0 deletions packages/datadog-plugin-aws-sdk/src/services/stepfunctions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
'use strict'
const log = require('../../../dd-trace/src/log')
const BaseAwsSdkPlugin = require('../base')

class Stepfunctions extends BaseAwsSdkPlugin {
static get id () { return 'stepfunctions' }

// This is the shape of StartExecutionInput, as defined in
// https://github.com/aws/aws-sdk-js/blob/master/apis/states-2016-11-23.normal.json
// "StartExecutionInput": {
// "type": "structure",
// "required": [
// "stateMachineArn"
// ],
// "members": {
// "stateMachineArn": {
// "shape": "Arn",
// },
// "name": {
// "shape": "Name",
// },
// "input": {
// "shape": "SensitiveData",
// },
// "traceHeader": {
// "shape": "TraceHeader",
// }
// }

generateTags (params, operation, response) {
if (!params) return {}
const tags = { 'resource.name': params.name ? `${operation} ${params.name}` : `${operation}` }
if (operation === 'startExecution' || operation === 'startSyncExecution') {
tags.statemachinearn = `${params.stateMachineArn}`
}
return tags
}

requestInject (span, request) {
const operation = request.operation
if (operation === 'startExecution' || operation === 'startSyncExecution') {
if (!request.params || !request.params.input) {
return
}

const input = request.params.input

try {
const inputObj = JSON.parse(input)
if (inputObj && typeof inputObj === 'object') {
// We've parsed the input JSON string
inputObj._datadog = {}
this.tracer.inject(span, 'text_map', inputObj._datadog)
const newInput = JSON.stringify(inputObj)
request.params.input = newInput
}
Comment on lines +49 to +56
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there nowhere we could do this injection where it's an object rather than a string? It would be nice if we could avoid parsing it only to convert it back to a string right after. 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question! The aws-sdk expects input to be a JSON-parsable string for reasons that baffle me. Unfortunately, we can't guarantee it will ever be an object until we parse it. https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/sfn/command/StartExecutionCommand/

} catch (e) {
log.info('Unable to treat input as JSON')
}
}
}
}

module.exports = Stepfunctions
128 changes: 128 additions & 0 deletions packages/datadog-plugin-aws-sdk/test/stepfunctions.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/* eslint-disable max-len */
'use strict'

const semver = require('semver')
const agent = require('../../dd-trace/test/plugins/agent')
const { setup } = require('./spec_helpers')

const helloWorldSMD = {
Comment: 'A Hello World example of the Amazon States Language using a Pass state',
StartAt: 'HelloWorld',
States: {
HelloWorld: {
Type: 'Pass',
Result: 'Hello World!',
End: true
}
}
}

describe('Sfn', () => {
let tracer

withVersions('aws-sdk', ['aws-sdk', '@aws-sdk/smithy-client'], (version, moduleName) => {
let stateMachineArn
let client

setup()

before(() => {
client = getClient()
})

function getClient () {
const params = { endpoint: 'http://127.0.0.1:4566', region: 'us-east-1' }
if (moduleName === '@aws-sdk/smithy-client') {
const lib = require(`../../../versions/@aws-sdk/client-sfn@${version}`).get()
const client = new lib.SFNClient(params)
return {
client,
createStateMachine: function () {
const req = new lib.CreateStateMachineCommand(...arguments)
return client.send(req)
},
deleteStateMachine: function () {
const req = new lib.DeleteStateMachineCommand(...arguments)
return client.send(req)
},
startExecution: function () {
const req = new lib.StartExecutionCommand(...arguments)
return client.send(req)
},
describeExecution: function () {
const req = new lib.DescribeExecutionCommand(...arguments)
return client.send(req)
}
}
} else {
const { StepFunctions } = require(`../../../versions/aws-sdk@${version}`).get()
const client = new StepFunctions(params)
return {
client,
createStateMachine: function () { return client.createStateMachine(...arguments).promise() },
deleteStateMachine: function () {
return client.deleteStateMachine(...arguments).promise()
},
startExecution: function () { return client.startExecution(...arguments).promise() },
describeExecution: function () { return client.describeExecution(...arguments).promise() }
}
}
}

async function createStateMachine (name, definition, xargs) {
return client.createStateMachine({
definition: JSON.stringify(definition),
name: name,
roleArn: 'arn:aws:iam::123456:role/test',
...xargs
})
}

async function deleteStateMachine (arn) {
return client.deleteStateMachine({ stateMachineArn: arn })
}

describe('Traces', () => {
before(() => {
tracer = require('../../dd-trace')
tracer.use('aws-sdk')
})
// aws-sdk v2 doesn't support StepFunctions below 2.7.10
// https://github.com/aws/aws-sdk-js/blob/5dba638fd/CHANGELOG.md?plain=1#L18
if (moduleName !== 'aws-sdk' || semver.intersects(version, '>=2.7.10')) {
beforeEach(() => { return agent.load('aws-sdk') })
beforeEach(async () => {
const data = await createStateMachine('helloWorld', helloWorldSMD, {})
stateMachineArn = data.stateMachineArn
})

afterEach(() => { return agent.close({ ritmReset: false }) })

afterEach(async () => {
await deleteStateMachine(stateMachineArn)
})

it('is instrumented', async function () {
const startExecInput = {
stateMachineArn,
input: JSON.stringify({ moduleName })
}
const expectSpanPromise = agent.use(traces => {
const span = traces[0][0]
expect(span).to.have.property('resource', 'startExecution')
expect(span.meta).to.have.property('statemachinearn', stateMachineArn)
})

const resp = await client.startExecution(startExecInput)

const result = await client.describeExecution({ executionArn: resp.executionArn })
const sfInput = JSON.parse(result.input)
expect(sfInput).to.have.property('_datadog')
expect(sfInput._datadog).to.have.property('x-datadog-trace-id')
expect(sfInput._datadog).to.have.property('x-datadog-parent-id')
return expectSpanPromise.then(() => {})
})
}
})
})
})
4 changes: 4 additions & 0 deletions packages/dd-trace/test/plugins/externals.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
"name": "@aws-sdk/client-s3",
"versions": [">=3"]
},
{
"name": "@aws-sdk/client-sfn",
"versions": [">=3"]
},
{
"name": "@aws-sdk/client-sns",
"versions": [">=3"]
Expand Down