-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
166757a
commit dd10b81
Showing
11 changed files
with
111 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
.idea | ||
venv/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
FROM python:alpine3.19 | ||
|
||
WORKDIR /app | ||
|
||
COPY requirements.txt . | ||
|
||
# How to get the requirements.txt file? | ||
# 1. Follow https://opentelemetry.io/docs/languages/python/getting-started/ | ||
# 2. Run `pip freeze > requirements.txt` in the same directory as your app.py file | ||
RUN pip install -r requirements.txt | ||
|
||
RUN pip install opentelemetry-distro[otlp] | ||
RUN opentelemetry-bootstrap -a install | ||
|
||
COPY app.py . | ||
|
||
# Logging support is still in alpha, so we need to enable it explicitly | ||
ENV OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED=true | ||
|
||
EXPOSE 8082 | ||
|
||
CMD ["opentelemetry-instrument", "flask", "run", "--host", "0.0.0.0", "--port", "8082"] | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from random import randint | ||
from flask import Flask, request | ||
import logging | ||
|
||
app = Flask(__name__) | ||
logging.basicConfig(level=logging.INFO) | ||
logger = logging.getLogger(__name__) | ||
|
||
|
||
@app.route("/rolldice") | ||
def roll_dice(): | ||
player = request.args.get('player', default=None, type=str) | ||
result = str(roll()) | ||
if player: | ||
logger.warning("%s is rolling the dice: %s", player, result) | ||
else: | ||
logger.warning("Anonymous player is rolling the dice: %s", result) | ||
return result | ||
|
||
|
||
def roll(): | ||
return randint(1, 6) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# OATS is an acceptance testing framework for OpenTelemetry - https://github.com/grafana/oats/tree/main/yaml | ||
version: '3.4' | ||
|
||
services: | ||
go: | ||
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
environment: | ||
OTEL_EXPORTER_OTLP_ENDPOINT: http://collector:4318 | ||
OTEL_METRIC_EXPORT_INTERVAL: "5000" # so we don't have to wait 60s for metrics | ||
ports: | ||
- "8080:8082" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# OATS is an acceptance testing framework for OpenTelemetry - https://github.com/grafana/oats/tree/main/yaml | ||
docker-compose: | ||
generator: lgtm | ||
files: | ||
- ./docker-compose.oats.yml | ||
input: | ||
- path: /rolldice | ||
expected: | ||
traces: | ||
- traceql: '{ span.http.route = "/rolldice" }' | ||
spans: | ||
- name: '/rolldice' # should be "GET /rolldice" | ||
attributes: | ||
otel.library.name: opentelemetry.instrumentation.flask | ||
metrics: | ||
- promql: 'http_server_active_requests{http_method="GET"}' | ||
value: ">= 0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
blinker==1.7.0 | ||
click==8.1.7 | ||
Flask==2.3.3 | ||
itsdangerous==2.1.2 | ||
Jinja2==3.1.3 | ||
MarkupSafe==2.1.5 | ||
Werkzeug==2.3.8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/bin/bash | ||
|
||
set -euo pipefail | ||
|
||
export OTEL_METRIC_EXPORT_INTERVAL="5000" # so we don't have to wait 60s for metrics | ||
export OTEL_RESOURCE_ATTRIBUTES="service.name=rolldice,service.instance.id=localhost:8082" | ||
export OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED=true | ||
|
||
python3 -m venv venv | ||
source ./venv/bin/activate | ||
|
||
# How to get the requirements.txt file? | ||
# 1. Follow https://opentelemetry.io/docs/languages/python/getting-started/ | ||
# 2. Run `pip freeze > requirements.txt` in the same directory as your app.py file | ||
pip install -r requirements.txt | ||
|
||
pip install opentelemetry-distro[otlp] | ||
opentelemetry-bootstrap -a install | ||
|
||
opentelemetry-instrument flask run -p 8082 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
#!/bin/bash | ||
|
||
watch 'curl -s http://localhost:8080/rolldice; curl -s http://localhost:8081/rolldice' | ||
watch 'curl -s http://localhost:8080/rolldice; curl -s http://localhost:8081/rolldice; curl -s http://localhost:8082/rolldice' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
|
||
docker run -p 3000:3000 -p 4317:4317 -p 4318:4318 --rm -ti grafana/otel-lgtm |