diff --git a/Rakefile b/Rakefile index 10735173b37..7f790241b7f 100644 --- a/Rakefile +++ b/Rakefile @@ -19,3 +19,22 @@ task :release do sh "mkwheelhouse s3://#{s3_bucket}/#{s3_dir}/ ." end + +task :clean do + sh 'rm -rf build *egg*' +end + + +task :docs do + Dir.chdir 'docs' do + sh "make html" + end +end + +task :'docs:loop' do + # FIXME do something real here + while true do + sleep 2 + Rake::Task["docs"].execute + end +end diff --git a/ddtrace/__init__.py b/ddtrace/__init__.py index 7b7cb6fd225..599422c16ef 100644 --- a/ddtrace/__init__.py +++ b/ddtrace/__init__.py @@ -1,5 +1,8 @@ -"""Datadog Tracing client""" +""" +""" + from .tracer import Tracer +from .span import Span __version__ = '0.2.0' diff --git a/ddtrace/contrib/__init__.py b/ddtrace/contrib/__init__.py index ad455755aad..be3b807ef4f 100644 --- a/ddtrace/contrib/__init__.py +++ b/ddtrace/contrib/__init__.py @@ -1,5 +1,4 @@ - def func_name(f): """ Return a human readable version of the function's name. """ return "%s.%s" % (f.__module__, f.__name__) diff --git a/ddtrace/contrib/django/__init__.py b/ddtrace/contrib/django/__init__.py index 42f42d0c8ba..872192ddaed 100644 --- a/ddtrace/contrib/django/__init__.py +++ b/ddtrace/contrib/django/__init__.py @@ -1,3 +1,21 @@ +""" +The Django middleware will trace requests, database calls and template +renders. + +To install the Django tracing middleware, add it to the list of your +application's installed in middleware in settings.py:: + + + MIDDLEWARE_CLASSES = ( + ... + 'ddtrace.contrib.django.TraceMiddleware', + ... + ) + + DATADOG_SERVICE = 'my-app' + +""" + from ..util import require_modules required_modules = ['django'] diff --git a/ddtrace/contrib/flask/__init__.py b/ddtrace/contrib/flask/__init__.py index 6d2b7a9cca0..0ea573d4891 100644 --- a/ddtrace/contrib/flask/__init__.py +++ b/ddtrace/contrib/flask/__init__.py @@ -1,3 +1,23 @@ +""" +The flask trace middleware will track request timings and templates. It +requires the `Blinker `_ library, which +Flask uses for signalling. + +To install the middleware, do the following:: + + from flask import Flask + from ddtrace import tracer + + app = Flask(...) + + traced_app = TraceMiddleware(app, tracer, service="my-flask-app") + + @app.route("/") + def home(): + return "hello world" + +""" + from ..util import require_modules required_modules = ['flask'] diff --git a/ddtrace/contrib/sqlite3/connection.py b/ddtrace/contrib/sqlite3/connection.py index 0bc2475bc28..ddac11e7662 100644 --- a/ddtrace/contrib/sqlite3/connection.py +++ b/ddtrace/contrib/sqlite3/connection.py @@ -9,6 +9,10 @@ def connection_factory(tracer, service="sqlite3"): """ Return a connection factory class that will can be used to trace sqlite queries. + + :param ddtrace.Tracer tracer: the tracer that will report the spans. + :param str service: the name of the database's service. + >>> factory = connection_factor(my_tracer, service="my_db_service") >>> conn = sqlite3.connect(":memory:", factory=factory) """ diff --git a/ddtrace/span.py b/ddtrace/span.py index e6df9f2284a..97ab6c720e7 100644 --- a/ddtrace/span.py +++ b/ddtrace/span.py @@ -26,12 +26,21 @@ def __init__(self, parent_id=None, start=None): """ - tracer: a link to the tracer that will store this span - name: the name of the operation we're measuring. - service: the name of the service that is being measured - resource: an optional way of specifying the 'normalized' params - of the request (i.e. the sql query, the url handler, etc) - start: the start time of request as a unix epoch in seconds + Create a new span. You must call `finish` on all spans. + + :param Tracer tracer: the tracer that will submit this span when + finished. + :param str name: the name of the traced operation. + :param str service: the service name + :param str resource: the resource name + + :param int start: the start time of the span in seconds from the epoch + + :param int trace_id: the id of this trace's root span. + :param int parent_id: the id of this span's direct parent span. + :param int span_id: the id of this span. + + :param int start: the start time of request as a unix epoch in seconds """ # required span info self.name = name @@ -61,15 +70,47 @@ def __init__(self, self._parent = None def finish(self, finish_time=None): - """ Mark the end time of the span and submit it to the tracer. """ + """ Mark the end time of the span and submit it to the tracer. + + :param int finish_time: the end time of the span in seconds. + Defaults to now. + """ ft = finish_time or time.time() # be defensive so we don't die if start isn't set self.duration = ft - (self.start or ft) if self._tracer: self._tracer.record(self) + def set_tag(self, key, value): + """ Set the given key / value tag pair on the span. Keys and values + must be strings (or stringable). If a casting error occurs, it will + be ignored. + """ + try: + self.meta[key] = stringify(value) + except Exception: + log.warning("error setting tag. ignoring", exc_info=True) + + def get_tag(self, key): + """ Return the given tag or None if it doesn't exist. + """ + return self.meta.get(key, None) + + def set_tags(self, tags): + """ Set a dictionary of tags on the given span. Keys and values + must be strings (or stringable) + """ + if tags: + for k, v in iter(tags.items()): + self.set_tag(k, v) + + def set_meta(self, k, v): + self.set_tag(k, v) + + def set_metas(self, kvs): + self.set_tags(kvs) + def to_dict(self): - """ Return a json serializable dictionary of the span's attributes. """ d = { 'trace_id' : self.trace_id, 'parent_id' : self.parent_id, @@ -95,32 +136,6 @@ def to_dict(self): return d - def set_tag(self, key, value): - """ Set the given key / value tag pair on the span. Keys and values - must be strings (or stringable). If a casting error occurs, it will - be ignored. - """ - try: - self.meta[key] = stringify(value) - except Exception: - log.warning("error setting tag. ignoring", exc_info=True) - - def get_tag(self, key): - """ Return the given tag or None if it doesn't exist""" - return self.meta.get(key, None) - - def set_tags(self, tags): - """ Set a dictionary of tags on the given span. Keys and values - must be strings (or stringable) - """ - if tags: - for k, v in iter(tags.items()): - self.set_tag(k, v) - - # backwards compatilibility, kill this - set_meta = set_tag - set_metas = set_tags - def set_traceback(self): """ If the current stack has a traceback, tag the span with the relevant error info. diff --git a/ddtrace/tracer.py b/ddtrace/tracer.py index ab58694e6e8..ec3ce039eb4 100644 --- a/ddtrace/tracer.py +++ b/ddtrace/tracer.py @@ -1,3 +1,4 @@ + import logging import threading @@ -11,16 +12,22 @@ class Tracer(object): + """ + Tracer is used to create, sample and submit spans that measure the + execution time of sections of code. + + If you're running an application that will serve a single trace per thread, + you can use the global traced instance: + + >>> from ddtrace import tracer + >>> tracer.trace("foo").finish() + """ def __init__(self, enabled=True, writer=None, span_buffer=None, sampler=None): """ - Create a new tracer object. + Create a new tracer. - enabled: if False, no spans will be submitted to the writer - writer: an instance of Writer - span_buffer: a span buffer instance. used to store inflight traces. by - default, will use thread local storage - sampler: Trace sampler. + :param bool enabled: If true, finished traces will be submitted to the API. Otherwise they'll be dropped. """ self.enabled = enabled @@ -43,15 +50,32 @@ def trace(self, name, service=None, resource=None, span_type=None): """ Return a span that will trace an operation called `name`. - It will store the created span in the span buffer and until it's - finished, any new spans will be a child of this span. + :param str name: the name of the operation being traced + :param str service: the name of the service being traced. If not set, + it will inherit the service from it's parent. + :param str resource: an optional name of the resource being tracked. + + You must call `finish` on all spans, either directly or with a context + manager. + + >>> span = tracer.trace("web.request") + try: + # do something + finally: + span.finish() + >>> with tracer.trace("web.request") as span: + # do something + + Trace will store the created span and subsequent child traces will + become it's children. >>> tracer = Tracer() - >>> parent = tracer.trace("parent") # has no parent span - >>> child = tracer.child("child") # is a child of a parent + >>> parent = tracer.trace("parent") # has no parent span + >>> child = tracer.trace("child") # is a child of a parent >>> child.finish() >>> parent.finish() - >>> parent2 = tracer.trace("parent2") # has no parent span + >>> parent2 = tracer.trace("parent2") # has no parent span + >>> parent2.finish() """ span = None parent = self._span_buffer.get() @@ -61,11 +85,11 @@ def trace(self, name, service=None, resource=None, span_type=None): span = Span( self, name, - trace_id=parent.trace_id, - parent_id=parent.span_id, service=(service or parent.service), resource=resource, span_type=span_type, + trace_id=parent.trace_id, + parent_id=parent.span_id, ) span._parent = parent span.sampled = parent.sampled @@ -103,7 +127,6 @@ def record(self, span): self.write(spans) def write(self, spans): - """ Submit the given spans to the agent. """ if not spans: return # nothing to do @@ -120,9 +143,9 @@ def set_service_info(self, service, app, app_type): """ Set the information about the given service. - @service: the internal name of the service (e.g. acme_search, datadog_web) - @app: the off the shelf name of the application (e.g. rails, postgres, custom-app) - @app_type: the type of the application (e.g. db, web) + :param str service: the internal name of the service (e.g. acme_search, datadog_web) + :param str app: the off the shelf name of the application (e.g. rails, postgres, custom-app) + :param str app_type: the type of the application (e.g. db, web) """ self._services[service] = { "app" : app, diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 00000000000..7b1ce33c234 --- /dev/null +++ b/docs/Makefile @@ -0,0 +1,225 @@ +# Makefile for Sphinx documentation +# + +# You can set these variables from the command line. +SPHINXOPTS = +SPHINXBUILD = sphinx-build +PAPER = +BUILDDIR = _build + +# Internal variables. +PAPEROPT_a4 = -D latex_paper_size=a4 +PAPEROPT_letter = -D latex_paper_size=letter +ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . +# the i18n builder cannot share the environment and doctrees with the others +I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . + +.PHONY: help +help: + @echo "Please use \`make ' where is one of" + @echo " html to make standalone HTML files" + @echo " dirhtml to make HTML files named index.html in directories" + @echo " singlehtml to make a single large HTML file" + @echo " pickle to make pickle files" + @echo " json to make JSON files" + @echo " htmlhelp to make HTML files and a HTML help project" + @echo " qthelp to make HTML files and a qthelp project" + @echo " applehelp to make an Apple Help Book" + @echo " devhelp to make HTML files and a Devhelp project" + @echo " epub to make an epub" + @echo " epub3 to make an epub3" + @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" + @echo " latexpdf to make LaTeX files and run them through pdflatex" + @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" + @echo " text to make text files" + @echo " man to make manual pages" + @echo " texinfo to make Texinfo files" + @echo " info to make Texinfo files and run them through makeinfo" + @echo " gettext to make PO message catalogs" + @echo " changes to make an overview of all changed/added/deprecated items" + @echo " xml to make Docutils-native XML files" + @echo " pseudoxml to make pseudoxml-XML files for display purposes" + @echo " linkcheck to check all external links for integrity" + @echo " doctest to run all doctests embedded in the documentation (if enabled)" + @echo " coverage to run coverage check of the documentation (if enabled)" + @echo " dummy to check syntax errors of document sources" + +.PHONY: clean +clean: + rm -rf $(BUILDDIR)/* + +.PHONY: html +html: + $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." + +.PHONY: dirhtml +dirhtml: + $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." + +.PHONY: singlehtml +singlehtml: + $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml + @echo + @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." + +.PHONY: pickle +pickle: + $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle + @echo + @echo "Build finished; now you can process the pickle files." + +.PHONY: json +json: + $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json + @echo + @echo "Build finished; now you can process the JSON files." + +.PHONY: htmlhelp +htmlhelp: + $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp + @echo + @echo "Build finished; now you can run HTML Help Workshop with the" \ + ".hhp project file in $(BUILDDIR)/htmlhelp." + +.PHONY: qthelp +qthelp: + $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp + @echo + @echo "Build finished; now you can run "qcollectiongenerator" with the" \ + ".qhcp project file in $(BUILDDIR)/qthelp, like this:" + @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/ddtrace.qhcp" + @echo "To view the help file:" + @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/ddtrace.qhc" + +.PHONY: applehelp +applehelp: + $(SPHINXBUILD) -b applehelp $(ALLSPHINXOPTS) $(BUILDDIR)/applehelp + @echo + @echo "Build finished. The help book is in $(BUILDDIR)/applehelp." + @echo "N.B. You won't be able to view it unless you put it in" \ + "~/Library/Documentation/Help or install it in your application" \ + "bundle." + +.PHONY: devhelp +devhelp: + $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp + @echo + @echo "Build finished." + @echo "To view the help file:" + @echo "# mkdir -p $$HOME/.local/share/devhelp/ddtrace" + @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/ddtrace" + @echo "# devhelp" + +.PHONY: epub +epub: + $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub + @echo + @echo "Build finished. The epub file is in $(BUILDDIR)/epub." + +.PHONY: epub3 +epub3: + $(SPHINXBUILD) -b epub3 $(ALLSPHINXOPTS) $(BUILDDIR)/epub3 + @echo + @echo "Build finished. The epub3 file is in $(BUILDDIR)/epub3." + +.PHONY: latex +latex: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo + @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." + @echo "Run \`make' in that directory to run these through (pdf)latex" \ + "(use \`make latexpdf' here to do that automatically)." + +.PHONY: latexpdf +latexpdf: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo "Running LaTeX files through pdflatex..." + $(MAKE) -C $(BUILDDIR)/latex all-pdf + @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." + +.PHONY: latexpdfja +latexpdfja: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo "Running LaTeX files through platex and dvipdfmx..." + $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja + @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." + +.PHONY: text +text: + $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text + @echo + @echo "Build finished. The text files are in $(BUILDDIR)/text." + +.PHONY: man +man: + $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man + @echo + @echo "Build finished. The manual pages are in $(BUILDDIR)/man." + +.PHONY: texinfo +texinfo: + $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo + @echo + @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." + @echo "Run \`make' in that directory to run these through makeinfo" \ + "(use \`make info' here to do that automatically)." + +.PHONY: info +info: + $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo + @echo "Running Texinfo files through makeinfo..." + make -C $(BUILDDIR)/texinfo info + @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." + +.PHONY: gettext +gettext: + $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale + @echo + @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." + +.PHONY: changes +changes: + $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes + @echo + @echo "The overview file is in $(BUILDDIR)/changes." + +.PHONY: linkcheck +linkcheck: + $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck + @echo + @echo "Link check complete; look for any errors in the above output " \ + "or in $(BUILDDIR)/linkcheck/output.txt." + +.PHONY: doctest +doctest: + $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest + @echo "Testing of doctests in the sources finished, look at the " \ + "results in $(BUILDDIR)/doctest/output.txt." + +.PHONY: coverage +coverage: + $(SPHINXBUILD) -b coverage $(ALLSPHINXOPTS) $(BUILDDIR)/coverage + @echo "Testing of coverage in the sources finished, look at the " \ + "results in $(BUILDDIR)/coverage/python.txt." + +.PHONY: xml +xml: + $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml + @echo + @echo "Build finished. The XML files are in $(BUILDDIR)/xml." + +.PHONY: pseudoxml +pseudoxml: + $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml + @echo + @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." + +.PHONY: dummy +dummy: + $(SPHINXBUILD) -b dummy $(ALLSPHINXOPTS) $(BUILDDIR)/dummy + @echo + @echo "Build finished. Dummy builder generates no files." diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 00000000000..5309a472ee1 --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,339 @@ +# -*- coding: utf-8 -*- +# +# ddtrace documentation build configuration file, created by +# sphinx-quickstart on Thu Jul 7 17:25:05 2016. +# +# This file is execfile()d with the current directory set to its +# containing dir. +# +# Note that not all possible configuration values are present in this +# autogenerated file. +# +# All configuration values have a default; values that are commented out +# serve to show the default. + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +# + +import os +import sys +sys.path.insert(0, os.path.abspath('..')) + +# -- General configuration ------------------------------------------------ + +# If your documentation needs a minimal Sphinx version, state it here. +# +# needs_sphinx = '1.0' + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = [ + 'sphinx.ext.autodoc', +] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# The suffix(es) of source filenames. +# You can specify multiple suffix as a list of string: +# +# source_suffix = ['.rst', '.md'] +source_suffix = '.rst' + +# The encoding of source files. +# +# source_encoding = 'utf-8-sig' + +# The master toctree document. +master_doc = 'index' + +# General information about the project. +project = u'ddtrace' +copyright = u'2016, Datadog, Inc' +author = u'Datadog, Inc' + +# document in order of source +autodoc_member_order = 'bysource' + + +# The version info for the project you're documenting, acts as replacement for +# |version| and |release|, also used in various other places throughout the +# built documents. +# +# The short X.Y version. +version = u'0.2' +# The full version, including alpha/beta/rc tags. +release = u'0.2' + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +# +# This is also used if you do content translation via gettext catalogs. +# Usually you set "language" from the command line for these cases. +language = None + +# There are two options for replacing |today|: either, you set today to some +# non-false value, then it is used: +# +# today = '' +# +# Else, today_fmt is used as the format for a strftime call. +# +# today_fmt = '%B %d, %Y' + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +# This patterns also effect to html_static_path and html_extra_path +exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] + +# The reST default role (used for this markup: `text`) to use for all +# documents. +# +# default_role = None + +# If true, '()' will be appended to :func: etc. cross-reference text. +# +# add_function_parentheses = True + +# If true, the current module name will be prepended to all description +# unit titles (such as .. function::). +# +# add_module_names = True + +# If true, sectionauthor and moduleauthor directives will be shown in the +# output. They are ignored by default. +# +# show_authors = False + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = 'sphinx' + +# A list of ignored prefixes for module index sorting. +# modindex_common_prefix = [] + +# If true, keep warnings as "system message" paragraphs in the built documents. +# keep_warnings = False + +# If true, `todo` and `todoList` produce output, else they produce nothing. +todo_include_todos = False + + +# -- Options for HTML output ---------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +# +html_theme = 'alabaster' + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +# +# html_theme_options = {} + +# Add any paths that contain custom themes here, relative to this directory. +# html_theme_path = [] + +# The name for this set of Sphinx documents. +# " v documentation" by default. +# +# html_title = u'ddtrace v0.2' + +# A shorter title for the navigation bar. Default is the same as html_title. +# +# html_short_title = None + +# The name of an image file (relative to this directory) to place at the top +# of the sidebar. +# +# html_logo = None + +# The name of an image file (relative to this directory) to use as a favicon of +# the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 +# pixels large. +# +# html_favicon = None + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ['_static'] + +# Add any extra paths that contain custom files (such as robots.txt or +# .htaccess) here, relative to this directory. These files are copied +# directly to the root of the documentation. +# +# html_extra_path = [] + +# If not None, a 'Last updated on:' timestamp is inserted at every page +# bottom, using the given strftime format. +# The empty string is equivalent to '%b %d, %Y'. +# +# html_last_updated_fmt = None + +# If true, SmartyPants will be used to convert quotes and dashes to +# typographically correct entities. +# +# html_use_smartypants = True + +# Custom sidebar templates, maps document names to template names. +# +# html_sidebars = {} + +# Additional templates that should be rendered to pages, maps page names to +# template names. +# +# html_additional_pages = {} + +# If false, no module index is generated. +# +# html_domain_indices = True + +# If false, no index is generated. +# +# html_use_index = True + +# If true, the index is split into individual pages for each letter. +# +# html_split_index = False + +# If true, links to the reST sources are added to the pages. +# +# html_show_sourcelink = True + +# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. +# +# html_show_sphinx = True + +# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. +# +# html_show_copyright = True + +# If true, an OpenSearch description file will be output, and all pages will +# contain a tag referring to it. The value of this option must be the +# base URL from which the finished HTML is served. +# +# html_use_opensearch = '' + +# This is the file name suffix for HTML files (e.g. ".xhtml"). +# html_file_suffix = None + +# Language to be used for generating the HTML full-text search index. +# Sphinx supports the following languages: +# 'da', 'de', 'en', 'es', 'fi', 'fr', 'hu', 'it', 'ja' +# 'nl', 'no', 'pt', 'ro', 'ru', 'sv', 'tr', 'zh' +# +# html_search_language = 'en' + +# A dictionary with options for the search language support, empty by default. +# 'ja' uses this config value. +# 'zh' user can custom change `jieba` dictionary path. +# +# html_search_options = {'type': 'default'} + +# The name of a javascript file (relative to the configuration directory) that +# implements a search results scorer. If empty, the default will be used. +# +# html_search_scorer = 'scorer.js' + +# Output file base name for HTML help builder. +htmlhelp_basename = 'ddtracedoc' + +# -- Options for LaTeX output --------------------------------------------- + +latex_elements = { + # The paper size ('letterpaper' or 'a4paper'). + # + # 'papersize': 'letterpaper', + + # The font size ('10pt', '11pt' or '12pt'). + # + # 'pointsize': '10pt', + + # Additional stuff for the LaTeX preamble. + # + # 'preamble': '', + + # Latex figure (float) alignment + # + # 'figure_align': 'htbp', +} + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, +# author, documentclass [howto, manual, or own class]). +latex_documents = [ + (master_doc, 'ddtrace.tex', u'ddtrace Documentation', + u'Datadog, Inc', 'manual'), +] + +# The name of an image file (relative to this directory) to place at the top of +# the title page. +# +# latex_logo = None + +# For "manual" documents, if this is true, then toplevel headings are parts, +# not chapters. +# +# latex_use_parts = False + +# If true, show page references after internal links. +# +# latex_show_pagerefs = False + +# If true, show URL addresses after external links. +# +# latex_show_urls = False + +# Documents to append as an appendix to all manuals. +# +# latex_appendices = [] + +# If false, no module index is generated. +# +# latex_domain_indices = True + + +# -- Options for manual page output --------------------------------------- + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +man_pages = [ + (master_doc, 'ddtrace', u'ddtrace Documentation', + [author], 1) +] + +# If true, show URL addresses after external links. +# +# man_show_urls = False + + +# -- Options for Texinfo output ------------------------------------------- + +# Grouping the document tree into Texinfo files. List of tuples +# (source start file, target name, title, author, +# dir menu entry, description, category) +texinfo_documents = [ + (master_doc, 'ddtrace', u'ddtrace Documentation', + author, 'ddtrace', 'One line description of project.', + 'Miscellaneous'), +] + +# Documents to append as an appendix to all manuals. +# +# texinfo_appendices = [] + +# If false, no module index is generated. +# +# texinfo_domain_indices = True + +# How to display URL addresses: 'footnote', 'no', or 'inline'. +# +# texinfo_show_urls = 'footnote' + +# If true, do not generate a @detailmenu in the "Top" node's menu. +# +# texinfo_no_detailmenu = False diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 00000000000..b603205aff4 --- /dev/null +++ b/docs/index.rst @@ -0,0 +1,128 @@ +.. ddtrace documentation master file, created by + sphinx-quickstart on Thu Jul 7 17:25:05 2016. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + +Datadog Trace Client +==================== + +`ddtrace` is Datadog's tracing client for Python. It is used to trace requests as +they flow across web servers, databases and microservices so that developers +have great visiblity into bottlenecks and troublesome requests. + + +Installation +------------ + + +Quick Start +----------- + +Adding tracing to your code is very simple. Let's imagine we were adding +tracing to a small web app:: + + from ddtrace import tracer + + service = 'my-web-site' + + @route("/home") + def home(request): + + with tracer.trace('web.request') as span: + # set some span metadata + span.service = service + span.resource = "home" + span.set_tag('web.user', request.username) + + # trace a database request + with tracer.trace('users.fetch'): + user = db.fetch_user(request.username) + + # trace a template render + with tracer.trace('template.render'): + return render_template('/templates/user.html', user=user) + + +Glossary +-------- + +**Service** + +The name of a set of processes that do the same job. Some examples are :code:`datadog-web-app` or :code:`datadog-metrics-db`. + +**Resource** + +A particular query to a service. For a web application, some +examples might be a URL stem like :code:`/user/home` or a handler function +like :code:`web.user.home`. For a sql database, a resource +would be the sql of the query itself like :code:`select * from users +where id = ?`. + +You can track thousands (not millions or billions) of unique resources per services, so prefer +resources like :code:`/user/home` rather than :code:`/user/home?id=123456789`. + +**App** + +The name of the code that a service is running. Some common open source +examples are :code:`postgres`, :code:`rails` or :code:`redis`. If it's running +custom code, name it accordingly like :code:`datadog-metrics-db`. + +**Span** + +A span tracks a unit of work in a service, like querying a database or +rendering a template. Spans are associated with a service and optionally a +resource. Spans have names, start times, durations and optional tags. + + +API +--- + +.. autoclass:: ddtrace.Tracer + :members: + :special-members: __init__ + + +.. autoclass:: ddtrace.Span + :members: + :special-members: __init__ + +.. toctree:: + :maxdepth: 2 + + +Integrations +------------ + + +Django +~~~~~~ + +.. automodule:: ddtrace.contrib.django + + +Flask +~~~~~ + +.. automodule:: ddtrace.contrib.flask + + +Postgres +~~~~~~~~ + +.. autofunction:: ddtrace.contrib.psycopg.connection_factory + + +SQLite +~~~~~~ + +.. autofunction:: ddtrace.contrib.sqlite3.connection_factory + + + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` + diff --git a/setup.py b/setup.py index cb028e861f3..efb7aad4cd8 100644 --- a/setup.py +++ b/setup.py @@ -13,6 +13,7 @@ 'flask', 'psycopg2', 'redis', + 'sphinx' ]