Skip to content

Commit 4242925

Browse files
committed
feat: auto instrument logging + requests + flask + fastapi
1 parent a0de393 commit 4242925

File tree

13 files changed

+483
-259
lines changed

13 files changed

+483
-259
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ build: install
1616

1717
#: build and publish a package
1818
publish: install
19-
poetry publish -u hyperdx -p ${PYPI_PASSWORD}
19+
poetry publish -u warrenathyper -p ${PYPI_PASSWORD}
2020

2121
#: cleans up smoke test output
2222
clean-smoke-tests:

examples/hello-world-flask/app.py

+12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
import logging
12
import os
3+
import requests
4+
25
from flask import Flask
36
from opentelemetry import trace, baggage, metrics
47
from opentelemetry.context import attach, detach
@@ -19,10 +22,13 @@
1922
meter = metrics.get_meter("hello_world_flask_meter")
2023
bee_counter = meter.create_counter("bee_counter")
2124

25+
logger = logging.getLogger(__name__)
26+
2227

2328
@app.route("/")
2429
# Recommended: use attach and detach tokens for Context management with Baggage
2530
def hello_world():
31+
logger.warn("processing request to /")
2632
# adding baggage attributes (key, value)
2733
token = attach(baggage.set_baggage("queen", "bee"))
2834

@@ -43,6 +49,12 @@ def hello_world():
4349
detach(token)
4450
# counter incremented by 1, attributes (route) associated with the increment
4551
bee_counter.add(1, {'app.route': '/'})
52+
logger.warn("finished processing request to /")
53+
54+
logger.warn("sending request to /health")
55+
resp = requests.post("https://in.hyperdx.io/health", json={"message": "Hello world"})
56+
logger.warn(f"received response from /health {resp.status_code}")
57+
4658
return "Hello World"
4759

4860

examples/hello-world-flask/pyproject.toml

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ readme = "README.md"
99
python = "^3.10"
1010
flask = "^2.2.2"
1111
hyperdx-opentelemetry = {path = "../../", develop = true}
12-
opentelemetry-api = "^1.17.0"
13-
opentelemetry-instrumentation-flask = "^0.38b0"
12+
opentelemetry-api = "^1.18.0"
13+
opentelemetry-instrumentation-requests = "0.39b0"
14+
opentelemetry-instrumentation-flask = "0.39b0"
1415

1516
[build-system]
1617
requires = ["poetry-core"]

examples/hello-world/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ readme = "README.md"
88
[tool.poetry.dependencies]
99
python = "^3.10"
1010
hyperdx-opentelemetry = {path = "../../", develop = true}
11-
opentelemetry-api = "^1.17.0"
11+
opentelemetry-api = "^1.18.0"
1212

1313
[build-system]
1414
requires = ["poetry-core"]

0 commit comments

Comments
 (0)