Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions python/django3/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.venv
7 changes: 7 additions & 0 deletions python/django3/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM python:3.8

WORKDIR /project

COPY ./requirements.txt /project

RUN pip install -r requirements.txt
Empty file added python/django3/app/__init__.py
Empty file.
16 changes: 16 additions & 0 deletions python/django3/app/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
ASGI config for app project.

It exposes the ASGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/3.1/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "app.settings")

application = get_asgi_application()
120 changes: 120 additions & 0 deletions python/django3/app/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
"""
Django settings for app project.

Generated by 'django-admin startproject' using Django 3.1.

For more information on this file, see
https://docs.djangoproject.com/en/3.1/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.1/ref/settings/
"""

from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve(strict=True).parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = "le@f+r+o4qqd_s=i6$1d313h2)xj#j1*k5immu*7qz)!g-vw7o"

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ["*"]


# Application definition

INSTALLED_APPS = [
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
]

MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
]

ROOT_URLCONF = "app.urls"

TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
],
},
},
]

WSGI_APPLICATION = "app.wsgi.application"


# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases

DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": BASE_DIR / "db.sqlite3",
}
}


# Password validation
# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
},
{
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
},
{
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
},
{
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
},
]


# Internationalization
# https://docs.djangoproject.com/en/3.1/topics/i18n/

LANGUAGE_CODE = "en-us"

TIME_ZONE = "UTC"

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.1/howto/static-files/

STATIC_URL = "/static/"
26 changes: 26 additions & 0 deletions python/django3/app/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""app URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.1/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path

from . import views


urlpatterns = [
path("admin/", admin.site.urls),
path("download/", views.file_response),
path("streaming/", views.streaming_response),
]
18 changes: 18 additions & 0 deletions python/django3/app/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import time
import random

from django.http import HttpResponse, StreamingHttpResponse, FileResponse


def file_response(request):
return FileResponse(open("manage.py", "rb"))


def get_resp():
for i in range(0, 10):
time.sleep(random.random() / 10)
yield "%d\n" % i


def streaming_response(request):
return StreamingHttpResponse(get_resp())
17 changes: 17 additions & 0 deletions python/django3/app/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""
WSGI config for app project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/3.1/howto/deployment/wsgi/
"""

import os

from ddtrace.contrib.wsgi import DDWSGIMiddleware
from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "app.settings")

application = DDWSGIMiddleware(get_wsgi_application())
39 changes: 39 additions & 0 deletions python/django3/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
version: "3"

services:
agent:
image: datadog/agent:latest
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- /proc/:/host/proc/:ro
- /sys/fs/cgroup/:/host/sys/fs/cgroup:ro
ports:
- 127.0.0.1:8126:8126/tcp
- 127.0.0.1:8125:8125/udp
environment:
- DD_API_KEY=${DD_API_KEY}
- DD_APM_ENABLED=true
- DD_APM_NON_LOCAL_TRAFFIC=true
- DD_LOG_LEVEL=INFO
- DD_DOGSTATSD_NON_LOCAL_TRAFFIC=true
- DD_AC_EXCLUDE=name:datadog-agent
app_dev:
build:
context: .
dockerfile: ./Dockerfile
command: ddtrace-run python manage.py runserver 0.0.0.0:8000
environment:
- DD_ENV=test
- "DD_TRACE_AGENT_URL=http://agent:8126"
- DD_SERVICE=django-test
- DD_DJANGO_CACHE_SERVICE_NAME=cache
- DD_DJANGO_DATABASE_SERVICE_NAME=django-test
- DD_DJANGO_USE_HANDLER_RESOURCE_FORMAT=true
- DD_SQLITE_SERVICE=test-db
- DD_PROFILING_ENABLED=true
# - DD_TRACE_DEBUG=true
ports:
- 8000:8000
volumes:
- .:/project

22 changes: 22 additions & 0 deletions python/django3/manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
"""Run administrative tasks."""
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "app.settings")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)


if __name__ == "__main__":
main()
71 changes: 71 additions & 0 deletions python/django3/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
alabaster==0.7.12
appdirs==1.4.4
attrs==20.3.0
Babel==2.8.1
black==20.8b1
certifi==2020.11.8
chardet==3.0.4
click==7.1.2
Cython==0.29.21
ddtrace
distlib==0.3.1
docutils==0.16
dulwich==0.20.11
filelock==3.0.12
flake8==3.8.4
gevent==20.9.0
greenlet==0.4.17
idna==2.10
imagesize==1.2.0
iniconfig==1.1.1
intervaltree==3.1.0
Jinja2==2.11.2
MarkupSafe==1.1.1
mccabe==0.6.1
mock==4.0.2
multidict==5.0.0
mypy-extensions==0.4.3
opentracing==2.3.0
packaging==20.4
pathspec==0.8.1
pbr==5.5.1
pluggy==0.13.1
protobuf==3.13.0
py==1.9.0
py-cpuinfo==7.0.0
pycodestyle==2.6.0
pyenchant==3.1.1
pyflakes==2.2.0
Pygments==2.7.2
pyparsing==2.4.7
pytest==6.1.2
pytest-benchmark==3.2.3
pytz==2020.4
PyYAML==5.3.1
regex==2020.11.11
reno==3.2.0
requests==2.25.0
riot==0.2.0
six==1.15.0
snowballstemmer==2.0.0
sortedcontainers==2.3.0
Sphinx==3.3.0
sphinx-rtd-theme==0.5.0
sphinxcontrib-applehelp==1.0.2
sphinxcontrib-devhelp==1.0.2
sphinxcontrib-htmlhelp==1.0.3
sphinxcontrib-jsmath==1.0.1
sphinxcontrib-qthelp==1.0.3
sphinxcontrib-serializinghtml==1.1.4
sphinxcontrib-spelling==7.1.0
tenacity==6.2.0
toml==0.10.2
typed-ast==1.4.1
typing-extensions==3.7.4.3
urllib3==1.26.1
vcrpy==4.1.1
virtualenv==20.1.0
wrapt==1.12.1
yarl==1.6.2
zope.event==4.5.0
zope.interface==5.2.0