Skip to content

Commit

Permalink
Merge remote-tracking branch 'source/master' into feature/trace-get-c…
Browse files Browse the repository at this point in the history
…urrent-span
  • Loading branch information
toumorokoshi committed May 5, 2020
2 parents 71e70b6 + e119285 commit 12569ea
Show file tree
Hide file tree
Showing 193 changed files with 7,353 additions and 1,075 deletions.
1 change: 1 addition & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ exclude =
ext/opentelemetry-ext-jaeger/src/opentelemetry/ext/jaeger/gen/
ext/opentelemetry-ext-jaeger/build/*
docs/examples/opentelemetry-example-app/src/opentelemetry_example_app/grpc/gen/
docs/examples/opentelemetry-example-app/build/*
2 changes: 1 addition & 1 deletion .isort.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ multi_line_output=3
skip=target
skip_glob=**/gen/*,.venv*/*,venv*/*
known_first_party=opentelemetry,opentelemetry_example_app
known_third_party=psutil,pytest
known_third_party=psutil,pytest,redis,redis_opentracing
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ language: python
cache: pip

python:
- 'pypy3'
- '3.8'
- '3.4'
- '3.5'
- '3.6'
- '3.7'
- '3.8'
- 'pypy3'

#matrix:
# allow_failures:
Expand Down
10 changes: 10 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ on how to become a [**Member**](https://github.com/open-telemetry/community/blob
[**Approver**](https://github.com/open-telemetry/community/blob/master/community-membership.md#approver)
and [**Maintainer**](https://github.com/open-telemetry/community/blob/master/community-membership.md#maintainer).

# Find your right repo

This is the main repo for OpenTelemetry Python. Nevertheless, there are other repos that are related to this project.
Please take a look at this list first, your contributions may belong in one of these repos better:

1. [OpenTelemetry Contrib](https://github.com/open-telemetry/opentelemetry-python-contrib): Instrumentations for third-party
libraries and frameworks. There is an ongoing effort to migrate into the Opentelemetry Contrib repo some of the existing
programmatic instrumentations that are now in the `ext` directory in the main OpenTelemetry repo. Please ask in the Gitter
channel (see below) for guidance if you want to contribute with these instrumentations.

## Find a Buddy and get Started Quickly!

If you are looking for someone to help you find a starting point and be a resource for your first contribution, join our
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ See the [OpenTelemetry registry](https://opentelemetry.io/registry/?s=python) fo

See [CONTRIBUTING.md](CONTRIBUTING.md)

We meet weekly on Thursday at 8AM PT. The meeting is subject to change depending on contributors' availability. Check the [OpenTelemetry community calendar](https://calendar.google.com/calendar/embed?src=google.com_b79e3e90j7bbsa2n2p5an5lf60%40group.calendar.google.com) for specific dates.
We meet weekly on Thursday, and the time of the meeting alternates between 9AM PT and 4PM PT. The meeting is subject to change depending on contributors' availability. Check the [OpenTelemetry community calendar](https://calendar.google.com/calendar/embed?src=google.com_b79e3e90j7bbsa2n2p5an5lf60%40group.calendar.google.com) for specific dates.

Meetings take place via [Zoom video conference](https://zoom.us/j/6729396170).

Expand Down
3 changes: 2 additions & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pylint~=2.3
pylint==2.4.4
flake8~=3.7
isort~=4.3
black>=19.3b0,==19.*
Expand All @@ -9,3 +9,4 @@ sphinx-autodoc-typehints~=1.10.2
pytest!=5.2.3
pytest-cov>=2.8
readme-renderer~=24.0
httpretty~=1.0
16 changes: 9 additions & 7 deletions docs-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ sphinx-rtd-theme~=0.4
sphinx-autodoc-typehints~=1.10.2

# Required by ext packages
opentracing~=2.2.0
Deprecated>=1.2.6
thrift>=0.10.0
pymongo~=3.1
PyMySQL~=0.9.3
flask~=1.0
mysql-connector-python ~= 8.0
wrapt >= 1.0.0, < 2.0.0
psycopg2-binary >= 2.7.3.1
prometheus_client >= 0.5.0, < 1.0.0
mysql-connector-python~=8.0
opentracing~=2.2.0
prometheus_client>=0.5.0,<1.0.0
psycopg2-binary>=2.7.3.1
pymongo~=3.1
redis>=2.6
thrift>=0.10.0
wrapt >=1.0.0,<2.0.0
81 changes: 67 additions & 14 deletions docs/examples/auto-instrumentation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,9 @@ $ source auto_instrumentation/bin/activate
# Installation

```sh
$ pip install opentelemetry-api
$ pip install opentelemetry-sdk
$ pip install opentelemetry-auto-instrumentation
$ pip install ext/opentelemetry-ext-flask
$ pip install flask
$ pip install opentelemetry-ext-flask
$ pip install requests
```

Expand All @@ -71,42 +69,97 @@ This is done in 2 separate consoles, one to run each of the scripts that make up

```sh
$ source auto_instrumentation/bin/activate
$ python opentelemetry-python/opentelemetry-auto-instrumentation/example/server_instrumented.py
$ python opentelemetry-python/docs/examples/auto-instrumentation/server_instrumented.py
```

```sh
$ source auto_instrumentation/bin/activate
$ python opentelemetry-python/opentelemetry-auto-instrumentation/example/client.py testing
$ python opentelemetry-python/docs/examples/auto-instrumentation/client.py testing
```

The execution of `server_instrumented.py` should return an output similar to:

```sh
Hello, testing!
Span(name="serv_request", context=SpanContext(trace_id=0x9c0e0ce8f7b7dbb51d1d6e744a4dad49, span_id=0xd1ba3ec4c76a0d7f, trace_state={}), kind=SpanKind.INTERNAL, parent=None, start_time=2020-03-19T00:06:31.275719Z, end_time=2020-03-19T00:06:31.275920Z)
127.0.0.1 - - [18/Mar/2020 18:06:31] "GET /serv_request?helloStr=Hello%2C+testing%21 HTTP/1.1" 200 -
{
"name": "server_request",
"context": {
"trace_id": "0xfa002aad260b5f7110db674a9ddfcd23",
"span_id": "0x8b8bbaf3ca9c5131",
"trace_state": "{}"
},
"kind": "SpanKind.SERVER",
"parent_id": null,
"start_time": "2020-04-30T17:28:57.886397Z",
"end_time": "2020-04-30T17:28:57.886490Z",
"status": {
"canonical_code": "OK"
},
"attributes": {
"component": "http",
"http.method": "GET",
"http.server_name": "127.0.0.1",
"http.scheme": "http",
"host.port": 8082,
"http.host": "localhost:8082",
"http.target": "/server_request?param=testing",
"net.peer.ip": "127.0.0.1",
"net.peer.port": 52872,
"http.flavor": "1.1"
},
"events": [],
"links": []
}
```

## Execution of an automatically instrumented server

Now, kill the execution of `server_instrumented.py` with `ctrl + c` and run this instead:

```sh
$ opentelemetry-auto-instrumentation opentelemetry-python/opentelemetry-auto-instrumentation/example/server_uninstrumented.py
$ opentelemetry-auto-instrumentation python docs/examples/auto-instrumentation/server_uninstrumented.py
```

In the console where you previously executed `client.py`, run again this again:

```sh
$ python opentelemetry-python/opentelemetry-auto-instrumentation/example/client.py testing
$ python opentelemetry-python/docs/examples/auto-instrumentation/client.py testing
```

The execution of `server_uninstrumented.py` should return an output similar to:

```sh
Hello, testing!
Span(name="serv_request", context=SpanContext(trace_id=0xf26b28b5243e48f5f96bfc753f95f3f0, span_id=0xbeb179a095d087ed, trace_state={}), kind=SpanKind.SERVER, parent=<opentelemetry.trace.DefaultSpan object at 0x7f1a20a54908>, start_time=2020-03-19T00:24:18.828561Z, end_time=2020-03-19T00:24:18.845127Z)
127.0.0.1 - - [18/Mar/2020 18:24:18] "GET /serv_request?helloStr=Hello%2C+testing%21 HTTP/1.1" 200 -
{
"name": "server_request",
"context": {
"trace_id": "0x9f528e0b76189f539d9c21b1a7a2fc24",
"span_id": "0xd79760685cd4c269",
"trace_state": "{}"
},
"kind": "SpanKind.SERVER",
"parent_id": "0xb4fb7eee22ef78e4",
"start_time": "2020-04-30T17:10:02.400604Z",
"end_time": "2020-04-30T17:10:02.401858Z",
"status": {
"canonical_code": "OK"
},
"attributes": {
"component": "http",
"http.method": "GET",
"http.server_name": "127.0.0.1",
"http.scheme": "http",
"host.port": 8082,
"http.host": "localhost:8082",
"http.target": "/server_request?param=testing",
"net.peer.ip": "127.0.0.1",
"net.peer.port": 48240,
"http.flavor": "1.1",
"http.route": "/server_request",
"http.status_text": "OK",
"http.status_code": 200
},
"events": [],
"links": []
}
```

As you can see, both outputs are equivalentsince the automatic instrumentation does what the manual instrumentation does too.
Both outputs are equivalent since the automatic instrumentation does what the manual instrumentation does too.
3 changes: 0 additions & 3 deletions docs/examples/auto-instrumentation/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

from sys import argv

from flask import Flask
from requests import get

from opentelemetry import propagators, trace
Expand All @@ -24,8 +23,6 @@
SimpleExportSpanProcessor,
)

app = Flask(__name__)

trace.set_tracer_provider(TracerProvider())
tracer = trace.get_tracer_provider().get_tracer(__name__)

Expand Down
3 changes: 3 additions & 0 deletions docs/examples/auto-instrumentation/server_instrumented.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from flask import Flask, request

from opentelemetry import propagators, trace
from opentelemetry.ext.wsgi import collect_request_attributes
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import (
ConsoleSpanExporter,
Expand All @@ -38,6 +39,8 @@ def server_request():
parent=propagators.extract(
lambda dict_, key: dict_.get(key, []), request.headers
)["current-span"],
kind=trace.SpanKind.SERVER,
attributes=collect_request_attributes(request.environ),
):
print(request.args.get("param"))
return "served"
Expand Down
6 changes: 3 additions & 3 deletions docs/examples/basic_tracer/tests/test_tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ def test_basic_tracer(self):
(sys.executable, test_script)
).decode()

self.assertIn('name="foo"', output)
self.assertIn('name="bar"', output)
self.assertIn('name="baz"', output)
self.assertIn('"name": "foo"', output)
self.assertIn('"name": "bar"', output)
self.assertIn('"name": "baz"', output)
6 changes: 3 additions & 3 deletions docs/examples/http/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ HTTP Integration Example

This example shows how to use
:doc:`WSGI Middleware <../../ext/wsgi/wsgi>`
and :doc:`requests <../../ext/http_requests/http_requests>` integrations to
and :doc:`requests <../../ext/requests/requests>` integrations to
instrument an HTTP client and server in Python.

The source files required to run this example are available :scm_web:`here <docs/examples/http/>`.
Expand All @@ -16,7 +16,7 @@ Installation
pip install opentelemetry-api
pip install opentelemetry-sdk
pip install opentelemetry-ext-wsgi
pip install opentelemetry-ext-http-requests
pip install opentelemetry-ext-requests
pip install flask
Expand Down Expand Up @@ -60,6 +60,6 @@ Useful links
- OpenTelemetry_
- :doc:`../../api/trace`
- :doc:`../../ext/wsgi/wsgi`
- :doc:`../../ext/http_requests/http_requests`
- :doc:`../../ext/requests/requests`

.. _OpenTelemetry: https://github.com/open-telemetry/opentelemetry-python/
11 changes: 7 additions & 4 deletions docs/examples/http/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import requests

from opentelemetry import trace
from opentelemetry.ext import http_requests
from opentelemetry.ext.requests import RequestsInstrumentor
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import (
BatchExportSpanProcessor,
Expand All @@ -28,15 +28,18 @@

# The preferred tracer implementation must be set, as the opentelemetry-api
# defines the interface with a no-op implementation.
# It must be done before instrumenting any library.
trace.set_tracer_provider(TracerProvider())
tracer_provider = trace.get_tracer_provider()

# Enable instrumentation in the requests library.
RequestsInstrumentor().instrument()

# Configure a console span exporter.
exporter = ConsoleSpanExporter()
span_processor = BatchExportSpanProcessor(exporter)
tracer_provider.add_span_processor(span_processor)
trace.get_tracer_provider().add_span_processor(span_processor)

# Integrations are the glue that binds the OpenTelemetry API and the
# frameworks and libraries that are used together, automatically creating
# Spans and propagating context as appropriate.
http_requests.enable(tracer_provider)
response = requests.get(url="http://127.0.0.1:5000/")
18 changes: 10 additions & 8 deletions docs/examples/http/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import requests

from opentelemetry import trace
from opentelemetry.ext import http_requests
from opentelemetry.ext.requests import RequestsInstrumentor
from opentelemetry.ext.wsgi import OpenTelemetryMiddleware
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import (
Expand All @@ -30,21 +30,23 @@

# The preferred tracer implementation must be set, as the opentelemetry-api
# defines the interface with a no-op implementation.
# It must be done before instrumenting any library.
trace.set_tracer_provider(TracerProvider())
tracer = trace.get_tracer(__name__)

exporter = ConsoleSpanExporter()
span_processor = BatchExportSpanProcessor(exporter)
trace.set_tracer_provider(TracerProvider())
trace.get_tracer_provider().add_span_processor(span_processor)

# Integrations are the glue that binds the OpenTelemetry API and the
# frameworks and libraries that are used together, automatically creating
# Spans and propagating context as appropriate.
http_requests.enable(trace.get_tracer_provider())
RequestsInstrumentor().instrument()
app = flask.Flask(__name__)
app.wsgi_app = OpenTelemetryMiddleware(app.wsgi_app)

# Configure a console span exporter.
exporter = ConsoleSpanExporter()
span_processor = BatchExportSpanProcessor(exporter)
trace.get_tracer_provider().add_span_processor(span_processor)

tracer = trace.get_tracer(__name__)


@app.route("/")
def hello():
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/http/tests/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def test_http(self):
output = subprocess.check_output(
(sys.executable, test_script)
).decode()
self.assertIn('name="/"', output)
self.assertIn('"name": "/"', output)

@classmethod
def teardown_class(cls):
Expand Down
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 @@ -37,7 +37,7 @@
"typing; python_version<'3.5'",
"opentelemetry-api",
"opentelemetry-sdk",
"opentelemetry-ext-http-requests",
"opentelemetry-ext-requests",
"opentelemetry-ext-flask",
"flask",
"requests",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import flask
import requests

import opentelemetry.ext.http_requests
import opentelemetry.ext.requests
from opentelemetry import trace
from opentelemetry.ext.flask import FlaskInstrumentor
from opentelemetry.sdk.trace import TracerProvider
Expand All @@ -28,14 +28,20 @@
SimpleExportSpanProcessor,
)

# The preferred tracer implementation must be set, as the opentelemetry-api
# defines the interface with a no-op implementation.
# It must be done before instrumenting any library
trace.set_tracer_provider(TracerProvider())

opentelemetry.ext.requests.RequestsInstrumentor().instrument()
FlaskInstrumentor().instrument()

trace.get_tracer_provider().add_span_processor(
SimpleExportSpanProcessor(ConsoleSpanExporter())
)

FlaskInstrumentor().instrument()

app = flask.Flask(__name__)
opentelemetry.ext.http_requests.enable(trace.get_tracer_provider())


@app.route("/")
Expand Down
Loading

0 comments on commit 12569ea

Please sign in to comment.