Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/bpschmitt/otel-python-demo

A simple Python demo app instrumented with OpenTelemetry
https://github.com/bpschmitt/otel-python-demo

Last synced: 12 days ago
JSON representation

A simple Python demo app instrumented with OpenTelemetry

Awesome Lists containing this project

README

        

# otel-python-demo
In this repo, you'll find a simple Python demo app instrumented with OpenTelemetry based on the Python [Getting Started](https://opentelemetry.io/docs/languages/python/getting-started/) guide. This app provides a easy-to-use, lightweight way to familiarize yourself with running OpenTelemetry instrumented microservices running in a Kubernetes cluster.

The OpenTelemetry Collector is configured to send telemetry data to your New Relic account where you can easily visualize Metrics, Traces, and Logs in a single, integrated platform.

# Prerequisites

- Access to a Kubernetes Cluster
- A New Relic account [Click here to sign up for FREE!](https://newrelic.com/signup)
- kubectl
- helm

# Getting Started

### Create a secret for your New Relic License Key

The OpenTelemetry collector will use your New Relic license key to authenticate with the New Relic platform. In this step, you'll create a secret containing your license key which will then be used in the OpenTelemetry Collector config.

```
export NEW_RELIC_LICENSE_KEY=
kubectl create ns collector && kubectl create secret generic nr-license-key --from-literal=license-key="$NEW_RELIC_LICENSE_KEY" -n collector
```

### Install the OpenTelemetry Collector

Install the OpenTelemetry Collector into your cluster using the [OpenTelemetry Collector Helm Chart](https://github.com/open-telemetry/opentelemetry-helm-charts/tree/main/charts/opentelemetry-collector). The values.yaml file in this repo has been pre-configured to work with your New Relic account.

```
helm repo add open-telemetry https://open-telemetry.github.io/opentelemetry-helm-charts
helm upgrade --install opentelemetry-collector open-telemetry/opentelemetry-collector -f collector/values.yaml -n collector
```

## Installing the Python demo app

The Python app in this repo replicates a simple roll of the dice while tracking the activity using Metrics, Logs, and Traces. The telemetry generated by the app is sent to the OpenTelemery collector where it goes through some minimal processing and then exported to the New Relic platform for visualization.

```
kubectl create ns demo && kubectl apply -f k8s/. -n demo
```
# Validating the data

After logging in to your New Relic account, you should see an APM Entity named `otel-python-rolldice`.

![AllEntities](https://p191.p3.n0.cdn.zight.com/items/d5uj22kw/65177937-7a71-49d6-a230-7e713b992f90.jpg?v=8a4bf087f46058d3a5b8ab6a8c6b6675)

When you click into the `otel-python-rolldice` entity, you are taken to the APM Summary page which provides you with the golden signals for the service.

![APMView](https://p191.p3.n0.cdn.zight.com/items/eDuZeeDj/5da1eb74-5074-4f8f-8ac8-0e02c07adcf0.jpg?v=830070adf14e97b2ff7cc26f13475c04)

From here, you can click into Distributed Tracing to view individual traces for the service.

![Traces](https://p191.p3.n0.cdn.zight.com/items/6qu1XX49/0354530c-15c6-4178-b6c0-798a4fbfa459.jpg?v=995bbc697dac8cda53c69317627307fd)

You can navigate to the Logs related to the service by clicking `Logs` in the left nav.

![Logs](https://p191.p3.n0.cdn.zight.com/items/v1uqBB80/9165d620-36f1-4d5e-befa-88e4be4e8ec2.jpg?v=337b2d2f45816e35e7d0665e5d453f4ak)

And finally, you can view Metrics emitted by the service in the Metrics Explorer. In thi example, you're looking at the count of dice rolls by number rolled.

![Metrics](https://p191.p3.n0.cdn.zight.com/items/nOu2JJxz/be271471-63ad-4788-aa41-f8db4cbc5540.jpg?v=a2c9e1d8c4713736e400fbfa6de4d14c)

# Updating

## Building the Container

After making customizations to the demo app, you'll need to build and push a new container image up to your container registry. Here's an example using Docker, but feel free to adjust based on your own environment.

```
docker buildx build --platform linux/amd64,linux/arm64 ./ -t /otel-python-demo:0.1
```

After building, push the new container up to your registry. Don't forget to update the [container image](https://github.com/bpschmitt/otel-python-demo/blob/main/k8s/deployment.yaml#L19) in the K8s deployment manifest.
```
docker push /otel-python-demo:0.1
```