2.1.0 Instrument X-Ray

0. Learning Materials

Task List

Env variables

Micro service
Variables

backend

  • HONEYCOMB_API_KEY

  • OTEL_SERVICE_NAME

  • OTEL_EXPORTER_OTLP_ENDPOINT

  • OTEL_EXPORTER_OTLP_HEADERS

  • AWS_XRAY_URL

  • AWS_XRAY_DAEMON_ADDRESS

x-ray daemon

  • AWS_ACCESS_KEY_ID

  • AWS_SECRET_ACCESS_KEY

  • AWS_REGION


1. Workflow

1.1 Install AWS SDK

  • Install AWS SDK.

  • Then run:

    • pip install -r requirements.txt

  • Create a json file for samling rules.

    • This is necessary because the X-Ray tracing can become expensive very quickly so we are reducing the amount of tgracing analysis by sampling only a limited amount.

1.2 Add X-ray daemon to DC (Docker Compose)

  • line 9: run xray on port 2000.

    • -o: local mode. 🍁 By default, X-Ray thinks that it's running on an AWS EC2 instance and tries to grab the metadata from the instance. The -o tag instructs X-ray to not check for EC2 instance metadata.

    • -b: Overrides default UDP address (127.0.0.1:2000).

1.2.1 Add backend variables in DC

Every time we add a container definition to the docker-compose file or we use env variables in the code base, it is important to add the env variables in the docker-compose file.

  • We can commit the implementation at this point.

1.2 Troubleshooting

The Docker container seems to be running. Inside the contianer, I find that the AWS credentials are not correctly injected into the container.
I get no data on X-Ray console. Something must be wrong.
No credentials provided
Hardcoded the credential values into the docker-compose file did the magic (This is a very poor thing to do in terms of security. I'm doing it this way only because I'm testing things out!).
The span data are coming through to X-ray on AWS Cloud.

2. Discussion

2.1 AWS X-Ray

  • In our Bootcamp context, this X-ray is another container running alongside our application (the other containers - backend-flask, frontend-react-js, dynamodb-local, and db).

  • X-Ray collects the data from our local machine, and send them in batches to AWS using the AWS APIs.

2.2 Middleware

Last updated