Skip to content

Commit

Permalink
Add support for sphinx as a documentation generator (#595)
Browse files Browse the repository at this point in the history
  • Loading branch information
pyohannes authored Mar 4, 2021
1 parent 71d5b1d commit 0481fa0
Show file tree
Hide file tree
Showing 13 changed files with 333 additions and 87 deletions.
13 changes: 7 additions & 6 deletions api/docs/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -790,8 +790,7 @@ WARN_LOGFILE =
# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING
# Note: If this tag is empty the current directory is searched.

INPUT = ./Overview.md \
../include/opentelemetry/common \
INPUT = ../include/opentelemetry/common \
../include/opentelemetry/core \
../include/opentelemetry/nostd/shared_ptr.h \
../include/opentelemetry/nostd/span.h \
Expand Down Expand Up @@ -839,6 +838,8 @@ RECURSIVE = YES
# run.

EXCLUDE = ../include/opentelemetry/common/spin_lock_mutex.h \
../include/opentelemetry/common/key_value_iterable_view.h \
../include/opentelemetry/trace/span_context_kv_iterable_view.h \
../include/opentelemetry/nostd/detail

# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or
Expand Down Expand Up @@ -1088,7 +1089,7 @@ IGNORE_PREFIX =
# If the GENERATE_HTML tag is set to YES, doxygen will generate HTML output
# The default value is: YES.

GENERATE_HTML = YES
GENERATE_HTML = NO

# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. If a
# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of
Expand Down Expand Up @@ -1444,7 +1445,7 @@ DISABLE_INDEX = NO
# The default value is: NO.
# This tag requires that the tag GENERATE_HTML is set to YES.

GENERATE_TREEVIEW = NO
GENERATE_TREEVIEW = YES

# The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values that
# doxygen will group on one line in the generated HTML documentation.
Expand Down Expand Up @@ -1912,15 +1913,15 @@ MAN_LINKS = NO
# captures the structure of the code including all documentation.
# The default value is: NO.

GENERATE_XML = NO
GENERATE_XML = YES

# The XML_OUTPUT tag is used to specify where the XML pages will be put. If a
# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of
# it.
# The default directory is: xml.
# This tag requires that the tag GENERATE_XML is set to YES.

XML_OUTPUT = xml
XML_OUTPUT = doxyoutput/xml

# If the XML_PROGRAMLISTING tag is set to YES, doxygen will dump the program
# listings (including syntax highlighting and cross-referencing information) to
Expand Down
25 changes: 25 additions & 0 deletions api/docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = .
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile clean

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
mkdir -p doxyoutput
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

clean:
rm -rf doxyoutput
@$(SPHINXBUILD) -M clean "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
79 changes: 0 additions & 79 deletions api/docs/Overview.md

This file was deleted.

84 changes: 84 additions & 0 deletions api/docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Path setup --------------------------------------------------------------

# 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('.'))


# -- Project information -----------------------------------------------------

project = 'OpenTelemetry C++ API'
copyright = '2021, OpenTelemetry authors'
author = 'OpenTelemetry authors'

# Run doxygen
# -----------
# For the readthedocs builds, for some reason exhale doesn't find doxygen.
# So we run it manually here.
import subprocess
import os
if not os.path.isdir('doxyoutput'):
os.mkdir('doxyoutput')
subprocess.call(['doxygen'])


# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
"breathe",
"exhale",
]

breathe_projects = {
"OpenTelemetry C++ API": "./doxyoutput/xml"
}

breathe_default_project = "OpenTelemetry C++ API"

exhale_args = {
"containmentFolder": "otel_api",
"rootFileName": "otel_api.rst",
"rootFileTitle": "Reference documentation",
"doxygenStripFromPath": "..",
"exhaleUseDoxyfile": True,
"createTreeView": True,
}

primary_domain = "cpp"

higlight_language = "cpp"


# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']


# -- 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 = "sphinx_rtd_theme"

# 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']
2 changes: 2 additions & 0 deletions api/docs/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
OpenTelemetry C++ API
=====================
4 changes: 2 additions & 2 deletions buildscripts/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,5 @@ END
git add "$(pwd)/sdk/src/version/version.cc"

