Skip to content

Commit 59cfe06

Browse files
authored
Merge branch 'master' into majorgreys/datadog-resource-target
2 parents caef948 + f2bc613 commit 59cfe06

File tree

148 files changed

+3472
-439
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

148 files changed

+3472
-439
lines changed

.circleci/config.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
version: 2.1
2+
3+
executors:
4+
python38:
5+
docker:
6+
- image: circleci/python:3.8
7+
8+
commands:
9+
setup_tox:
10+
description: "Install tox"
11+
steps:
12+
- run: pip install -U tox-factor
13+
14+
restore_tox_cache:
15+
description: "Restore .tox directory from previous runs for faster installs"
16+
steps:
17+
- restore_cache:
18+
# In the cache key:
19+
# - .Environment.CIRCLE_JOB: We do separate tox environments by job name, so caching and restoring is
20+
# much faster.
21+
key: tox-cache-{{ .Environment.CIRCLE_JOB }}-{{ checksum "tox.ini" }}-{{ checksum "dev-requirements.txt" }}
22+
23+
save_tox_cache:
24+
description: "Save .tox directory into cache for faster installs next time"
25+
steps:
26+
- save_cache:
27+
# In the cache key:
28+
# - .Environment.CIRCLE_JOB: We do separate tox environments by job name, so caching and restoring is
29+
# much faster.
30+
key: tox-cache-{{ .Environment.CIRCLE_JOB }}-{{ checksum "tox.ini" }}-{{ checksum "dev-requirements.txt" }}
31+
paths:
32+
- ".tox"
33+
34+
jobs:
35+
docs:
36+
executor: python38
37+
steps:
38+
- checkout
39+
- setup_tox
40+
- restore_tox_cache
41+
- run: tox -e docs
42+
- save_tox_cache
43+
44+
lint:
45+
executor: python38
46+
steps:
47+
- checkout
48+
- setup_tox
49+
- restore_tox_cache
50+
- run: tox -e lint
51+
- save_tox_cache
52+
53+
workflows:
54+
main:
55+
jobs:
56+
- docs
57+
- lint

dev-requirements.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,4 @@ sphinx-rtd-theme~=0.4
88
sphinx-autodoc-typehints~=1.10.2
99
pytest!=5.2.3
1010
pytest-cov>=2.8
11-
readme-renderer~=24.0
12-
httpretty~=1.0
13-
opentracing~=2.2.0
11+
readme-renderer~=24.0

docs-requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ mysql-connector-python~=8.0
1414
opentracing~=2.2.0
1515
prometheus_client>=0.5.0,<1.0.0
1616
psycopg2-binary>=2.7.3.1
17+
pymemcache~=1.3
1718
pymongo~=3.1
19+
pyramid>=1.7
1820
redis>=2.6
1921
sqlalchemy>=1.0
2022
thrift>=0.10.0
@@ -24,3 +26,4 @@ boto~=2.0
2426
google-cloud-trace >=0.23.0
2527
google-cloud-monitoring>=0.36.0
2628
botocore~=1.0
29+
starlette~=0.13

docs/examples/cloud_monitoring/README.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ To use this exporter you first need to:
2222
2323
* Run example
2424

25-
.. code-block:: sh
26-
27-
python basic_metrics.py
25+
.. literalinclude:: basic_metrics.py
26+
:language: python
27+
:lines: 1-
2828

2929
Viewing Output
3030
--------------------------

docs/examples/cloud_trace_exporter/README.rst

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ Basic Example
88
-------------
99

1010
To use this exporter you first need to:
11-
* A Google Cloud project. You can `create one here. <https://console.cloud.google.com/projectcreate>`_
12-
* Enable Cloud Trace API (aka StackDriver Trace API) in the project `here. <https://console.cloud.google.com/apis/library?q=cloud_trace>`_
13-
* Enable `Default Application Credentials. <https://developers.google.com/identity/protocols/application-default-credentials>`_
11+
* A Google Cloud project. You can `create one here <https://console.cloud.google.com/projectcreate>`_.
12+
* Enable Cloud Trace API (listed in the Cloud Console as Stackdriver Trace API) in the project `here <https://console.cloud.google.com/apis/library?q=cloud%20trace&filter=visibility:public>`_.
13+
* If the page says "API Enabled" then you're done! No need to do anything.
14+
* Enable Default Application Credentials by creating setting `GOOGLE_APPLICATION_CREDENTIALS <https://cloud.google.com/docs/authentication/getting-started>`_ or by `installing gcloud sdk <https://cloud.google.com/sdk/install>`_ and calling ``gcloud auth application-default login``.
1415

