-
Notifications
You must be signed in to change notification settings - Fork 238
feat: implment awk-sdk v2 dynamodb instrumentation #2128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
911e789
feat: initial instrumentation
ac9b43e
test: in progress
ba9f494
fix: remove console.log
a94f935
Merge branch 'master' into astorm/dynamo-db
c930448
test: integartion tests
bedc992
Merge branch 'master' into astorm/dynamo-db
astorm 8e999bd
fix: error state test
ac1aeea
test: test second API method
a0d4f52
docs: add dynamodb to list
19c9f22
test: update tav
1f25db6
Merge branch 'master' into astorm/dynamo-db
astorm 883970c
test: different default configuration
93f36eb
fix: move fixtures
de5afd8
fix: whitespace
7ca40d1
fix: pin 2.858 as lowest version to test
7c66640
fix: PR feedback
d7afe99
fix: fixtures
c8b3ecc
Merge branch 'master' into astorm/dynamo-db
astorm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| 'use strict' | ||
| const constants = require('../../../constants') | ||
| const TYPE = 'db' | ||
| const SUBTYPE = 'dynamodb' | ||
| const ACTION = 'query' | ||
|
|
||
| function getRegionFromRequest (request) { | ||
| return request && request.service && | ||
| request.service.config && request.service.config.region | ||
| } | ||
|
|
||
| function getPortFromRequest (request) { | ||
| return request && request.service && | ||
| request.service.endpoint && request.service.endpoint.port | ||
| } | ||
|
|
||
| function getMethodFromRequest (request) { | ||
| const method = request && request.operation | ||
| if (method) { | ||
| return method[0].toUpperCase() + method.slice(1) | ||
| } | ||
| } | ||
|
|
||
| function getStatementFromRequest (request) { | ||
| const method = getMethodFromRequest(request) | ||
| if (method === 'Query' && request && request.params && request.params.KeyConditionExpression) { | ||
| return request.params.KeyConditionExpression | ||
| } | ||
| return undefined | ||
| } | ||
|
|
||
| function getAddressFromRequest (request) { | ||
| return request && request.service && request.service.endpoint && | ||
| request.service.endpoint.hostname | ||
| } | ||
|
|
||
| function getTableFromRequest (request) { | ||
| const table = request && request.params && request.params.TableName | ||
astorm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (!table) { | ||
| return '' | ||
| } | ||
| return ` ${table}` | ||
| } | ||
|
|
||
| // Creates the span name from request information | ||
| function getSpanNameFromRequest (request) { | ||
| const method = getMethodFromRequest(request) | ||
| const table = getTableFromRequest(request) | ||
| const name = `DynamoDB ${method}${table}` | ||
| return name | ||
| } | ||
|
|
||
| function shouldIgnoreRequest (request, agent) { | ||
| return false | ||
| } | ||
|
|
||
| // Main entrypoint for SQS instrumentation | ||
| // | ||
| // Must call (or one of its function calls must call) the | ||
| // `orig` function/method | ||
| function instrumentationDynamoDb (orig, origArguments, request, AWS, agent, { version, enabled }) { | ||
| if (shouldIgnoreRequest(request, agent)) { | ||
| return orig.apply(request, origArguments) | ||
| } | ||
|
|
||
| const type = TYPE | ||
| const subtype = SUBTYPE | ||
| const action = ACTION | ||
|
|
||
| const name = getSpanNameFromRequest(request) | ||
| const span = agent.startSpan(name, type, subtype, action) | ||
| if (!span) { | ||
| return orig.apply(request, origArguments) | ||
| } | ||
|
|
||
| span.setDbContext({ | ||
| instance: getRegionFromRequest(request), | ||
| statement: getStatementFromRequest(request), | ||
| type: SUBTYPE | ||
| }) | ||
| span.setDestinationContext({ | ||
| address: getAddressFromRequest(request), | ||
| port: getPortFromRequest(request), | ||
| service: { | ||
| name: SUBTYPE, | ||
| type: 'db', | ||
| resource: SUBTYPE | ||
| }, | ||
| cloud: { | ||
| region: getRegionFromRequest(request) | ||
| } | ||
| }) | ||
|
|
||
| request.on('complete', function (response) { | ||
| if (response && response.error) { | ||
| const errOpts = { | ||
| skipOutcome: true | ||
| } | ||
| agent.captureError(response.error, errOpts) | ||
| span._setOutcomeFromErrorCapture(constants.OUTCOME_FAILURE) | ||
astorm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| // Workaround a bug in the agent's handling of `span.sync`. | ||
| // | ||
| // The bug: Currently this span.sync is not set `false` because there is | ||
| // an HTTP span created (for this S3 request) in the same async op. That | ||
| // HTTP span becomes the "active span" for this async op, and *it* gets | ||
| // marked as sync=false in `before()` in async-hooks.js. | ||
| span.sync = false | ||
| span.end() | ||
| }) | ||
|
|
||
| return orig.apply(request, origArguments) | ||
| } | ||
|
|
||
| module.exports = { | ||
| instrumentationDynamoDb, | ||
|
|
||
| // exported for testing | ||
| getRegionFromRequest, | ||
| getPortFromRequest, | ||
| getStatementFromRequest, | ||
| getAddressFromRequest, | ||
| getMethodFromRequest | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.