Skip to content

Commit

Permalink
Merge remote-tracking branch 'ot/master' into utils-package
Browse files Browse the repository at this point in the history
  • Loading branch information
cnnradams committed Jun 1, 2020
2 parents 3870e3b + 602ddb0 commit 57ec4f9
Show file tree
Hide file tree
Showing 97 changed files with 1,171 additions and 244 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,10 @@ Meeting notes are available as a public [Google doc](https://docs.google.com/doc

Approvers ([@open-telemetry/python-approvers](https://github.com/orgs/open-telemetry/teams/python-approvers)):

- [Alex Boten](https://github.com/codeboten), LightStep
- [Carlos Alberto Cortez](https://github.com/carlosalberto), LightStep
- [Chris Kleinknecht](https://github.com/c24t), Google
- [Christian Neumüller](https://github.com/Oberon00), Dynatrace
- [Diego Hurtado](https://github.com/ocelotl)
- [Hector Hernandez](https://github.com/hectorhdzg), Microsoft
- [Leighton Chen](https://github.com/lzchen), Microsoft
- [Mauricio Vásquez](https://github.com/mauriciovasquezbernal), Kinvolk
Expand All @@ -115,7 +116,7 @@ Approvers ([@open-telemetry/python-approvers](https://github.com/orgs/open-telem

Maintainers ([@open-telemetry/python-maintainers](https://github.com/orgs/open-telemetry/teams/python-maintainers)):

- [Chris Kleinknecht](https://github.com/c24t), Google
- [Alex Boten](https://github.com/codeboten), LightStep
- [Yusuke Tsutsumi](https://github.com/toumorokoshi), Zillow Group

*Find more about the maintainer role in [community repository](https://github.com/open-telemetry/community/blob/master/community-membership.md#maintainer).*
Expand Down
4 changes: 3 additions & 1 deletion RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
This document explains how to publish all OT modules at version x.y.z. Ensure that you’re following semver when choosing a version number.

Release Process:
* [Checkout a clean repo](#checkout-a-clean-repo)
* [Create a new branch](#create-a-new-branch)
* [Open a Pull Request](#open-a-pull-request)
* [Create a Release](#Create-a-Release)
Expand All @@ -10,6 +11,8 @@ Release Process:
* [Check PyPI](#Check-PyPI)
* [Troubleshooting](#troubleshooting)

## Checkout a clean repo
- To avoid pushing untracked changes, check out the repo in a new dir

## Create a new branch
The following script does the following:
Expand Down Expand Up @@ -74,7 +77,6 @@ git commit -m

If for some reason the action failed, do it manually:

- To avoid pushing untracked changes, check out the repo in a new dir
- Switch to the release branch (important so we don't publish packages with "dev" versions)
- Build distributions with `./scripts/build.sh`
- Delete distributions we don't want to push (e.g. `testutil`)
Expand Down
5 changes: 3 additions & 2 deletions docs-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ sphinx-autodoc-typehints~=1.10.2
# Required by ext packages
asgiref~=3.0
ddtrace>=0.34.0
aiohttp ~= 3.0
aiohttp~= 3.0
Deprecated>=1.2.6
django>=2.2
PyMySQL~=0.9.3
Expand All @@ -18,4 +18,5 @@ pymongo~=3.1
redis>=2.6
sqlalchemy>=1.0
thrift>=0.10.0
wrapt >=1.0.0,<2.0.0
wrapt>=1.0.0,<2.0.0
psutil~=5.7.0
2 changes: 1 addition & 1 deletion docs/examples/opentelemetry-example-app/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

setuptools.setup(
name="opentelemetry-example-app",
version="0.8.dev0",
version="0.9.dev0",
author="OpenTelemetry Authors",
author_email="[email protected]",
classifiers=[
Expand Down
7 changes: 7 additions & 0 deletions docs/ext/system_metrics/system_metrics.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
OpenTelemetry System Metrics Instrumentation
============================================

.. automodule:: opentelemetry.ext.system_metrics
:members:
:undoc-members:
:show-inheritance:
4 changes: 2 additions & 2 deletions ext/opentelemetry-ext-aiohttp-client/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ package_dir=
=src
packages=find_namespace:
install_requires =
opentelemetry-api >= 0.8.dev0
opentelemetry-instrumentation-utils == 0.8.dev0
opentelemetry-api >= 0.9.dev0
opentelemetry-instrumentation-utils == 0.9.dev0
aiohttp ~= 3.0

[options.packages.find]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.

__version__ = "0.8.dev0"
__version__ = "0.9.dev0"
4 changes: 4 additions & 0 deletions ext/opentelemetry-ext-asgi/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@

## Unreleased

## 0.8b0

Released 2020-05-27

- Add ASGI middleware ([#716](https://github.com/open-telemetry/opentelemetry-python/pull/716))
2 changes: 1 addition & 1 deletion ext/opentelemetry-ext-asgi/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ package_dir=
=src
packages=find_namespace:
install_requires =
opentelemetry-api == 0.8.dev0
opentelemetry-api == 0.9.dev0
asgiref ~= 3.0

[options.extras_require]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.

__version__ = "0.8.dev0"
__version__ = "0.9.dev0"
4 changes: 4 additions & 0 deletions ext/opentelemetry-ext-datadog/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

## 0.8b0

Released 2020-05-27

- Add exporter to Datadog
([#572](https://github.com/open-telemetry/opentelemetry-python/pull/572))

4 changes: 2 additions & 2 deletions ext/opentelemetry-ext-datadog/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ package_dir=
packages=find_namespace:
install_requires =
ddtrace>=0.34.0
opentelemetry-api==0.8.dev0
opentelemetry-sdk==0.8.dev0
opentelemetry-api==0.9.dev0
opentelemetry-sdk==0.9.dev0

[options.packages.find]
where = src
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
AUTO_REJECT = 0
AUTO_KEEP = 1
USER_KEEP = 2
SAMPLE_RATE_METRIC_KEY = "_sample_rate"
SAMPLING_PRIORITY_KEY = "_sampling_priority_v1"
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from opentelemetry.trace.status import StatusCanonicalCode

# pylint:disable=relative-beyond-top-level
from .constants import DD_ORIGIN
from .constants import DD_ORIGIN, SAMPLE_RATE_METRIC_KEY

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -136,6 +136,10 @@ def _translate_to_datadog(self, spans):
if origin and parent_id == 0:
datadog_span.set_tag(DD_ORIGIN, origin)

sampling_rate = _get_sampling_rate(span)
if sampling_rate is not None:
datadog_span.set_metric(SAMPLE_RATE_METRIC_KEY, sampling_rate)

# span events and span links are not supported

datadog_spans.append(datadog_span)
Expand Down Expand Up @@ -216,3 +220,13 @@ def _get_origin(span):
ctx = span.get_context()
origin = ctx.trace_state.get(DD_ORIGIN)
return origin


def _get_sampling_rate(span):
ctx = span.get_context()
return (
span.sampler.rate
if ctx.trace_flags.sampled
and isinstance(span.sampler, trace_api.sampling.ProbabilitySampler)
else None
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.

__version__ = "0.8.dev0"
__version__ = "0.9.dev0"
32 changes: 32 additions & 0 deletions ext/opentelemetry-ext-datadog/tests/test_datadog_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,3 +440,35 @@ def test_origin(self):
]
expected = ["origin-service", None]
self.assertListEqual(actual, expected)

def test_sampling_rate(self):
context = trace_api.SpanContext(
trace_id=0x000000000000000000000000DEADBEEF,
span_id=0x34BF92DEEFC58C92,
is_remote=False,
trace_flags=trace_api.TraceFlags(trace_api.TraceFlags.SAMPLED),
)
sampler = trace_api.sampling.ProbabilitySampler(0.5)

span = trace.Span(
name="sampled", context=context, parent=None, sampler=sampler
)
span.start()
span.end()

# pylint: disable=protected-access
exporter = datadog.DatadogSpanExporter()
datadog_spans = [
span.to_dict() for span in exporter._translate_to_datadog([span])
]

self.assertEqual(len(datadog_spans), 1)

actual = [
span["metrics"].get(datadog.constants.SAMPLE_RATE_METRIC_KEY)
if "metrics" in span
else None
for span in datadog_spans
]
expected = [0.5]
self.assertListEqual(actual, expected)
6 changes: 3 additions & 3 deletions ext/opentelemetry-ext-dbapi/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ package_dir=
=src
packages=find_namespace:
install_requires =
opentelemetry-api == 0.8.dev0
opentelemetry-instrumentation-utils == 0.8.dev0
opentelemetry-api == 0.9.dev0
opentelemetry-instrumentation-utils == 0.9.dev0
wrapt >= 1.0.0, < 2.0.0

[options.extras_require]
test =
opentelemetry-test == 0.8.dev0
opentelemetry-test == 0.9.dev0

[options.packages.find]
where = src
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.

__version__ = "0.8.dev0"
__version__ = "0.9.dev0"
8 changes: 7 additions & 1 deletion ext/opentelemetry-ext-django/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@

## Unreleased

- Add support for django >= 1.10 (#717)
## 0.8b0

Released 2020-05-27

- Add exclude list for paths and hosts to prevent from tracing
([#670](https://github.com/open-telemetry/opentelemetry-python/pull/670))
- Add support for django >= 1.10 (#717)

## 0.7b1

Expand Down
10 changes: 10 additions & 0 deletions ext/opentelemetry-ext-django/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ Installation

pip install opentelemetry-ext-django

Configuration
-------------

Exclude lists
*************
Excludes certain hosts and paths from being tracked. Pass in comma delimited string into environment variables.
Host refers to the entire url and path refers to the part of the url after the domain. Host matches the exact string that is given, where as path matches if the url starts with the given excluded path.

Excluded hosts: OPENTELEMETRY_PYTHON_DJANGO_EXCLUDED_HOSTS
Excluded paths: OPENTELEMETRY_PYTHON_DJANGO_EXCLUDED_PATHS

References
----------
Expand Down
8 changes: 4 additions & 4 deletions ext/opentelemetry-ext-django/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ package_dir=
packages=find_namespace:
install_requires =
django >= 1.10
opentelemetry-ext-wsgi == 0.8.dev0
opentelemetry-auto-instrumentation == 0.8.dev0
opentelemetry-api == 0.8.dev0
opentelemetry-ext-wsgi == 0.9.dev0
opentelemetry-auto-instrumentation == 0.9.dev0
opentelemetry-api == 0.9.dev0

[options.extras_require]
test =
opentelemetry-test == 0.8.dev0
opentelemetry-test == 0.9.dev0

[options.packages.find]
where = src
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from logging import getLogger

from opentelemetry.configuration import Configuration
from opentelemetry.context import attach, detach
from opentelemetry.ext.django.version import __version__
from opentelemetry.ext.wsgi import (
Expand All @@ -23,6 +24,7 @@
)
from opentelemetry.propagators import extract
from opentelemetry.trace import SpanKind, get_tracer
from opentelemetry.util import disable_trace

try:
from django.utils.deprecation import MiddlewareMixin
Expand All @@ -42,6 +44,13 @@ class _DjangoMiddleware(MiddlewareMixin):
_environ_token = "opentelemetry-instrumentor-django.token"
_environ_span_key = "opentelemetry-instrumentor-django.span_key"

_excluded_hosts = Configuration().DJANGO_EXCLUDED_HOSTS or []
_excluded_paths = Configuration().DJANGO_EXCLUDED_PATHS or []
if _excluded_hosts:
_excluded_hosts = str.split(_excluded_hosts, ",")
if _excluded_paths:
_excluded_paths = str.split(_excluded_paths, ",")

def process_view(
self, request, view_func, view_args, view_kwargs
): # pylint: disable=unused-argument
Expand All @@ -53,6 +62,12 @@ def process_view(
# key.lower().replace('_', '-').replace("http-", "", 1): value
# for key, value in request.META.items()
# }
if disable_trace(
request.build_absolute_uri("?"),
self._excluded_hosts,
self._excluded_paths,
):
return

environ = request.META

Expand Down Expand Up @@ -82,6 +97,13 @@ def process_exception(self, request, exception):
# Django can call this method and process_response later. In order
# to avoid __exit__ and detach from being called twice then, the
# respective keys are being removed here.
if disable_trace(
request.build_absolute_uri("?"),
self._excluded_hosts,
self._excluded_paths,
):
return

if self._environ_activation_key in request.META.keys():
request.META[self._environ_activation_key].__exit__(
type(exception),
Expand All @@ -94,6 +116,13 @@ def process_exception(self, request, exception):
request.META.pop(self._environ_token, None)

def process_response(self, request, response):
if disable_trace(
request.build_absolute_uri("?"),
self._excluded_hosts,
self._excluded_paths,
):
return response

if (
self._environ_activation_key in request.META.keys()
and self._environ_span_key in request.META.keys()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.

__version__ = "0.8.dev0"
__version__ = "0.9.dev0"
Loading

0 comments on commit 57ec4f9

Please sign in to comment.