1516
* Installation
1617

@@ -20,15 +21,59 @@ To use this exporter you first need to:
2021
pip install opentelemetry-sdk
2122
pip install opentelemetry-exporter-cloud-trace
2223
23-
* Run example
24+
* Run an example locally
2425

25-
.. code-block:: sh
26-
27-
python basic_trace.py
26+
.. literalinclude:: basic_trace.py
27+
:language: python
28+
:lines: 1-
2829

2930
Checking Output
3031
--------------------------
3132

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

34-
* `More information about exporters in general <https://opentelemetry-python.readthedocs.io/en/stable/getting-started.html#configure-exporters-to-emit-spans-elsewhere>`_
35+
36+
Further Reading
37+
--------------------------
38+
39+
* `More information about exporters in general <https://opentelemetry-python.readthedocs.io/en/stable/getting-started.html#configure-exporters-to-emit-spans-elsewhere>`_
40+
41+
Troubleshooting
42+
--------------------------
43+
44+
Running basic_trace.py hangs:
45+
#############################
46+
* 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.
47+
48+
Getting error ``google.api_core.exceptions.ResourceExhausted: 429 Resource has been exhausted``:
49+
################################################################################################
50+
* Check that you've enabled the `Cloud Trace (Stackdriver Trace) API <https://console.cloud.google.com/apis/library?q=cloud%20trace&filter=visibility:public>`_
51+
52+
bash: pip: command not found:
53+
#############################
54+
* `Install pip <https://cloud.google.com/python/setup#installing_python>`_
55+
* If your machine uses python2 by default, pip will also be the python2 version. Try using ``pip3`` instead of ``pip``.
56+
57+
pip install is hanging
58+
######################
59+
Try upgrading pip
60+
61+
.. code-block:: sh
62+
63+
pip install --upgrade pip
64+
65+
``pip install grcpio`` has been known to hang when you aren't using an upgraded version.
66+
67+
ImportError: No module named opentelemetry
68+
##########################################
69+
Make sure you are using python3. If
70+
71+
.. code-block:: sh
72+
73+
python --version
74+
75+
returns ``Python 2.X.X`` try calling
76+
77+
.. code-block:: sh
78+
79+
python3 basic_trace.py

docs/examples/datadog_exporter/README.rst

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,15 @@ Basic Example
3232

3333
.. code-block:: sh
3434
35-
python datadog_exporter.py
35+
python basic_example.py
3636
37-
Auto-Instrumention Example
38-
--------------------------
37+
38+
.. code-block:: sh
39+
40+
python basic_example.py
41+
42+
Distributed Example
43+
-------------------
3944

4045
* Installation
4146

@@ -79,3 +84,12 @@ Auto-Instrumention Example
7984
.. code-block:: sh
8085
8186
opentelemetry-instrument python client.py error
87+
88+
* Run Datadog instrumented client
89+
90+
The OpenTelemetry instrumented server is set up with propagation of Datadog trace context.
91+
92+
.. code-block:: sh
93+
94+
pip install ddtrace
95+
ddtrace-run python datadog_client.py testing

docs/examples/datadog_exporter/datadog_exporter.py renamed to docs/examples/datadog_exporter/basic_example.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
span_processor = DatadogExportSpanProcessor(exporter)
3232
trace.get_tracer_provider().add_span_processor(span_processor)
3333

34+
3435
with tracer.start_as_current_span("foo"):
3536
with tracer.start_as_current_span("bar"):
3637
with tracer.start_as_current_span("baz"):
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright The OpenTelemetry Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from sys import argv
16+
17+
import requests
18+
19+
requested = requests.get(
20+
"http://localhost:8082/server_request", params={"param": argv[1]}
21+
)
22+
assert requested.status_code == 200
23+
print(requested.text)

docs/examples/datadog_exporter/server.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414

1515
from flask import Flask, request
1616

17-
from opentelemetry import trace
17+
from opentelemetry import propagators, trace
1818
from opentelemetry.ext.datadog import (
1919
DatadogExportSpanProcessor,
2020
DatadogSpanExporter,
2121
)
22+
from opentelemetry.ext.datadog.propagator import DatadogFormat
2223
from opentelemetry.sdk.trace import TracerProvider
2324

2425
app = Flask(__name__)
@@ -33,6 +34,21 @@
3334
)
3435
)
3536

