-
Notifications
You must be signed in to change notification settings - Fork 404
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added entity linking attributes to aws-sdk v3 Lambda segments (#…
…2845) Signed-off-by: mrickard <[email protected]> Co-authored-by: Bob Evans <[email protected]>
- Loading branch information
Showing
5 changed files
with
167 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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,57 @@ | ||
/* | ||
* Copyright 2021 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
'use strict' | ||
const InstrumentationDescriptor = require('../../../instrumentation-descriptor') | ||
|
||
/** | ||
* Defines a deserialize middleware to add the | ||
* cloud.resource_id segment attributes for the AWS command | ||
* | ||
* @param {Shim} shim New Relic agent shim | ||
* @param {Object} config AWS command configuration | ||
* @param {function} next next function in middleware chain | ||
* @returns {function} wrapped version of middleware function | ||
*/ | ||
function resourceIdMiddleware(shim, config, next) { | ||
return async function wrappedResourceIdMiddleware(args) { | ||
let result | ||
try { | ||
const region = await config.region() | ||
result = await next(args) | ||
const { response } = result | ||
const segment = shim.getSegment(response.body.req) | ||
// We can't derive account ID, so we have to consume it from config | ||
const accountId = shim.agent.config.cloud.aws.account_id | ||
const functionName = args?.input?.FunctionName // have to get function from params | ||
if (accountId && functionName) { | ||
segment.addAttribute( | ||
'cloud.resource_id', | ||
`arn:aws:lambda:${region}:${accountId}:function:${functionName}` | ||
) | ||
segment.addAttribute('cloud.platform', `aws_lambda`) | ||
} | ||
} catch (err) { | ||
shim.logger.debug(err, 'Failed to add AWS cloud resource id to segment') | ||
} finally { | ||
return result | ||
} | ||
} | ||
} | ||
|
||
const lambdaMiddlewareConfig = { | ||
middleware: resourceIdMiddleware, | ||
type: InstrumentationDescriptor.TYPE_GENERIC, | ||
config: { | ||
name: 'NewRelicGetResourceId', | ||
step: 'deserialize', | ||
priority: 'low', | ||
override: true | ||
} | ||
} | ||
|
||
module.exports = { | ||
lambdaMiddlewareConfig | ||
} |
This file contains 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 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 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 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