From 0aa95b2bfedc642f701322b1d2d8c571696cef40 Mon Sep 17 00:00:00 2001 From: brettlangdon Date: Wed, 21 Dec 2016 20:09:04 -0500 Subject: [PATCH] initial repro info --- README.md | 72 +++++++++++++++++++++++++ manage.py | 10 ++++ mysite/__init__.py | 8 +++ mysite/settings.py | 128 +++++++++++++++++++++++++++++++++++++++++++++ mysite/urls.py | 21 ++++++++ mysite/wsgi.py | 16 ++++++ 6 files changed, 255 insertions(+) create mode 100644 README.md create mode 100755 manage.py create mode 100644 mysite/__init__.py create mode 100644 mysite/settings.py create mode 100644 mysite/urls.py create mode 100644 mysite/wsgi.py diff --git a/README.md b/README.md new file mode 100644 index 0000000..7a15029 --- /dev/null +++ b/README.md @@ -0,0 +1,72 @@ +``` +$ python --version +Python 2.7.12 +``` + +# Setup/run +```bash +git clone https://gist.github.com/ab633fb149d7b02e3916c370d57becd2.git ./django-repo +cd ./django-repo +# mkvirtualenv django-repo +pip install django==1.9.4 https://github.com/DataDog/dd-trace-py/archive/v0.5.2.tar.gz +python manage.py runserver +``` + +Open http://localhost:8000/ + +Will receive the following error: + +``` +error sending spans +Traceback (most recent call last): + File "/Users/brettlangdon/.env/django-test/lib/python2.7/site-packages/ddtrace/writer.py", line 127, in _target + self.api.send_services(services) + File "/Users/brettlangdon/.env/django-test/lib/python2.7/site-packages/ddtrace/api.py", line 65, in send_services + response = self._put(self._services, data) + File "/Users/brettlangdon/.env/django-test/lib/python2.7/site-packages/ddtrace/api.py", line 78, in _put + conn.request("PUT", endpoint, data, self._headers) + File "/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 1057, in request + self._send_request(method, url, body, headers) + File "/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 1097, in _send_request + self.endheaders(body) + File "/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 1053, in endheaders + self._send_output(message_body) + File "/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 897, in _send_output + self.send(msg) + File "/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 859, in send + self.connect() + File "/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 836, in connect + self.timeout, self.source_address) + File "/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 557, in create_connection + for res in getaddrinfo(host, port, 0, SOCK_STREAM): +error: getaddrinfo() argument 2 must be integer or string +``` + +Reproducing via Python repl: + +``` +$ python +Python 2.7.12 (default, Oct 11 2016, 15:46:18) +[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.38)] on darwin +Type "help", "copyright", "credits" or "license" for more information. +>>> from socket import * +>>> getaddrinfo('127.0.0.1', u'7777', 0, SOCK_STREAM) +Traceback (most recent call last): + File "", line 1, in +socket.error: getaddrinfo() argument 2 must be integer or string +>>> getaddrinfo('127.0.0.1', '7777', 0, SOCK_STREAM) +[(2, 1, 6, '', ('127.0.0.1', 7777))] +>>> getaddrinfo('127.0.0.1', 7777, 0, SOCK_STREAM) +[(2, 1, 6, '', ('127.0.0.1', 7777))] +>>> +``` + +`getaddrinfo` only allows `str` or `int` for the port number and errors on `unicode`. This is not an issue for Python 3. + +Fixing the problem: + +```python +DATADOG_TRACE = { + 'AGENT_PORT': 7777, +} +``` diff --git a/manage.py b/manage.py new file mode 100755 index 0000000..8a50ec0 --- /dev/null +++ b/manage.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings") + + from django.core.management import execute_from_command_line + + execute_from_command_line(sys.argv) diff --git a/mysite/__init__.py b/mysite/__init__.py new file mode 100644 index 0000000..8d4483b --- /dev/null +++ b/mysite/__init__.py @@ -0,0 +1,8 @@ +import logging +import sys + +from ddtrace.writer import log + +handler = logging.StreamHandler(sys.stdout) +log.addHandler(handler) +log.setLevel(logging.DEBUG) diff --git a/mysite/settings.py b/mysite/settings.py new file mode 100644 index 0000000..230087c --- /dev/null +++ b/mysite/settings.py @@ -0,0 +1,128 @@ +""" +Django settings for mysite project. + +Generated by 'django-admin startproject' using Django 1.9.4. + +For more information on this file, see +https://docs.djangoproject.com/en/1.9/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/1.9/ref/settings/ +""" + +import os + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'jb=3)yo#5kx_w&4i0c3qz6ns02e092f3wnla^*--9h94y4iii+' + +# 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', + 'ddtrace.contrib.django', +] + +MIDDLEWARE_CLASSES = [ + 'ddtrace.contrib.django.TraceMiddleware', + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'mysite.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 = 'mysite.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/1.9/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } +} + + +# Password validation +# https://docs.djangoproject.com/en/1.9/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/1.9/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/1.9/howto/static-files/ + +STATIC_URL = '/static/' + +DATADOG_TRACE = { + 'DEFAULT_SERVICE': 'my-django-app', + 'ENABLED': True, +} diff --git a/mysite/urls.py b/mysite/urls.py new file mode 100644 index 0000000..6d5264d --- /dev/null +++ b/mysite/urls.py @@ -0,0 +1,21 @@ +"""mysite URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/1.9/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.conf.urls import url, include + 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) +""" +from django.conf.urls import url +from django.contrib import admin + +urlpatterns = [ + url(r'^admin/', admin.site.urls), +] diff --git a/mysite/wsgi.py b/mysite/wsgi.py new file mode 100644 index 0000000..328bae0 --- /dev/null +++ b/mysite/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for mysite 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/1.9/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings") + +application = get_wsgi_application()