Skip to content

Commit

Permalink
Split out auto instrumentation into new package
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanielRN committed Nov 25, 2020
1 parent 3da42e9 commit 5499d30
Show file tree
Hide file tree
Showing 11 changed files with 230 additions and 82 deletions.
11 changes: 11 additions & 0 deletions opentelemetry-auto-instrumentation/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Changelog

## Unreleased

- Initial Release
- Add IDs Generator as Configurable Property of Auto Instrumentation
([#1404](https://github.com/open-telemetry/opentelemetry-python/pull/1404))
- Added support for `OTEL_EXPORTER` to the `opentelemetry-instrument` command
([#1036](https://github.com/open-telemetry/opentelemetry-python/pull/1036))
- Split auto instrumentation into a new package
([#1415](https://github.com/open-telemetry/opentelemetry-python/pull/1415))
7 changes: 7 additions & 0 deletions opentelemetry-auto-instrumentation/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
prune tests
graft src
global-exclude *.pyc
global-exclude *.pyo
global-exclude __pycache__/*
include MANIFEST.in
include README.rst
98 changes: 98 additions & 0 deletions opentelemetry-auto-instrumentation/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
OpenTelemetry Auto Instrumentation
==================================

|pypi|

.. |pypi| image:: https://badge.fury.io/py/opentelemetry-auto-instrumentation.svg
:target: https://pypi.org/project/opentelemetry-auto-instrumentation/

Installation
------------

::

pip install opentelemetry-auto-instrumentation

This package provides a wrapper to automatically instrument applications. The
wrapper will automatically instrument the application's usage of dependencies if
the relevant instrumentation packages for those dependencies are installed.
These packages can be installed automatically using the `opentelmetry-bootstrap <https://github.com/open-telemetry/opentelemetry-python/tree/master/opentelemetry-instrumentation>`_ command.

opentelemetry-auto-instrument
-----------------------------

::

opentelemetry-instrument python program.py

The instrument command will try to automatically detect dependencies used by your python program
and when possible, apply automatic tracing instrumentation on them. This means your program
will get automatic distributed tracing for free without having to make any code changes
at all. This command will also configure the OTel SDK's TracerProvider as the global tracer provider
and the tracing exporter according to the specified configuration flags without you having to
make any code changes. By default, the instrument command will use the OTLP exporter but
this can be overridden when needed.

The command supports the following configuration options as CLI arguments and environment vars:

* ``--exporter`` or ``OTEL_EXPORTER``

Used to specify which trace exporter to use. Can be set to one or more
of the well-known exporter names (see below).

- Defaults to `otlp`.
- Can be set to `none` to disable automatic tracer initialization.

You can pass multiple values to configure multiple exporters e.g, ``zipkin,prometheus``

Well known trace exporter names:

- jaeger
- opencensus
- otlp
- otlp_span
- otlp_metric
- zipkin

``otlp`` is an alias for ``otlp_span,otlp_metric``.

* ``--service-name`` or ``OTEL_SERVICE_NAME``

When present the value is passed on to the relevant exporter initializer as ``service_name`` argument.

* ``--ids-generator`` or ``OTEL_IDS_GENERATOR``

Used to specify which IDs Generator to use for the global Tracer Provider. By default, it
will use the random IDs generator.

The code in ``program.py`` needs to use one of the packages for which there is
an OpenTelemetry integration. For a list of the available integrations please
check `here <https://opentelemetry-python.readthedocs.io/en/stable/index.html#integrations>`_

Examples
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

::

opentelemetry-instrument -e otlp flask run --port=3000

The above command will pass ``-e otlp`` to the instrument command and ``--port=3000`` to ``flask run``.

::

opentelemetry-instrument -e zipkin,otlp celery -A tasks worker --loglevel=info

The above command will configure global trace provider, attach zipkin and otlp exporters to it and then
start celery with the rest of the arguments.

::

opentelemetry-instrument --ids-generator random flask run --port=3000

The above command will configure the global trace provider to use the Random IDs Generator, and then
pass ``--port=3000`` to ``flask run``.

References
----------

* `OpenTelemetry Project <https://opentelemetry.io/>`_
55 changes: 55 additions & 0 deletions opentelemetry-auto-instrumentation/setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Copyright The OpenTelemetry Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
[metadata]
name = opentelemetry-auto-instrumentation
description = Auto Instrumentation for OpenTelemetry Python
long_description = file: README.rst
long_description_content_type = text/x-rst
author = OpenTelemetry Authors
author_email = [email protected]
url = https://github.com/open-telemetry/opentelemetry-python/tree/master/opentelemetry-auto-instrumentation
platforms = any
license = Apache-2.0
classifiers =
Development Status :: 4 - Beta
Intended Audience :: Developers
License :: OSI Approved :: Apache Software License
Programming Language :: Python
Programming Language :: Python :: 3
Programming Language :: Python :: 3.5
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8

[options]
python_requires = >=3.5
package_dir=
=src
packages=find_namespace:
zip_safe = False
include_package_data = True
install_requires =
opentelemetry-api == 0.16.dev0
opentelemetry-sdk == 0.16.dev0

[options.packages.find]
where = src

[options.entry_points]
console_scripts =
opentelemetry-instrument = opentelemetry.instrumentation.auto_instrumentation:run

[options.extras_require]
test =
32 changes: 32 additions & 0 deletions opentelemetry-auto-instrumentation/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright The OpenTelemetry Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os

import setuptools

BASE_DIR = os.path.dirname(__file__)
VERSION_FILENAME = os.path.join(
BASE_DIR,
"src",
"opentelemetry",
"instrumentation",
"auto_instrumentation",
"version.py",
)
PACKAGE_INFO = {}
with open(VERSION_FILENAME) as f:
exec(f.read(), PACKAGE_INFO)

setuptools.setup(version=PACKAGE_INFO["__version__"],)
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright The OpenTelemetry Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

__version__ = "0.16.dev0"
Empty file.
6 changes: 2 additions & 4 deletions opentelemetry-instrumentation/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# Changelog

## Unreleased

- Add IDs Generator as Configurable Property of Auto Instrumentation
([#1404](https://github.com/open-telemetry/opentelemetry-python/pull/1404))
- Added support for `OTEL_EXPORTER` to the `opentelemetry-instrument` command ([#1036](https://github.com/open-telemetry/opentelemetry-python/pull/1036))
- Split auto instrumentation into a new package
([#1415](https://github.com/open-telemetry/opentelemetry-python/pull/1415))

## Version 0.14b0

Expand Down
78 changes: 2 additions & 76 deletions opentelemetry-instrumentation/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ Installation
pip install opentelemetry-instrumentation


This package provides a couple of commands that help automatically instruments a program:
This package provides the following command to automatically find and install instrumentation
packages for the dependencies of a program:


opentelemetry-bootstrap
Expand All @@ -30,81 +31,6 @@ a list of the suggested instrumentation packages which can be added to a require
file. It also supports installing the suggested packages when run with :code:`--action=install`
flag.


opentelemetry-instrument
------------------------

::

opentelemetry-instrument python program.py

The instrument command will try to automatically detect packages used by your python program
and when possible, apply automatic tracing instrumentation on them. This means your program
will get automatic distributed tracing for free without having to make any code changes
at all. This will also configure a global tracer and tracing exporter without you having to
make any code changes. By default, the instrument command will use the OTLP exporter but
this can be overriden when needed.

The command supports the following configuration options as CLI arguments and environment vars:


* ``--exporter`` or ``OTEL_EXPORTER``

Used to specify which trace exporter to use. Can be set to one or more
of the well-known exporter names (see below).

- Defaults to `otlp`.
- Can be set to `none` to disable automatic tracer initialization.

You can pass multiple values to configure multiple exporters e.g, ``zipkin,prometheus``

Well known trace exporter names:

- jaeger
- opencensus
- otlp
- otlp_span
- otlp_metric
- zipkin

``otlp`` is an alias for ``otlp_span,otlp_metric``.

* ``--service-name`` or ``OTEL_SERVICE_NAME``

When present the value is passed on to the relevant exporter initializer as ``service_name`` argument.

* ``--ids-generator`` or ``OTEL_IDS_GENERATOR``

Used to specify which IDs Generator to use for the global Tracer Provider. By default, it
will use the random IDs generator.

The code in ``program.py`` needs to use one of the packages for which there is
an OpenTelemetry integration. For a list of the available integrations please
check `here <https://opentelemetry-python.readthedocs.io/en/stable/index.html#integrations>`_

Examples
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

::

opentelemetry-instrument -e otlp flask run --port=3000

The above command will pass ``-e otlp`` to the instrument command and ``--port=3000`` to ``flask run``.

::

opentelemetry-instrument -e zipkin,otlp celery -A tasks worker --loglevel=info

The above command will configure global trace provider, attach zipkin and otlp exporters to it and then
start celery with the rest of the arguments.

::

opentelemetry-instrument --ids-generator random flask run --port=3000

The above command will configure the global trace provider to use the Random IDs Generator, and then
pass ``--port=3000`` to ``flask run``.

References
----------

Expand Down
3 changes: 1 addition & 2 deletions opentelemetry-instrumentation/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#
[metadata]
name = opentelemetry-instrumentation
description = Instrumentation Tools & Auto Instrumentation for OpenTelemetry Python
description = Instrumentation Tools for OpenTelemetry Python
long_description = file: README.rst
long_description_content_type = text/x-rst
author = OpenTelemetry Authors
Expand Down Expand Up @@ -49,7 +49,6 @@ where = src

[options.entry_points]
console_scripts =
opentelemetry-instrument = opentelemetry.instrumentation.auto_instrumentation:run
opentelemetry-bootstrap = opentelemetry.instrumentation.bootstrap:run

[options.extras_require]
Expand Down
7 changes: 7 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ envlist =
py3{5,6,7,8}-test-core-instrumentation
pypy3-test-core-instrumentation

; opentelemetry-auto-instrumentation
py3{5,6,7,8}-test-core-auto_instrumentation
pypy3-test-core-auto_instrumentation

; docs/getting-started
py3{5,6,7,8}-test-core-getting-started
pypy3-test-core-getting-started
Expand Down Expand Up @@ -68,6 +72,7 @@ changedir =
test-core-api: opentelemetry-api/tests
test-core-sdk: opentelemetry-sdk/tests
test-core-proto: opentelemetry-proto/tests
test-core-auto_instrumentation: opentelemetry-auto-instrumentation/tests
test-core-instrumentation: opentelemetry-instrumentation/tests
test-core-getting-started: docs/getting_started/tests
test-core-opentracing-shim: instrumentation/opentelemetry-instrumentation-opentracing-shim/tests
Expand All @@ -88,6 +93,8 @@ commands_pre =
test-core-proto: pip install {toxinidir}/opentelemetry-proto
instrumentation: pip install {toxinidir}/opentelemetry-instrumentation

core-auto_instrumentation: pip install {toxinidir}/opentelemetry-auto-instrumentation

getting-started: pip install -e {toxinidir}/opentelemetry-instrumentation -e {toxinidir}/opentelemetry-python-contrib/instrumentation/opentelemetry-instrumentation-requests -e {toxinidir}/opentelemetry-python-contrib/instrumentation/opentelemetry-instrumentation-wsgi -e {toxinidir}/opentelemetry-python-contrib/instrumentation/opentelemetry-instrumentation-flask

opencensus: pip install {toxinidir}/exporter/opentelemetry-exporter-opencensus
Expand Down

0 comments on commit 5499d30

Please sign in to comment.