Skip to content

Commit 582d1cc

Browse files
authored
Add uWSGI support (#41)
- Add uWSGI service for testing and as an example - Add propagation tests for uwsgi directives - Update example/README.md - Ignore *.pyc - Mention uwsgi_pass in the docs for datadog_proxy_directive Resolves #38
1 parent 39e535b commit 582d1cc

24 files changed

+311
-3
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,6 @@
1818

1919
# scratch directory for preparing releases
2020
/.release/
21+
22+
# Python
23+
__pycache__/

doc/API.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,8 @@ If there is no location associated with the current request, then
358358

359359
### `datadog_proxy_directive`
360360
`$datadog_proxy_directive` expands to the name of the configuration directive
361-
used to proxy the current request, i.e. one of `proxy_pass`, `grpc_pass`, or
362-
`fastcgi_pass`.
361+
used to proxy the current request, i.e. one of `proxy_pass`, `grpc_pass`,
362+
`fastcgi_pass`, or `uwsgi_pass`.
363363

364364
If the request was not configured by one of those directives, then
365365
`$datadog_proxy_directive` expands to "`location`".

example/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ services:
1212
- `http` runs a NodeJS HTTP server that listens on port 8080.
1313
- `fastcgi` runs a NodeJS FastCGI server that listens on port 8080.
1414
- `grpc` runs a NodeJS gRPC server that listens on port 1337.
15+
- `uwsgi` runs a Python uWSGI server that listens on port 8080.
1516
- `client` contains the command line tools `curl` and `grpcurl`.
1617

1718
Because client command line tools are available within the `client` service,

example/docker-compose.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ services:
1414
- http
1515
- fastcgi
1616
- grpc
17+
- uwsgi
1718
- agent
1819

1920
# `agent` is the Datadog Agent to which traces are sent.
@@ -69,6 +70,18 @@ services:
6970
depends_on:
7071
- agent
7172

73+
# `uwsgi` is a uWSGI server that is reverse proxied by `nginx`.
74+
uwsgi:
75+
build:
76+
context: ./services/uwsgi
77+
dockerfile: ./Dockerfile
78+
environment:
79+
- DD_ENV=prod
80+
- DD_AGENT_HOST=agent
81+
- DD_SERVICE=uwsgi
82+
depends_on:
83+
- agent
84+
7285
# `client` is a container that exists solely so that the host can
7386
# `docker-compose exec` into it to run command line tools such as `curl` and
7487
# `grpcurl`. This way, the host's network doesn't need access to the network

example/services/nginx/nginx.conf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ http {
4242
location /fastcgi {
4343
fastcgi_pass fastcgi:8080;
4444
}
45+
46+
location /uwsgi {
47+
include uwsgi_params;
48+
uwsgi_pass uwsgi:8080;
49+
}
4550
}
4651

4752
server {

example/services/uwsgi/Dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM alpine:3.15
2+
3+
RUN mkdir /opt/app
4+
WORKDIR /opt/app
5+
6+
RUN apk update && apk add python3 py3-pip python3-dev build-base linux-headers pcre-dev
7+
RUN pip3 install --no-cache-dir uwsgi flask ddtrace
8+
9+
COPY ./uwsgi.ini /opt/app/uwsgi.ini
10+
COPY ./wsgi.py /opt/app/wsgi.py
11+
COPY ./app.py /opt/app/app.py
12+
13+
CMD ["uwsgi", "--ini", "uwsgi.ini"]

example/services/uwsgi/app.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from flask import Flask, request, jsonify
2+
3+
app = Flask(__name__)
4+
5+
@app.route("/", defaults={"path": ""})
6+
@app.route("/<string:path>")
7+
@app.route("/<path:path>")
8+
def main(path):
9+
response = {
10+
"service": "uwsgi",
11+
"headers": dict(request.headers)
12+
}
13+
print(response)
14+
return jsonify(response)

example/services/uwsgi/uwsgi.ini

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[uwsgi]
2+
module = wsgi:app
3+
master = true
4+
socket = :8080
5+
6+
;; dd-trace-py is used to trace the Flask application.
7+
;; It requires these options to supports uWSGI.
8+
;; See <https://ddtrace.readthedocs.io/en/stable/advanced_usage.html#uwsgi>.
9+
enable-threads = 1
10+
lazy-apps = 1
11+
import=ddtrace.bootstrap.sitecustomize

example/services/uwsgi/wsgi.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from app import app
2+
3+
if __name__ == "__main__":
4+
app.run()

module/config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ ngx_module_name="$ngx_addon_name"
66
# configuration directives we override. This way, our module can define
77
# handlers for those directives that do some processing and then forward
88
# to the "real" handler in the other module.
9-
ngx_module_order="$ngx_addon_name ngx_http_log_module ngx_http_fastcgi_module ngx_http_grpc_module ngx_http_proxy_module ngx_http_api_module"
9+
ngx_module_order="$ngx_addon_name ngx_http_log_module ngx_http_fastcgi_module ngx_http_grpc_module ngx_http_proxy_module ngx_http_api_module ngx_http_uwsgi_module"
1010

1111
. auto/module

0 commit comments

Comments
 (0)