|
1 | | -Readme for examples (temporary file) |
| 1 | + |
| 2 | +# Tracing with AWS Sample Apps |
| 3 | + |
| 4 | +## Overview |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | +This is a getting started guide for the example applications found in the AWS contrib folder. This walkthrough covers prerequisite, installations, how to run the applications, and viewing the traces on X-Ray. Before reading this guide, you should familiarize with distributed tracing and the basics of OpenTelemetry. To learn more about getting started with OpenTelemetry PHP, see the OpenTelemetry developer documentation. |
| 9 | + |
| 10 | +## About the Sample Apps |
| 11 | + |
| 12 | +Currently, the ability to instrument an application automatically does not exist, so manually instrumenting the apps was necessary. In both of the applications, creation of a tracer, generation of spans, propagation of contexts, and closing spans was implemented manually. Both of these applications are console applications that export trace data to the OTEL Collector which is then exported to AWS X-Ray. |
| 13 | + |
| 14 | +### Sample App 1 |
| 15 | + |
| 16 | +The first sample app in its implementation is creation of a span, then a child span, which is then populated in an HTTP header that makes a request to either aws.amazon.com (http://aws.amazon.com/) or the AWS SDK. The application will prompt you for input on which action you would like to take, and subsequently prints out the trace ID. |
| 17 | + |
| 18 | +### Sample App 2 |
| 19 | + |
| 20 | +The second application is a more robust example of how a real-world application may make a request to different services. A main application will make a call to two different microservices called Service1 and Service2. Before calling either of the services, the span context is injected into a carrier that is then taken to the service. Then, the services will extract the context from the carrier and create a new span based upon it. After the services are concluded, the child spans are ended and then the main root span is ended in the main application. |
| 21 | + |
| 22 | +## Prerequisites |
| 23 | + |
| 24 | +The following downloads are necessary for running either of the above specified applications. The two repositories below can be downloaded anywhere on your machine. If you are having an issue with not being able to access the collector with your credentials, clone the aws-otel-collector in your root directory. |
| 25 | + |
| 26 | +Download Docker here: https://docs.docker.com/get-docker/ |
| 27 | + |
| 28 | +Clone locally the opentelemetry-php-contrib here: https://github.com/open-telemetry/opentelemetry-php-contrib |
| 29 | + |
| 30 | +Clone locally the aws-otel-collector here: https://github.com/aws-observability/aws-otel-collector |
| 31 | + |
| 32 | +## Set Up |
| 33 | + |
| 34 | +### Docker |
| 35 | + |
| 36 | +Make sure Docker Desktop is running. |
| 37 | + |
| 38 | +### AWS Access Keys |
| 39 | + |
| 40 | +Now make sure that your AWS access keys are configured in your root directory. To see if your credentials are setup run the following command: |
| 41 | + |
| 42 | +`cat .aws/credentials` |
| 43 | + |
| 44 | +If they are not configured, please visit [here](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html) for instructions on how to set them up. |
| 45 | + |
| 46 | +### Grpc Installation |
| 47 | + |
| 48 | +In your root directory, run the following commands. These commands will take a while to install all the necessary components. |
| 49 | + |
| 50 | +`brew install PHP` |
| 51 | + |
| 52 | +`sudo pecl install grpc` |
| 53 | + |
| 54 | +If you are having issues please visit one of these resources: |
| 55 | + |
| 56 | +- https://github.com/grpc/grpc/tree/master/src/php |
| 57 | +- https://grpc.io/docs/languages/php/quickstart/ |
| 58 | + |
| 59 | +### Composer |
| 60 | + |
| 61 | +To check if you have composer installed, run the following command in your root directory: |
| 62 | + |
| 63 | +`composer -V` |
| 64 | + |
| 65 | +If the above does not work, please visit [here](https://getcomposer.org/download/) to install Composer. There are two methods, programmatically or manual file download. Please choose whichever way you prefer and then move the composer.phar file to your `$PATH` with the following command: |
| 66 | + |
| 67 | +`mv composer.phar /usr/local/bin/composer` |
| 68 | + |
| 69 | +### Update Repository Packages and Dependencies |
| 70 | + |
| 71 | +In the php contrib repository, run the following four commands: |
| 72 | + |
| 73 | +`make install` |
| 74 | + |
| 75 | +Then run to make sure all dependencies and packages are up to date: |
| 76 | + |
| 77 | +`make update` |
| 78 | + |
| 79 | +Then run the following command to make sure the local composer is updated: |
| 80 | + |
| 81 | +`composer update` |
| 82 | + |
| 83 | +To make sure everything is working properly, run the following command to run all tests: |
| 84 | + |
| 85 | +`make install && make update && make style && make test && make phan && make psalm && make phpstan` |
| 86 | + |
| 87 | +At this point all necessary items have been installed in your system and you are ready to begin running the application. |
| 88 | + |
| 89 | +## Running the Applications |
| 90 | + |
| 91 | +### Run Collector |
| 92 | + |
| 93 | +Open a new terminal window and navigate into the aws-otel-collector folder. |
| 94 | + |
| 95 | +Run the following command. Make sure to replace `YOUR_ACCESS_KEY_HERE` and `YOUR_SECRET_ACCESS_KEY_HERE` with your own specific keys. |
| 96 | + |
| 97 | +```console |
| 98 | +docker run --rm -p 4317:4317 -p 55681:55681 -p 8889:8888 \ |
| 99 | + -e AWS_REGION=us-west-2 \ |
| 100 | + -e AWS_ACCESS_KEY_ID=YOUR_ACCESS_KEY_HERE \ |
| 101 | + -e AWS_SECRET_ACCESS_KEY=YOUR_SECRET_ACCESS_KEY_HERE \ |
| 102 | + -v "${PWD}/examples/docker/config-test.yaml":/otel-local-config.yaml \ |
| 103 | + --name awscollector public.ecr.aws/aws-observability/aws-otel-collector:latest \ |
| 104 | + --config otel-local-config.yaml |
| 105 | +``` |
| 106 | + |
| 107 | +In another terminal window, navigate to the opentelemetry-php-contrib folder. |
| 108 | + |
| 109 | +Run the following command for Sample App 1: |
| 110 | + |
| 111 | +`php examples/aws/SampleApp1/SampleApp1.php` |
| 112 | + |
| 113 | +The output for this app should look similar to the following: |
| 114 | + |
| 115 | +```console |
| 116 | +Starting Sample App |
| 117 | +Which call would you like to make? |
| 118 | +Type outgoing-http-call or aws-sdk-call |
| 119 | +outgoing-http-call |
| 120 | +Final trace ID: {"traceId":"1-6115648a-d40b50a270b3c1249bcf60c2"} |
| 121 | +Sample App complete! |
| 122 | +``` |
| 123 | + |
| 124 | +Currently the `aws-sdk-call` option is commented out. This is due to dependency conflicts between AWS and the PHP Library. If you would like to enable it, follow the instructions in the comments of the SampleApp1.php file. |
| 125 | + |
| 126 | +Run the following command for Sample App 2: |
| 127 | + |
| 128 | +`php examples/aws/SampleApp2/SampleApp2.php` |
| 129 | + |
| 130 | +The output for this app should look similar to the following: |
| 131 | + |
| 132 | +```console |
| 133 | +Starting Sample App |
| 134 | +Child span trace ID after service 2: {"traceId":"1-6115649a-230ef2ffe1d289a056b8d0ea"} |
| 135 | +Sample App complete! |
| 136 | +``` |
| 137 | + |
| 138 | +The trace IDs in any sample app will be completely unique. The first number is the version, the second section is the timestamp, and the last section is a randomized hexadecimal string. |
| 139 | + |
| 140 | +## Viewing Traces on AWS X-Ray |
| 141 | + |
| 142 | +Navigate to AWS X-Ray on your internet browser. |
| 143 | + |
| 144 | +Click on the traces tab on the left hand side, like the image below: |
| 145 | + |
| 146 | +<img width="1755" alt="Screen Shot 2021-08-12 at 11 22 23 AM" src="https://user-images.githubusercontent.com/46689344/129248717-a9fd9137-0ed5-4498-9cfb-8e3ba1a57fbe.png"> |
| 147 | + |
| 148 | +Make sure your region is set to us-west-2: |
| 149 | + |
| 150 | +<img width="291" alt="Screen Shot 2021-08-12 at 11 21 59 AM" src="https://user-images.githubusercontent.com/46689344/129248725-d3f7a655-fe3b-47d4-a229-583365e16a54.png"> |
| 151 | + |
| 152 | +After running the sample app, there should be traces under the traces tab with all relevant information. |
| 153 | + |
| 154 | +<img width="1398" alt="Screen Shot 2021-08-09 at 11 42 50 PM" src="https://user-images.githubusercontent.com/46689344/129248704-0888b387-2fa8-4753-824e-d99e0c9a67b6.png"> |
0 commit comments