Skip to content

Commit

Permalink
Merge branch 'master' into tracer_provider_force_flush
Browse files Browse the repository at this point in the history
  • Loading branch information
toumorokoshi authored May 5, 2020
2 parents b4277bf + e119285 commit 0336f3e
Show file tree
Hide file tree
Showing 42 changed files with 422 additions and 159 deletions.
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: 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/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/
4 changes: 2 additions & 2 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 @@ -32,7 +32,7 @@
trace.set_tracer_provider(TracerProvider())

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

# Configure a console span exporter.
exporter = ConsoleSpanExporter()
Expand Down
4 changes: 2 additions & 2 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 @@ -36,7 +36,7 @@
# 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.RequestsInstrumentor().instrument()
RequestsInstrumentor().instrument()
app = flask.Flask(__name__)
app.wsgi_app = OpenTelemetryMiddleware(app.wsgi_app)

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 @@ -33,7 +33,7 @@
# It must be done before instrumenting any library
trace.set_tracer_provider(TracerProvider())

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

trace.get_tracer_provider().add_span_processor(
Expand Down
7 changes: 0 additions & 7 deletions docs/ext/grpc/grpc.client_interceptor.rst

This file was deleted.

11 changes: 2 additions & 9 deletions docs/ext/grpc/grpc.rst
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
.. include:: ../../../ext/opentelemetry-ext-grpc/README.rst

Submodules
----------

.. toctree::

grpc.client_interceptor
grpc.server_interceptor
OpenTelemetry gRPC Integration
==============================

Module contents
---------------
Expand Down
7 changes: 0 additions & 7 deletions docs/ext/grpc/grpc.server_interceptor.rst

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
OpenTelemetry requests Integration
==================================

.. automodule:: opentelemetry.ext.http_requests
.. automodule:: opentelemetry.ext.requests
:members:
:undoc-members:
:show-inheritance:
6 changes: 3 additions & 3 deletions docs/getting-started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ We will now instrument a basic Flask application that uses the requests library
.. code-block:: sh
pip install opentelemetry-ext-flask
pip install opentelemetry-ext-http-requests
pip install opentelemetry-ext-requests
And let's write a small Flask application that sends an HTTP request, activating each instrumentation during the initialization:
Expand All @@ -190,7 +190,7 @@ And let's write a small Flask application that sends an HTTP request, activating
import flask
import requests
import opentelemetry.ext.http_requests
import opentelemetry.ext.requests
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import ConsoleSpanExporter
Expand All @@ -202,7 +202,7 @@ And let's write a small Flask application that sends an HTTP request, activating
)
app = flask.Flask(__name__)
opentelemetry.ext.http_requests.RequestsInstrumentor().instrument()
opentelemetry.ext.requests.RequestsInstrumentor().instrument()
@app.route("/")
def hello():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def test_executemany(self):
"""Should create a child span for executemany
"""
with self._tracer.start_as_current_span("rootSpan"):
data = ["1", "2", "3"]
data = (("1",), ("2",), ("3",))
stmt = "INSERT INTO test (id) VALUES (%s)"
self._cursor.executemany(stmt, data)
self.validate_spans()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def test_executemany(self):
"""Should create a child span for executemany
"""
with self._tracer.start_as_current_span("rootSpan"):
data = ("1", "2", "3")
data = (("1",), ("2",), ("3",))
stmt = "INSERT INTO test (id) VALUES (%s)"
self._cursor.executemany(stmt, data)
self.validate_spans()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def test_executemany(self):
"""Should create a child span for executemany
"""
with self._tracer.start_as_current_span("rootSpan"):
data = ["1", "2", "3"]
data = (("1",), ("2",), ("3",))
stmt = "INSERT INTO test (id) VALUES (%s)"
self._cursor.executemany(stmt, data)
self.validate_spans()
Expand Down
3 changes: 3 additions & 0 deletions ext/opentelemetry-ext-flask/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

- Add exclude list for paths and hosts
([#630](https://github.com/open-telemetry/opentelemetry-python/pull/630))

## 0.6b0

Released 2020-03-30
Expand Down
11 changes: 11 additions & 0 deletions ext/opentelemetry-ext-flask/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ Installation

pip install opentelemetry-ext-flask

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_FLASK_EXCLUDED_HOSTS
Excluded paths: OPENTELEMETRY_PYTHON_FLASK_EXCLUDED_PATHS


References
----------
Expand Down
Loading

0 comments on commit 0336f3e

Please sign in to comment.