alex-murashkin / serverless-plugin-tracing Goto Github PK
View Code? Open in Web Editor NEWEnables AWS X-Ray tracing for Serverless
License: MIT License
Enables AWS X-Ray tracing for Serverless
License: MIT License
Error:
{
"errorMessage": "Missing AWS Lambda trace data for X-Ray. Expected _X_AMZN_TRACE_ID to be set.",
"errorType": "Error"
}
Invoked by running: sls invoke local -f activateTrigger --path trigger.json
Is there any way to bypass tracing all together if it is invoked locally?
In release v1.40 the Serverless Framework included support for lambda X-Ray tracing (https://serverless.com/blog/framework-release-v140/) and subsequently in v1.41 also incorporated API Gateway tracing support (https://serverless.com/blog/framework-release-v141/).
Do these SLS releases supersede this plugin, or are there any benefits/implementation advantages of using this plugin over the native features?
Since today I'm receiving these errors when deploying an application with the tracing plugin enabled:
Serverless: Tracing ENABLED for function "func1"
Serverless: Tracing ENABLED for function "func2"
Serverless: Tracing ENABLED for function "func3"
Serverless: Tracing ENABLED for function "func4"
Serverless: Tracing ENABLED for function "func5"
Serverless Error ---------------------------------------
The function could not be updated due to a concurrent update operation.
Get Support --------------------------------------------
Docs: docs.serverless.com
Bugs: github.com/serverless/serverless/issues
Forums: forum.serverless.com
Chat: gitter.im/serverless/serverless
Your Environment Information -----------------------------
OS: linux
Node Version: 8.7.0
Serverless Version: 1.23.0
Any ideas why this is happening? Maybe throttling would help?
P.S: I replaced the func names ;)
Nice plugin. There is a small issue that occurs when a custom name element is used with the serverless functions. In this scenario, Tracing is not set.
It should be a pretty easy fix to check for the 'name' element before calling toggleTracing. Something like:
this.toggleTracing((
service.functions[functionName].name ||
${service.service}-${stage}-${functionName}
),
(service.functions[functionName].tracing === true)
|| (providerLevelTracingEnabled && service.functions[functionName].tracing !== false)
);
Thanks
This is just a question.
Thanks a lot
Hi! Could we configure x-ray groups and annotations using this plugin or any other serverless tool? If no, it will be great feature.
Because of the === true
evaluations it isn't possible to set tracing via options or env variables since they are Strings.
I noticed that for v2.0, you added a comment at the top of the README which states this plugin now enables tracing via CloudFormation, instead of making calls to the AWS sdk.
However, a few lines later in the README, you state that we still need to include the following code:
const awsXRay = require('aws-xray-sdk');
const awsSdk = awsXRay.captureAWS(require('aws-sdk'));
Is that call to captureAWS
still a requirement via code, or just a remnant of previous requirement before v2.0, and should be removed from the README?
Can you please give an example in the README of specifying resources for the iamRoleStatements
clause without a wildcard? Our policies don't allow us to use wildcards, but when I specify the functions explicitly themselves, it is silently not working.
Thanks for your help.
Good Day.
I just noticed that installing npm install --save-dev serverless-plugin-tracing
is not enough to use this plugin.
I have struggled for serveral days to find the way how to run my application without error.
so I just found the cause that aws-xray-sdk
package is not installed in my project.
after I installed aws-xray-sdk
, my project started working well and I can see the Service map
in AWS X-Ray
screen.
Am I only person who have this problem?
I don't know about details but just let you guys know.
Here's my serverless.yml
and handler.js
.
and I am using next.js
and node.js 8
with Koa
.
serverless.yml
service: mom # NOTE: update this with your service name
provider:
name: aws
runtime: nodejs8.10
stage: ${self:custom.stageName}
region: ap-northeast-2
tracing: true # enable tracing
environment:
NODE_PATH: "./:/opt/node_modules"
stageName: ${self:custom.stageName}
iamRoleStatements:
- Effect: "Allow" # xray permissions (required)
Action:
- "xray:PutTraceSegments"
- "xray:PutTelemetryRecords"
Resource:
- "*"
custom:
stageName: NextJS
package:
individually: true
exclude:
- .cache
- .serverless
- .vscode
- serverless.yml
functions:
frontendAdmin:
handler: handler.index
name: ideasam-mom-frontendAdmin # optional, Deployed Lambda name
description: MOM - match admin page # optional, Description to publish to AWS
# environment: ${self:custom.environment}
memorySize: 512
package:
exclude:
- frontend/test
- frontend/"**.test.js"
- frontend/"__snapshots__/"
include:
- frontend/.next/**
events:
# - http:
# path: /admin
# method: get
# cors: true
- http:
path: /admin/{addr+}
method: get
cors: true
layers:
- arn:aws:lambda:ap-northeast-2:***:layer:***:1
...
plugins:
- serverless-offline
- serverless-plugin-tracing
handler.js
'use strict'
const debugging = process.env.DEBUG || process.env.DEBUG === 'true'
let layerPath = ''
if (debugging) {
layerPath = require('./layerPath').layerPath(__dirname.substring(0, __dirname.lastIndexOf('/')))
}
const serverless = require(layerPath + 'serverless-http')
const server = require('./server_koa')
module.exports.index = async (event, context) => {
try {
/**
* @author 박태성
* @name AWS_X-Ray
* @description AWS X-Ray 적용을 위한 코드. 디버깅 모드에서는 지원되지 않음.
aws-xray-sdk를 추가로 인스톨해야 Prod에서 사용 가능.
*/
if (!debugging) {
const awsXRay = require('aws-xray-sdk')
const awsSdk = awsXRay.captureAWS(require('aws-sdk'))
}
const appServer = await server.createServer(event)
return await serverless(appServer)(event, context)
} catch (e) {
console.log('error in handler.js', e)
return {
statusCode: 500,
headers: {
'content-type': 'text/html',
},
body: `
<html>
<body style="margin: 0px; padding: 1rem; background-color: #ff0081;">
<div style="color: #fff;">${e.message}</div>
</body>
</html>
`,
}
}
}
Is there a simple way to get the Trace ID from one function and then pass it to a lambda.invoke() to call a second function, to tie chaining lambdas together?
It would be handy if we could pass a stage variable into this plugin to be enabled only at that stage. Currently, I have to reference an external file in order to check the current stage and return true/false for the tracing
property.
Just a comment, this plugin could be simplified by setting tracing via CloudFormation: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-tracingconfig.html
If I find the will, I might put together a PR. But no promises.
Otherwise, thanks, plugin worked first time.
Seems like in the latest Serverless version(3.19.0), yaml-schema changed for tracing directive (tracing to Tracing ). it is a warning. "DID NOT IMPACT" tracing config
Incorrect type. Expected "Aws.Tracing".yaml-schema: Serverless Framework Configuration
I suspect this happens because of the new schema validation rules put in place in serverless 2.x. Can we just move provider.tracing
to custom.tracing
in the serverless.yml
?
AWS supports X-Ray for API Gateways: https://aws.amazon.com/de/blogs/aws/apigateway-xray/
It would be great to configure the stage property via this serverless plugin.
I could not find any hints if cloudformation supports it yet. At least it is not documented.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.