# Update documentation version
sed -i "/^PROJECT_BRIEF/cPROJECT_BRIEF = \"Version ${short_version}\"" "$(pwd)/api/docs/Doxyfile"
git add "$(pwd)/api/docs/Doxyfile"
sed -i "/^release =/crelease = \"${short_version}\"" "$(pwd)/docs/public/conf.py"
git add "$(pwd)/docs/public/conf.py"
17 changes: 17 additions & 0 deletions docs/public/GettingHelp.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Getting help
------------

- Refer to `opentelemetry.io <https://opentelemetry.io/>`__ for general
information about OpenTelemetry.
- Refer to the `OpenTelemetry C++ GitHub
repository <https://github.com/open-telemetry/opentelemetry-cpp>`__
for further information and resources related to OpenTelemetry C++.
- For questions related to OpenTelemetry C++ that are not covered by
the existing documentation, please ask away in `GitHub
discussions <https://github.com/open-telemetry/opentelemetry-cpp/discussions>`__.
- Feel free to join the `CNCF OpenTelemetry C++ Slack
channel <https://cloud-native.slack.com/archives/C01N3AT62SJ>`__. If
you are new, you can create a CNCF Slack account
`here <http://slack.cncf.io/>`__.
- For bugs and feature requests, write a `GitHub
issue <https://github.com/open-telemetry/opentelemetry-cpp/issues>`__.
52 changes: 52 additions & 0 deletions docs/public/GettingStarted.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
Getting started
---------------

Tracing
~~~~~~~

When instrumenting libraries and applications, the most simple approach
requires three steps.

Obtain a tracer
^^^^^^^^^^^^^^^

.. code:: cpp
auto provider = opentelemetry::trace::Provider::GetTracerProvider();
auto tracer = provider->GetTracer("foo_library", "1.0.0");
The ``TracerProvider`` acquired in the first step is a singleton object
that is usually provided by the OpenTelemetry C++ SDK. It is used to
provide specific implementations for API interfaces. In case no SDK is
used, the API provides a default no-op implementation of a
``TracerProvider``.

The ``Tracer`` acquired in the second step is needed to create and start
``Span``\ s.

Start a span
^^^^^^^^^^^^

.. code:: cpp
auto span = tracer->StartSpan("HandleRequest");
This creates a span, sets its name to ``"HandleRequest"``, and sets its
start time to the current time. Refer to the API documentation for other
operations that are available to enrich spans with additional data.

Mark a span as active
^^^^^^^^^^^^^^^^^^^^^

.. code:: cpp
auto scope = tracer->WithActiveSpan(span);
This marks a span as active and returns a ``Scope`` object bound to the
lifetime of the span. When the ``Scope`` object is destroyed, the
related span is ended.

The concept of an active span is important, as any span that is created
without explicitly specifying a parent is parented to the currently
active span.

25 changes: 25 additions & 0 deletions docs/public/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = .
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile clean

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

clean:
rm -rf doxyoutput
@$(SPHINXBUILD) -M clean ../../api/docs "$(BUILDDIR)" $(SPHINXOPTS) $(O)
@$(SPHINXBUILD) -M clean "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
26 changes: 26 additions & 0 deletions docs/public/Overview.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Overview
========

The OpenTelemetry C++ API enables developers to instrument their
applications and libraries in order to make them ready to create and
emit telemetry data. The OpenTelemetry C++ API exclusively focuses on
instrumentation and does not address concerns like exporting, sampling,
and aggregating telemetry data. Those concerns are addressed by the
OpenTelemetry C++ SDK. This architecture enables developers to
instrument applications and libraries with the OpenTelemetry C++ API
while being completely agnostic of how telemetry data is exported and
processed.

Library design
--------------

The OpenTelemetry C++ API is provided as a header-only library and
supports all recent versions of the C++ standard, down to C++11.

A single application might dynamically or statically link to different
libraries that were compiled with different compilers, while several of
the linked libraries are instrumented with OpenTelemetry. OpenTelemetry
C++ supports those scenarios by providing a stable ABI. This is achieved
by a careful API design, and most notably by providing ABI stable
versions of classes from the standard library. All those classes are
provided in the ``opentelemetry::nostd`` namespace.
Loading

0 comments on commit 0481fa0

Please sign in to comment.