Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into majorgreys/instru…
Browse files Browse the repository at this point in the history
…mentor-celery
  • Loading branch information
majorgreys committed Jun 16, 2020
2 parents 03cf262 + 39fa078 commit 8d293fd
Show file tree
Hide file tree
Showing 276 changed files with 10,312 additions and 1,278 deletions.
1 change: 1 addition & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ exclude =
ext/opentelemetry-ext-jaeger/build/*
docs/examples/opentelemetry-example-app/src/opentelemetry_example_app/grpc/gen/
docs/examples/opentelemetry-example-app/build/*
opentelemetry-proto/src/opentelemetry/proto/
2 changes: 1 addition & 1 deletion .isort.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ line_length=79
; docs: https://github.com/timothycrosley/isort#multi-line-output-modes
multi_line_output=3
skip=target
skip_glob=**/gen/*,.venv*/*,venv*/*
skip_glob=**/gen/*,.venv*/*,venv*/*,**/proto/*
known_first_party=opentelemetry,opentelemetry_example_app
known_third_party=psutil,pytest,redis,redis_opentracing
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ extension-pkg-whitelist=

# Add files or directories to the blacklist. They should be base names, not
# paths.
ignore=CVS,gen
ignore=CVS,gen,proto

# Add files or directories matching the regex patterns to the blacklist. The
# regex matches against base names, not paths.
Expand Down
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,29 +103,30 @@ 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)):

- [Carlos Alberto Cortez](https://github.com/carlosalberto), LightStep
- [Carlos Alberto Cortez](https://github.com/carlosalberto), Lightstep
- [Tahir H. Butt](https://github.com/majorgreys) DataDog
- [Chris Kleinknecht](https://github.com/c24t), Google
- [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
- [Reiley Yang](https://github.com/reyang), Microsoft

*Find more about the approver role in [community repository](https://github.com/open-telemetry/community/blob/master/community-membership.md#approver).*

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

- [Alex Boten](https://github.com/codeboten), LightStep
- [Alex Boten](https://github.com/codeboten), Lightstep
- [Leighton Chen](https://github.com/lzchen), Microsoft
- [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).*

### Thanks to all the people who already contributed!

<a href="https://github.com/open-telemetry/opentelemetry-python/graphs/contributors">
<img src="https://contributors-img.web.app/image?repo=open-telemetry/opentelemetry-python" />
</a>

*Find more about the maintainer role in [community repository](https://github.com/open-telemetry/community/blob/master/community-membership.md#maintainer).*

## Release Schedule

OpenTelemetry Python is under active development.
Expand Down
5 changes: 1 addition & 4 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@ pylint==2.4.4
flake8==3.7.9
isort~=4.3
black>=19.3b0,==19.*
mypy==0.740
mypy==0.770
sphinx~=2.1
sphinx-rtd-theme~=0.4
sphinx-autodoc-typehints~=1.10.2
pytest!=5.2.3
pytest-cov>=2.8
readme-renderer~=24.0
httpretty~=1.0
celery>=4.0
opentracing~=2.2.0
5 changes: 5 additions & 0 deletions docs-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ mysql-connector-python~=8.0
opentracing~=2.2.0
prometheus_client>=0.5.0,<1.0.0
psycopg2-binary>=2.7.3.1
pymemcache~=1.3
pymongo~=3.1
pyramid>=1.7
redis>=2.6
sqlalchemy>=1.0
thrift>=0.10.0
Expand All @@ -23,3 +25,6 @@ celery>=4.0
psutil~=5.7.0
boto~=2.0
google-cloud-trace >=0.23.0
google-cloud-monitoring>=0.36.0
botocore~=1.0
starlette~=0.13
3 changes: 2 additions & 1 deletion docs/api/trace.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ Submodules

trace.sampling
trace.status
trace.span

Module contents
---------------

.. automodule:: opentelemetry.trace
.. automodule:: opentelemetry.trace
7 changes: 7 additions & 0 deletions docs/api/trace.span.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
opentelemetry.trace.span
========================

.. automodule:: opentelemetry.trace.span
:members:
:undoc-members:
:show-inheritance:
15 changes: 0 additions & 15 deletions docs/auto_instrumentation/auto_instrumentation.rst

This file was deleted.

7 changes: 0 additions & 7 deletions docs/auto_instrumentation/instrumentor.rst

This file was deleted.

2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
source_dirs = [
os.path.abspath("../opentelemetry-api/src/"),
os.path.abspath("../opentelemetry-sdk/src/"),
os.path.abspath("../opentelemetry-auto-instrumentation/src/"),
os.path.abspath("../opentelemetry-instrumentation/src/"),
]

ext = "../ext"
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/auto-instrumentation/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Installation
.. code:: sh
$ pip install opentelemetry-sdk
$ pip install opentelemetry-auto-instrumentation
$ pip install opentelemetry-instrumentation
$ pip install opentelemetry-ext-flask
$ pip install requests
Expand Down Expand Up @@ -138,7 +138,7 @@ and run this instead:

.. code:: sh
$ opentelemetry-auto-instrumentation python server_uninstrumented.py
$ opentelemetry-instrument python server_uninstrumented.py
In the console where you previously executed ``client.py``, run again
this again:
Expand Down
17 changes: 9 additions & 8 deletions docs/examples/basic_meter/basic_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
from opentelemetry import metrics
from opentelemetry.sdk.metrics import Counter, MeterProvider, ValueRecorder
from opentelemetry.sdk.metrics.export import ConsoleMetricsExporter
from opentelemetry.sdk.metrics.export.controller import PushController

stateful = True

print(
"Starting example, values will be printed to the console every 5 seconds."
Expand All @@ -37,17 +34,21 @@
# Stateful determines whether how metrics are collected: if true, metrics
# accumulate over the process lifetime. If false, metrics are reset at the
# beginning of each collection interval.
metrics.set_meter_provider(MeterProvider(stateful))
stateful = True

# Sets the global MeterProvider instance
metrics.set_meter_provider(MeterProvider())

# The Meter is responsible for creating and recording metrics. Each meter has a
# unique name, which we set as the module's name here.
meter = metrics.get_meter(__name__)

# Exporter to export metrics to the console
exporter = ConsoleMetricsExporter()

# A PushController collects metrics created from meter and exports it via the
# exporter every interval
controller = PushController(meter=meter, exporter=exporter, interval=5)
# start_pipeline will notify the MeterProvider to begin collecting/exporting
# metrics with the given meter, exporter and interval in seconds
metrics.get_meter_provider().start_pipeline(meter, exporter, 5)

# Metric instruments allow to capture measurements
requests_counter = meter.create_metric(
Expand Down Expand Up @@ -77,7 +78,7 @@
# Update the metric instruments using the direct calling convention
requests_counter.add(25, staging_labels)
requests_size.record(100, staging_labels)
time.sleep(5)
time.sleep(10)

requests_counter.add(50, staging_labels)
requests_size.record(5000, staging_labels)
Expand Down
6 changes: 2 additions & 4 deletions docs/examples/basic_meter/calling_conventions.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@
from opentelemetry import metrics
from opentelemetry.sdk.metrics import Counter, MeterProvider, ValueRecorder
from opentelemetry.sdk.metrics.export import ConsoleMetricsExporter
from opentelemetry.sdk.metrics.export.controller import PushController

# Use the meter type provided by the SDK package
metrics.set_meter_provider(MeterProvider())
meter = metrics.get_meter(__name__)
exporter = ConsoleMetricsExporter()
controller = PushController(meter=meter, exporter=exporter, interval=5)
metrics.get_meter_provider().start_pipeline(meter, ConsoleMetricsExporter(), 5)

requests_counter = meter.create_metric(
name="requests",
Expand Down Expand Up @@ -62,7 +60,7 @@
# You can record metrics directly using the metric instrument. You pass in
# labels that you would like to record for.
requests_counter.add(25, labels)
time.sleep(5)
time.sleep(10)

print("Updating using a bound instrument...")
# You can record metrics with bound metric instruments. Bound metric
Expand Down
9 changes: 4 additions & 5 deletions docs/examples/basic_meter/observer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,12 @@
import psutil

from opentelemetry import metrics
from opentelemetry.sdk.metrics import MeterProvider
from opentelemetry.sdk.metrics import MeterProvider, ValueObserver
from opentelemetry.sdk.metrics.export import ConsoleMetricsExporter
from opentelemetry.sdk.metrics.export.batcher import UngroupedBatcher
from opentelemetry.sdk.metrics.export.controller import PushController

metrics.set_meter_provider(MeterProvider())
meter = metrics.get_meter(__name__)
exporter = ConsoleMetricsExporter()
controller = PushController(meter=meter, exporter=exporter, interval=2)
metrics.get_meter_provider().start_pipeline(meter, ConsoleMetricsExporter(), 5)


# Callback to gather cpu usage
Expand All @@ -43,6 +40,7 @@ def get_cpu_usage_callback(observer):
description="per-cpu usage",
unit="1",
value_type=float,
observer_type=ValueObserver,
label_keys=("cpu_number",),
)

Expand All @@ -59,6 +57,7 @@ def get_ram_usage_callback(observer):
description="RAM memory usage",
unit="1",
value_type=float,
observer_type=ValueObserver,
label_keys=(),
)

Expand Down
35 changes: 35 additions & 0 deletions docs/examples/cloud_monitoring/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
Cloud Monitoring Exporter Example
=================================

These examples show how to use OpenTelemetry to send metrics data to Cloud Monitoring.


Basic Example
-------------

To use this exporter you first need to:
* `Create a Google Cloud project <https://console.cloud.google.com/projectcreate>`_.
* Enable the Cloud Monitoring API (aka Stackdriver Monitoring API) in the project `here <https://console.cloud.google.com/apis/library?q=cloud_monitoring>`_.
* Enable `Default Application Credentials <https://developers.google.com/identity/protocols/application-default-credentials>`_.

* Installation

.. code-block:: sh
pip install opentelemetry-api
pip install opentelemetry-sdk
pip install opentelemetry-exporter-cloud-monitoring
* Run example

.. code-block:: sh
python basic_metrics.py
Viewing Output
--------------------------

After running the example:
* Go to the `Cloud Monitoring Metrics Explorer page <https://console.cloud.google.com/monitoring/metrics-explorer>`_.
* In "Find resource type and metric" enter "OpenTelemetry/request_counter".
* You can filter by labels and change the graphical output here as well.
43 changes: 43 additions & 0 deletions docs/examples/cloud_monitoring/basic_metrics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env python3
# 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 time

from opentelemetry import metrics
from opentelemetry.exporter.cloud_monitoring import (
CloudMonitoringMetricsExporter,
)
from opentelemetry.sdk.metrics import Counter, MeterProvider

metrics.set_meter_provider(MeterProvider())
meter = metrics.get_meter(__name__)
metrics.get_meter_provider().start_pipeline(
meter, CloudMonitoringMetricsExporter(), 5
)

requests_counter = meter.create_metric(
name="request_counter",
description="number of requests",
unit="1",
value_type=int,
metric_type=Counter,
label_keys=("environment"),
)

staging_labels = {"environment": "staging"}

for i in range(20):
requests_counter.add(25, staging_labels)
time.sleep(10)
22 changes: 19 additions & 3 deletions docs/examples/cloud_trace_exporter/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Basic Example

To use this exporter you first need to:
* A Google Cloud project. You can `create one here. <https://console.cloud.google.com/projectcreate>`_
* Enable Cloud Trace API (aka StackDriver Trace API) in the project `here. <https://console.cloud.google.com/apis/library?q=cloud_trace>`_
* Enable Cloud Trace API (aka Stackdriver Trace API) in the project `here. <https://console.cloud.google.com/apis/library?q=cloud_trace>`_
* Enable `Default Application Credentials. <https://developers.google.com/identity/protocols/application-default-credentials>`_

* Installation
Expand All @@ -20,15 +20,31 @@ To use this exporter you first need to:
pip install opentelemetry-sdk
pip install opentelemetry-exporter-cloud-trace
* Run example
* Run example locally

.. code-block:: sh
cd opentelemetry-python/docs/examples/cloud_trace_exporter
python basic_trace.py
Checking Output
--------------------------

After running any of these examples, you can go to `Cloud Trace overview <https://console.cloud.google.com/traces/list>`_ to see the results.

* `More information about exporters in general <https://opentelemetry-python.readthedocs.io/en/stable/getting-started.html#configure-exporters-to-emit-spans-elsewhere>`_

Further Reading
--------------------------

* `More information about exporters in general <https://opentelemetry-python.readthedocs.io/en/stable/getting-started.html#configure-exporters-to-emit-spans-elsewhere>`_

Troubleshooting
--------------------------

Running basic_trace.py hangs:
#############################
* Make sure you've setup Application Default Credentials. Either run ``gcloud auth application-default login`` or set the ``GOOGLE_APPLICATION_CREDENTIALS`` environment variable to be a path to a service account token file.

Getting error ``google.api_core.exceptions.ResourceExhausted: 429 Resource has been exhausted``:
################################################################################################
* Check that you've enabled the `Cloud Trace (Stackdriver Trace) API <https://console.cloud.google.com/apis/library?q=cloud_trace>`_
Loading

0 comments on commit 8d293fd

Please sign in to comment.