37+
# append Datadog format for propagation to and from Datadog instrumented services
38+
global_httptextformat = propagators.get_global_httptextformat()
39+
if isinstance(
40+
global_httptextformat, propagators.composite.CompositeHTTPPropagator
41+
) and not any(
42+
isinstance(p, DatadogFormat) for p in global_httptextformat._propagators
43+
):
44+
propagators.set_global_httptextformat(
45+
propagators.composite.CompositeHTTPPropagator(
46+
global_httptextformat._propagators + [DatadogFormat()]
47+
)
48+
)
49+
else:
50+
propagators.set_global_httptextformat(DatadogFormat())
51+
3652
tracer = trace.get_tracer(__name__)
3753

3854

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Copyright The OpenTelemetry Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
[metadata]
16+
name = opentelemetry-example-app
17+
description = OpenTelemetry Example App
18+
long_description = file: README.rst
19+
long_description_content_type = text/x-rst
20+
author = OpenTelemetry Authors
21+
author_email = cncf-opentelemetry-contributors@lists.cncf.io
22+
url = https://github.com/open-telemetry/opentelemetry-python/tree/master/opentelemetry-example-app
23+
platforms = any
24+
license = Apache-2.0
25+
classifiers =
26+
Development Status :: 4 - Beta
27+
Intended Audience :: Developers
28+
License :: OSI Approved :: Apache Software License
29+
Programming Language :: Python
30+
Programming Language :: Python :: 3
31+
Programming Language :: Python :: 3.4
32+
Programming Language :: Python :: 3.5
33+
Programming Language :: Python :: 3.6
34+
Programming Language :: Python :: 3.7
35+
Programming Language :: Python :: 3.8
36+
37+
[options]
38+
python_requires = >=3.4
39+
package_dir=
40+
=src
41+
packages = find_namespace:
42+
zip_safe = False
43+
include_package_data = True
44+
install_requires =
45+
typing; python_version<'3.5'
46+
opentelemetry-api == 0.10.dev0
47+
opentelemetry-sdk == 0.10.dev0
48+
opentelemetry-ext-requests == 0.10.dev0
49+
opentelemetry-ext-flask == 0.10.dev0
50+
flask
51+
requests
52+
protobuf~=3.11
53+
54+
[options.packages.find]
55+
where = src
56+
include = opentelemetry_example_app
57+
58+
[options.entry_points]
59+
opentelemetry_meter_provider =
60+
sdk_meter_provider = opentelemetry.sdk.metrics:MeterProvider
61+
opentelemetry_tracer_provider =
62+
sdk_tracer_provider = opentelemetry.sdk.trace:TracerProvider

docs/examples/opentelemetry-example-app/setup.py

Lines changed: 9 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -11,44 +11,16 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
import os
1415

1516
import setuptools
1617

17-
setuptools.setup(
18-
name="opentelemetry-example-app",
19-
version="0.9.dev0",
20-
author="OpenTelemetry Authors",
21-
author_email="cncf-opentelemetry-contributors@lists.cncf.io",
22-
classifiers=[
23-
"Development Status :: 4 - Beta",
24-
"Intended Audience :: Developers",
25-
"License :: OSI Approved :: Apache Software License",
26-
"Programming Language :: Python",
27-
"Programming Language :: Python :: 3",
28-
"Programming Language :: Python :: 3.4",
29-
"Programming Language :: Python :: 3.5",
30-
"Programming Language :: Python :: 3.6",
31-
"Programming Language :: Python :: 3.7",
32-
],
33-
description="OpenTelemetry Python API",
34-
include_package_data=True,
35-
long_description=open("README.rst").read(),
36-
install_requires=[
37-
"typing; python_version<'3.5'",
38-
"opentelemetry-api",
39-
"opentelemetry-sdk",
40-
"opentelemetry-ext-requests",
41-
"opentelemetry-ext-flask",
42-
"flask",
43-
"requests",
44-
"protobuf~=3.11",
45-
],
46-
license="Apache-2.0",
47-
package_dir={"": "src"},
48-
packages=setuptools.find_namespace_packages(where="src"),
49-
url=(
50-
"https://github.com/open-telemetry/opentelemetry-python"
51-
"/tree/master/opentelemetry-example-app"
52-
),
53-
zip_safe=False,
18+
BASE_DIR = os.path.dirname(__file__)
19+
VERSION_FILENAME = os.path.join(
20+
BASE_DIR, "src", "opentelemetry_example_app", "version.py"
5421
)
22+
PACKAGE_INFO = {}
23+
with open(VERSION_FILENAME) as f:
24+
exec(f.read(), PACKAGE_INFO)
25+
26+
setuptools.setup(version=PACKAGE_INFO["__version__"],)

0 commit comments

Comments
 (0)