11

Is there a way to enable X-Ray from the serverless.yml for Lambda functions? I've added the X-Ray permissions in the file:

  iamRoleStatements:
    - Effect: "Allow"
      Resource: "*"
      Action:
        - "xray:*"

But Advanced Tracing still needs to be manually enabled in the AWS console.

Bachman
  • 701
  • 1
  • 6
  • 25

3 Answers3

12

See the serverless documentation:

https://serverless.com/framework/docs/providers/aws/guide/functions/#aws-x-ray-tracing

service: myService

provider:
  name: aws
  runtime: nodejs8.10
  tracing:
    lambda: true

See also tracing for api gateway: https://serverless.com/framework/docs/providers/aws/events/apigateway/#aws-x-ray-tracing

# serverless.yml

provider:
  name: aws
  tracing:
    apiGateway: true
Ulad Kasach
  • 11,558
  • 11
  • 61
  • 87
  • Does the apiGateway option only work if the API gateway is created by the serverless framework? I am trying this and the lambda option works ok, but the API gateway option doesnt work, I build my api gateway with terraform. My stage is created by serverless, so I figured it would work. – berimbolo Nov 26 '20 at 16:19
3

It's in development. If you're unwilling to wait until the official functionality is released, you can install the plugin until it's ready.

Trent Bartlem
  • 2,213
  • 1
  • 13
  • 22
  • 1
    this plugin hasn't been updated for a year and still in beta mode. Does serverless framework support AWS XRay tracing now or this plugin is the only option? – mandar.gokhale Oct 09 '18 at 19:02
  • 1
    it's already released, check serverless AWS document here https://serverless.com/framework/docs/providers/aws/guide/serverless.yml/ – ilumin May 06 '19 at 14:37
0

It is also worth noting that currently X-Ray support is dependent on which type of Aws API is selected. If you chose REST (which by your syntax you did ) X-Ray is supported BUT if someone chooses HTTP it is NOT supported. For reference see https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-vs-rest.html#http-api-vs-rest.differences.monitoring

Rhineb
  • 305
  • 3
  • 12