Tracing for Amazon API Gateway is in Preview

This feature is in Preview.

Datadog APM supports tracing for API Gateway when API Gateway proxies requests to applications running in Fargate or EC2.

Prerequisites

  • Amazon API Gateway is configured on your environment. Datadog recommends testing on a development environment before releasing to production.
  • The API Gateway is using the REST API (V1) option. The HTTP API (V2) is not supported.
  • Your underlying application is running a supported web framework.

Supported versions and web frameworks

RuntimeDatadog TracerTracer versionFrameworks
Node.jsdd-trace-jsv4.50.0+ or v5.26.0+express, fastify, hapi, koa, microgateway-core, next, paperplane, restify, router, apollo
Godd-trace-gov1.72.1+chi, httptreemux, echo, go-restful, fiber, gin, gorilla mux, httprouter, fasthttp, goji
Pythondd-trace-pyv3.1.0+aiohttp, asgi, bottle, cherrypy, django, djangorestframework, falcon, fastapi, flask, molten, pyramid, sanic, starlette, tornado, wsgi

Setup

To see inferred spans for Amazon API Gateway, complete the following steps:

  1. Ensure you are using a supported version of the Datadog tracer.

  2. Where your application container is deployed, set the environment variable:

    DD_TRACE_INFERRED_PROXY_SERVICES_ENABLED=true
    
  3. Add headers and related mappings to Amazon API Gateway. API Gateway must pass the following headers in the request for the tracer to create the inferred span:

    headervalue
    x-dd-proxy'aws-apigateway'
    x-dd-proxy-request-time-mscontext.requestTimeEpoch
    x-dd-proxy-domain-namecontext.domainName
    x-dd-proxy-httpmethodcontext.httpMethod
    x-dd-proxy-pathcontext.path
    x-dd-proxy-stagecontext.stage

    To pass in these headers, you can use the AWS CDK or AWS Console.

    To deploy API Gateway with the AWS CDK, add the headers under requestParameters and use $context variables:

    const resource = api.root.addResource('myresource');
     resource.addMethod('ANY', new apigateway.Integration({
       # other configurations
       options: {
         # other options
         requestParameters: {
           "integration.request.header.x-dd-proxy": "'aws-apigateway'",
           "integration.request.header.x-dd-proxy-request-time-ms": "context.requestTimeEpoch",
           "integration.request.header.x-dd-proxy-domain-name": "context.domainName",
           "integration.request.header.x-dd-proxy-httpmethod": "context.httpMethod",
           "integration.request.header.x-dd-proxy-path": "context.path",
           "integration.request.header.x-dd-proxy-stage": "context.stage",
         }
       }
     })
     # other settings here
     });
    
    1. In the AWS Management Console, navigate to API Gateway and go to your API’s Resources page.

    2. Go to Integration request and click Edit.

    3. Under Edit integration request, scroll down to URL request headers parameters. Click Add request header parameter.

    Your HTTP headers for your API in API Gateway, after you have added all six header parameters.

Further Reading

PREVIEWING: cswatt/aws-api-gateway