From 0f39624765c313611814bb8885e038efed1cd293 Mon Sep 17 00:00:00 2001 From: Drew Bednar Date: Tue, 13 Feb 2024 14:47:51 -0500 Subject: [PATCH] Add opentelemtry distro --- dev-requirements.txt | 1 + learn_otel/app.py | 24 ++++++++++++++++++++++++ learn_otel/example.py | 5 ----- requirements.in | 2 ++ requirements.txt | 32 ++++++++++++++++++++++++++++++++ tasks.py | 7 ++++++- 6 files changed, 65 insertions(+), 6 deletions(-) create mode 100644 learn_otel/app.py delete mode 100644 learn_otel/example.py diff --git a/dev-requirements.txt b/dev-requirements.txt index c2940ff..dd47d72 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -39,6 +39,7 @@ nodeenv==1.8.0 # via pre-commit packaging==23.2 # via + # -c ./requirements.txt # black # build # pytest diff --git a/learn_otel/app.py b/learn_otel/app.py new file mode 100644 index 0000000..3eb91ea --- /dev/null +++ b/learn_otel/app.py @@ -0,0 +1,24 @@ +import logging +from random import randint + +from flask import Flask +from flask import request + +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.warn("%s is rolling the dice: %s", player, result) + else: + logger.warn("Anonymous player is rolling the dice: %s", result) + return result + + +def roll(): + return randint(1, 6) diff --git a/learn_otel/example.py b/learn_otel/example.py deleted file mode 100644 index b83ab56..0000000 --- a/learn_otel/example.py +++ /dev/null @@ -1,5 +0,0 @@ -class Example: - """An example class""" - - def __init__(self, name): - self.name = name diff --git a/requirements.in b/requirements.in index 52f833f..a2be255 100644 --- a/requirements.in +++ b/requirements.in @@ -1,2 +1,4 @@ flask<3 +gunicorn +opentelemetry-distro werkzeug<3 diff --git a/requirements.txt b/requirements.txt index 667b88d..7d7b37a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,8 +8,14 @@ blinker==1.7.0 # via flask click==8.1.7 # via flask +deprecated==1.2.14 + # via opentelemetry-api flask==2.3.3 # via -r requirements.in +gunicorn==21.2.0 + # via -r requirements.in +importlib-metadata==6.11.0 + # via opentelemetry-api itsdangerous==2.1.2 # via flask jinja2==3.1.3 @@ -18,7 +24,33 @@ markupsafe==2.1.5 # via # jinja2 # werkzeug +opentelemetry-api==1.22.0 + # via + # opentelemetry-distro + # opentelemetry-instrumentation + # opentelemetry-sdk +opentelemetry-distro==0.43b0 + # via -r requirements.in +opentelemetry-instrumentation==0.43b0 + # via opentelemetry-distro +opentelemetry-sdk==1.22.0 + # via opentelemetry-distro +opentelemetry-semantic-conventions==0.43b0 + # via opentelemetry-sdk +packaging==23.2 + # via gunicorn +typing-extensions==4.9.0 + # via opentelemetry-sdk werkzeug==2.3.8 # via # -r requirements.in # flask +wrapt==1.16.0 + # via + # deprecated + # opentelemetry-instrumentation +zipp==3.17.0 + # via importlib-metadata + +# The following packages are considered to be unsafe in a requirements file: +# setuptools diff --git a/tasks.py b/tasks.py index 0d25a32..64eb82a 100644 --- a/tasks.py +++ b/tasks.py @@ -2,7 +2,7 @@ import os from invoke import task -IMAGE_RESPOSITORY = os.environ.get("IMAGE_RESPOSITORY", "registry.runcible.io/learn_otel") +IMAGE_RESPOSITORY = os.environ.get("IMAGE_RESPOSITORY", "registry.runcible.io/learn-otel") @task @@ -50,3 +50,8 @@ def build_image(c, dev=True, registry_user=None, registry_token=None, push=False c.run(f"docker login -u {registry_user} -p {registry_token}") if push: c.run(f"docker push {image_name}") + + +@task +def serve_dev(c): + c.run("FLASK_APP=./learn_otel/app.py flask run -p 8888")