|
| 1 | +# Tracing on Amazon EKS |
| 2 | + |
| 3 | +[Distributed tracing](https://aws-observability.github.io/observability-best-practices/signals/traces/) |
| 4 | +helps you have end-to-end visibility between transactions in distributed nodes. |
| 5 | +The `eks-monitoring` module is configured by default to collect traces into |
| 6 | +[AWS X-Ray](https://docs.aws.amazon.com/xray/latest/devguide/aws-xray.html). |
| 7 | + |
| 8 | +The AWS Distro for OpenTelemetry collector is configured to receive traces |
| 9 | +in the OTLP format (OTLP receiver), using the OpenTelemetry SDK or |
| 10 | +auto-instrumentation agents. |
| 11 | + |
| 12 | +!!! note |
| 13 | + To disable the tracing configuration, set up `enable_tracing = false` in |
| 14 | + the [module configuration](https://github.com/aws-observability/terraform-aws-observability-accelerator/tree/main/modules/eks-monitoring#input_enable_tracing) |
| 15 | + |
| 16 | + |
| 17 | +## Instrumentation |
| 18 | + |
| 19 | +Let's take a [sample application](https://github.com/aws-observability/aws-otel-community/tree/master/sample-apps/go-sample-app) |
| 20 | +that is already instrumented with the OpenTelemetry SDK. |
| 21 | + |
| 22 | +!!! note |
| 23 | + To learn more about instrumenting with OpenTelemetry, please visit the |
| 24 | + [OpenTelemetry documentation](https://opentelemetry.io/docs/instrumentation/) |
| 25 | + for your programming language. |
| 26 | + |
| 27 | +Cloning the repo |
| 28 | + |
| 29 | +```console |
| 30 | +git clone https://github.com/aws-observability/aws-otel-community.git |
| 31 | +cd aws-otel-community/sample-apps/go-sample-app |
| 32 | +``` |
| 33 | + |
| 34 | + |
| 35 | +Highlighting code sections |
| 36 | + |
| 37 | + |
| 38 | +## Deploying on Amazon EKS |
| 39 | + |
| 40 | +Using the sample application, we will build a container image, create and push |
| 41 | +an image on Amazon ECR. We will use a Kubernetes manifest to deploy to an EKS |
| 42 | +cluster. |
| 43 | + |
| 44 | +!!! warning |
| 45 | + The following steps require that you have an EKS cluster ready. To deploy |
| 46 | + an EKS cluster, please visit [our example](https://aws-observability.github.io/terraform-aws-observability-accelerator/helpers/new-eks-cluster/). |
| 47 | + |
| 48 | +### Building container image |
| 49 | + |
| 50 | + |
| 51 | +=== "amd64 linux" |
| 52 | + |
| 53 | + ``` console |
| 54 | + docker build -t go-sample-app . |
| 55 | + ``` |
| 56 | + |
| 57 | +=== "cross platform build" |
| 58 | + |
| 59 | + ``` bash |
| 60 | + docker buildx build -t go-sample-app . --platform=linux/amd64 |
| 61 | + ``` |
| 62 | + |
| 63 | +### Publishing on Amazon ECR |
| 64 | + |
| 65 | + |
| 66 | +=== "using docker" |
| 67 | + |
| 68 | + ``` console |
| 69 | + export ECR_REPOSITORY_URI=$(aws ecr create-repository --repository go-sample-app --query repository.repositoryUri --output text) |
| 70 | + aws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin $ECR_REPOSITORY_URI |
| 71 | + docker tag go-sample-app:latest "${ECR_REPOSITORY_URI}:latest" |
| 72 | + docker push "${ECR_REPOSITORY_URI}:latest" |
| 73 | + ``` |
| 74 | + |
| 75 | + |
| 76 | +## Deploying on Amazon EKS |
| 77 | + |
| 78 | + |
| 79 | +``` yaml title="eks.yaml" linenums="1" |
| 80 | +apiVersion: apps/v1 |
| 81 | +kind: Deployment |
| 82 | +metadata: |
| 83 | + name: go-sample-app |
| 84 | + namespace: default |
| 85 | +spec: |
| 86 | + replicas: 2 |
| 87 | + selector: |
| 88 | + matchLabels: |
| 89 | + app: go-sample-app |
| 90 | + template: |
| 91 | + metadata: |
| 92 | + labels: |
| 93 | + app: go-sample-app |
| 94 | + spec: |
| 95 | + containers: |
| 96 | + - name: go-sample-app |
| 97 | + image: "${ECR_REPOSITORY_URI}:latest" # make sure to replace this variable |
| 98 | + imagePullPolicy: Always |
| 99 | + env: |
| 100 | + - name: OTEL_EXPORTER_OTLP_TRACES_ENDPOINT |
| 101 | + value: adot-collector.adot-collector-kubeprometheus.svc.cluster.local:4317 |
| 102 | + resources: |
| 103 | + limits: |
| 104 | + cpu: 300m |
| 105 | + memory: 300Mi |
| 106 | + requests: |
| 107 | + cpu: 100m |
| 108 | + memory: 180Mi |
| 109 | + ports: |
| 110 | + - containerPort: 8080 |
| 111 | +--- |
| 112 | +apiVersion: v1 |
| 113 | +kind: Service |
| 114 | +metadata: |
| 115 | + name: go-sample-app |
| 116 | + namespace: default |
| 117 | + labels: |
| 118 | + app: go-sample-app |
| 119 | +spec: |
| 120 | + ports: |
| 121 | + - protocol: TCP |
| 122 | + port: 8080 |
| 123 | + targetPort: 8080 |
| 124 | + selector: |
| 125 | + app: go-sample-app |
| 126 | +--- |
| 127 | +apiVersion: v1 |
| 128 | +kind: Service |
| 129 | +metadata: |
| 130 | + name: go-sample-app |
| 131 | + namespace: default |
| 132 | +spec: |
| 133 | + type: ClusterIP |
| 134 | + selector: |
| 135 | + app: go-sample-app |
| 136 | + ports: |
| 137 | + - protocol: TCP |
| 138 | + port: 8080 |
| 139 | + targetPort: 8080 |
| 140 | +``` |
| 141 | +
|
| 142 | +### Deploying and testing |
| 143 | +
|
| 144 | +With the Kubernetes manifest ready, run: |
| 145 | +
|
| 146 | +```bash |
| 147 | +kubectl apply -f eks.yaml |
| 148 | +``` |
| 149 | + |
| 150 | +You should see the pods running with the command: |
| 151 | + |
| 152 | +```console |
| 153 | +kubectl get pods |
| 154 | +NAME READY STATUS RESTARTS AGE |
| 155 | +go-sample-app-67c48ff8c6-bdw74 1/1 Running 0 4s |
| 156 | +go-sample-app-67c48ff8c6-t6k2j 1/1 Running 0 4s |
| 157 | +``` |
| 158 | + |
| 159 | +To simulate some traffic you can forward the service port to your local host |
| 160 | +and test a few queries |
| 161 | + |
| 162 | +```console |
| 163 | +kubectl port-forward deployment/go-sample-app 8080:8080 |
| 164 | +``` |
| 165 | + |
| 166 | +Test a few endpoints |
| 167 | + |
| 168 | +``` |
| 169 | +curl http://localhost:8080/ |
| 170 | +curl http://localhost:8080/outgoing-http-call |
| 171 | +curl http://localhost:8080/aws-sdk-call |
| 172 | +curl http://localhost:8080/outgoing-sampleapp |
| 173 | +``` |
| 174 | + |
| 175 | +## Visualizing traces |
| 176 | + |
| 177 | +As this is a basic example, the service map doesn't have a lot of nodes, |
| 178 | +but this shows you how to setup tracing in your application and deploying |
| 179 | +it on Amazon EKS using the `eks-monitoring` module. |
| 180 | + |
| 181 | +With Flux and Grafana Operator, the `eks-monitoring` module configures |
| 182 | +an AWS X-Ray data source on your provided Grafana workspace. Open the |
| 183 | +Grafana explorer view and select the X-Ray data source. If you type the query |
| 184 | +below, and select `Trace List` for **Query Type**, you should see the list |
| 185 | +of traces occured in the selected timeframe. |
| 186 | + |
| 187 | +<img width="1721" alt="Screenshot 2023-07-20 at 21 42 30" src="https://github.com/aws-observability/terraform-aws-observability-accelerator/assets/10175027/bd992a77-05fb-47d2-8ed4-af05d96e951d"> |
| 188 | + |
| 189 | +You can add the service map to a dashbaord, for example a service focused |
| 190 | +dashbaord. You can click on any of the traces to view a node map and the traces |
| 191 | +details. |
| 192 | + |
| 193 | +There is a button that can take you the CloudWatch console to view the same |
| 194 | +data. If your logs are stored on CloudWatch Logs, this page can present |
| 195 | +all the logs in the trace details page. The CloudWatch Log Group name should |
| 196 | +be added to the trace as an attribute. |
| 197 | +Read more about this in our [One Observability Workshop](https://catalog.workshops.aws/observability/en-US/use-cases/trace-to-logs-java-instrumentation/concepts) |
| 198 | + |
| 199 | + |
| 200 | + |
| 201 | + |
| 202 | +## Resoures |
| 203 | + |
| 204 | +- [AWS Observability Best Practices](https://aws-observability.github.io/observability-best-practices/) |
| 205 | +- [One Observability Workshop](https://catalog.workshops.aws/observability/en-US/) |
| 206 | +- [AWS Distro for OpenTelemetry documentation](https://aws-otel.github.io/docs/introduction) |
| 207 | +- [AWS X-Ray user guide](https://docs.aws.amazon.com/xray/latest/devguide/aws-xray.html) |
| 208 | +- [OpenTelemetry documentation](https://opentelemetry.io/docs/what-is-opentelemetry/) |
0 commit comments