From b346942932f68229021af6d249948fcdbc4e8aae Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Tue, 10 Dec 2019 17:19:14 -0600 Subject: [PATCH 01/27] Add autoinstrumentation prototype for Flask Fixes #300 --- docs/conf.py | 1 + docs/index.rst | 4 +- ...telemetry.auto_instrumentation.patcher.rst | 8 + examples/auto_instrumentation/README.md | 119 ++++++++++++ examples/auto_instrumentation/formatter.py | 52 ++++++ examples/auto_instrumentation/hello.py | 67 +++++++ .../publisher_instrumented.py | 52 ++++++ .../publisher_uninstrumented.py | 41 ++++ examples/auto_instrumentation/utils.py | 21 +++ .../flask_example.py | 78 ++++++++ ext/opentelemetry-ext-flask/setup.py | 9 +- .../src/opentelemetry/ext/flask/__init__.py | 175 ++++++++++-------- ext/opentelemetry-ext-flask/tests/conftest.py | 24 +++ .../tests/test_flask_integration.py | 2 - .../CHANGELOG.md | 1 + .../MANIFEST.in | 7 + opentelemetry-auto-instrumentation/README.rst | 32 ++++ opentelemetry-auto-instrumentation/setup.cfg | 50 +++++ opentelemetry-auto-instrumentation/setup.py | 27 +++ .../auto_instrumentation/__init__.py | 0 .../auto_instrumentation.py | 38 ++++ .../auto_instrumentation/patcher.py | 65 +++++++ .../auto_instrumentation/version.py | 15 ++ .../tests/__init__.py | 13 ++ .../tests/test_patcher.py | 44 +++++ tox.ini | 9 + 26 files changed, 875 insertions(+), 79 deletions(-) create mode 100644 docs/opentelemetry.auto_instrumentation.patcher.rst create mode 100644 examples/auto_instrumentation/README.md create mode 100644 examples/auto_instrumentation/formatter.py create mode 100644 examples/auto_instrumentation/hello.py create mode 100644 examples/auto_instrumentation/publisher_instrumented.py create mode 100644 examples/auto_instrumentation/publisher_uninstrumented.py create mode 100644 examples/auto_instrumentation/utils.py create mode 100644 examples/opentelemetry-example-app/src/opentelemetry_example_app/flask_example.py create mode 100644 ext/opentelemetry-ext-flask/tests/conftest.py create mode 100644 opentelemetry-auto-instrumentation/CHANGELOG.md create mode 100644 opentelemetry-auto-instrumentation/MANIFEST.in create mode 100644 opentelemetry-auto-instrumentation/README.rst create mode 100644 opentelemetry-auto-instrumentation/setup.cfg create mode 100644 opentelemetry-auto-instrumentation/setup.py create mode 100644 opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/__init__.py create mode 100644 opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/auto_instrumentation.py create mode 100644 opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/patcher.py create mode 100644 opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/version.py create mode 100644 opentelemetry-auto-instrumentation/tests/__init__.py create mode 100644 opentelemetry-auto-instrumentation/tests/test_patcher.py diff --git a/docs/conf.py b/docs/conf.py index a509f14f5d6..acd44c0c7af 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -18,6 +18,7 @@ source_dirs = [ os.path.abspath("../opentelemetry-api/src/"), os.path.abspath("../opentelemetry-sdk/src/"), + os.path.abspath("../opentelemetry-auto-instrumentation/src/"), ] ext = "../ext" diff --git a/docs/index.rst b/docs/index.rst index bc09b5a4759..777bd0dfde4 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -61,7 +61,6 @@ install getting-started - .. toctree:: :maxdepth: 1 :caption: OpenTelemetry Python Packages @@ -83,6 +82,9 @@ install :caption: Examples :name: examples :glob: + :caption: OpenTelemetry Auto Instrumentation: + + opentelemetry.auto_instrumentation.patcher examples/** diff --git a/docs/opentelemetry.auto_instrumentation.patcher.rst b/docs/opentelemetry.auto_instrumentation.patcher.rst new file mode 100644 index 00000000000..731d03d6e07 --- /dev/null +++ b/docs/opentelemetry.auto_instrumentation.patcher.rst @@ -0,0 +1,8 @@ +opentelemetry.auto_instrumentation.patcher package +================================================== + + +Module contents +--------------- + +.. automodule:: opentelemetry.auto_instrumentation.patcher diff --git a/examples/auto_instrumentation/README.md b/examples/auto_instrumentation/README.md new file mode 100644 index 00000000000..431593e3f4c --- /dev/null +++ b/examples/auto_instrumentation/README.md @@ -0,0 +1,119 @@ +# Overview + +This example shows how to use auto-instrumentation in OpenTelemetry. This example is also based on a previous example +for OpenTracing that can be found [here](https://github.com/yurishkuro/opentracing-tutorial/tree/master/python). + +This example uses 2 scripts whose main difference is they being instrumented manually or not: + +1. `publisher_instrumented.py` which has been instrumented manually +2. `publisher_uninstrumented.py` which has not been instrumented manually + +The former will be run without the automatic instrumentation agent and the latter with the automatic instrumentation +agent. They should produce an equal result, showing that the automatic instrumentation agent does the equivalent +of what manual instrumentation does. + +In order to understand this better, here is the relevant part of both scripts: + +## Publisher instrumented manually + +`publisher_instrumented.py` + +```python +@app.route("/publish_request") +def publish_request(): + + with tracer.start_as_current_span( + "publish_request", propagators.extract(get_as_list, request.headers) + ): + hello_str = request.args.get("helloStr") + print(hello_str) + return "published" +``` + +## Publisher not instrumented manually + +`publisher_uninstrumented.py` + +```python +@app.route("/publish_request") +def publish_request(): + hello_str = request.args.get("helloStr") + print(hello_str) + return "published" +``` + +# Preparation + +This example will be executed in a separate virtual environment: + +```sh +$ mkdir auto_instrumentation +$ virtualenv auto_instrumentation +$ source auto_instrumentation/bin/activate +``` + +# Installation + +```sh +$ git clone git@github.com:open-telemetry/opentelemetry-python.git +$ cd opentelemetry-python +$ pip3 install -e opentelemetry-api +$ pip3 install -e opentelemetry-sdk +$ pip3 install -e opentelemetry-auto-instrumentation +$ pip3 install -e ext/opentelemetry-ext-flask +$ pip3 install flask +$ pip3 install requests +``` + +# Execution + +## Execution of the manually instrumented publisher + +This is done in 3 separate consoles, one to run each of the scripts that make up this example: + +```sh +$ source auto_instrumentation/bin/activate +$ python3 opentelemetry-python/examples/auto_instrumentation/formatter.py +``` + +```sh +$ source auto_instrumentation/bin/activate +$ python3 opentelemetry-python/examples/auto_instrumentation/publisher_instrumented.py +``` + +```sh +$ source auto_instrumentation/bin/activate +$ python3 opentelemetry-python/examples/auto_instrumentation/hello.py testing +``` + +The execution of `publisher_instrumented.py` should return an output similar to: + +```sh +Hello, testing! +Span(name="publish", context=SpanContext(trace_id=0xd18be4c644d3be57a8623bbdbdbcef76, span_id=0x6162c475bab8d365, trace_state={}), kind=SpanKind.SERVER, parent=SpanContext(trace_id=0xd18be4c644d3be57a8623bbdbdbcef76, span_id=0xdafb264c5b1b6ed0, trace_state={}), start_time=2019-12-19T01:11:12.172866Z, end_time=2019-12-19T01:11:12.173383Z) +127.0.0.1 - - [18/Dec/2019 19:11:12] "GET /publish?helloStr=Hello%2C+testing%21 HTTP/1.1" 200 - +``` + +## Execution of an automatically instrumented publisher + +Now, kill the execution of `publisher_instrumented.py` with `ctrl + c` and run this instead: + +```sh +$ opentelemetry-auto-instrumentation opentelemetry-python/examples/auto_instrumentation/publisher_uninstrumented.py +``` + +In the console where you previously executed `hello.py`, run again this again: + +```sh +$ python3 opentelemetry-python/examples/auto_instrumentation/hello.py testing +``` + +The execution of `publisher_uninstrumented.py` should return an output similar to: + +```sh +Hello, testing! +Span(name="publish", context=SpanContext(trace_id=0xd18be4c644d3be57a8623bbdbdbcef76, span_id=0x6162c475bab8d365, trace_state={}), kind=SpanKind.SERVER, parent=SpanContext(trace_id=0xd18be4c644d3be57a8623bbdbdbcef76, span_id=0xdafb264c5b1b6ed0, trace_state={}), start_time=2019-12-19T01:11:12.172866Z, end_time=2019-12-19T01:11:12.173383Z) +127.0.0.1 - - [18/Dec/2019 19:11:12] "GET /publish?helloStr=Hello%2C+testing%21 HTTP/1.1" 200 - +``` + +As you can see, both outputs are equal since the automatic instrumentation does what the manual instrumentation does too. diff --git a/examples/auto_instrumentation/formatter.py b/examples/auto_instrumentation/formatter.py new file mode 100644 index 00000000000..5e16f89938e --- /dev/null +++ b/examples/auto_instrumentation/formatter.py @@ -0,0 +1,52 @@ +# Copyright 2020, 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. + +from flask import Flask, request + +from opentelemetry import propagators, trace +from opentelemetry.context.propagation.tracecontexthttptextformat import ( + TraceContextHTTPTextFormat, +) +from opentelemetry.propagators import set_global_httptextformat +from opentelemetry.sdk.trace import TracerProvider +from opentelemetry.sdk.trace.export import ( + ConsoleSpanExporter, + SimpleExportSpanProcessor, +) +from utils import get_as_list + +app = Flask(__name__) + +trace.set_preferred_tracer_provider_implementation(lambda T: TracerProvider()) +tracer = trace.tracer_provider().get_tracer(__name__) + +trace.tracer_provider().add_span_processor( + SimpleExportSpanProcessor(ConsoleSpanExporter()) +) +set_global_httptextformat(TraceContextHTTPTextFormat) + + +@app.route("/format_request") +def format_request(): + + with tracer.start_as_current_span( + "format_request", + parent=propagators.extract(get_as_list, request.headers), + ): + hello_to = request.args.get("helloTo") + return "Hello, %s!" % hello_to + + +if __name__ == "__main__": + app.run(port=8081) diff --git a/examples/auto_instrumentation/hello.py b/examples/auto_instrumentation/hello.py new file mode 100644 index 00000000000..85108006f71 --- /dev/null +++ b/examples/auto_instrumentation/hello.py @@ -0,0 +1,67 @@ +# Copyright 2020, 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. + +from sys import argv + +from flask import Flask +from requests import get + +from opentelemetry import propagators, trace +from opentelemetry.context.propagation.tracecontexthttptextformat import ( + TraceContextHTTPTextFormat, +) +from opentelemetry.propagators import set_global_httptextformat +from opentelemetry.sdk.trace import TracerProvider +from opentelemetry.sdk.trace.export import ( + ConsoleSpanExporter, + SimpleExportSpanProcessor, +) + +app = Flask(__name__) + +trace.set_preferred_tracer_provider_implementation(lambda T: TracerProvider()) +tracer = trace.tracer_provider().get_tracer(__name__) + +trace.tracer_provider().add_span_processor( + SimpleExportSpanProcessor(ConsoleSpanExporter()) +) +set_global_httptextformat(TraceContextHTTPTextFormat) + + +def http_get(port, path, param, value): + + headers = {} + propagators.inject(tracer, dict.__setitem__, headers) + + requested = get( + "http://localhost:{}/{}".format(port, path), + params={param: value}, + headers=headers, + ) + + assert requested.status_code == 200 + return requested.text + + +assert len(argv) == 2 + +hello_to = argv[1] + +with tracer.start_as_current_span("hello") as hello_span: + + with tracer.start_as_current_span("hello-format", parent=hello_span): + hello_str = http_get(8081, "format_request", "helloTo", hello_to) + + with tracer.start_as_current_span("hello-publish", parent=hello_span): + http_get(8082, "publish_request", "helloStr", hello_str) diff --git a/examples/auto_instrumentation/publisher_instrumented.py b/examples/auto_instrumentation/publisher_instrumented.py new file mode 100644 index 00000000000..328c5cbb37c --- /dev/null +++ b/examples/auto_instrumentation/publisher_instrumented.py @@ -0,0 +1,52 @@ +# Copyright 2020, 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. + +from flask import Flask, request + +from opentelemetry import propagators, trace +from opentelemetry.context.propagation.tracecontexthttptextformat import ( + TraceContextHTTPTextFormat, +) +from opentelemetry.propagators import set_global_httptextformat +from opentelemetry.sdk.trace import TracerProvider +from opentelemetry.sdk.trace.export import ( + ConsoleSpanExporter, + SimpleExportSpanProcessor, +) +from utils import get_as_list + +app = Flask(__name__) + +trace.set_preferred_tracer_provider_implementation(lambda T: TracerProvider()) +tracer = trace.tracer_provider().get_tracer(__name__) + +trace.tracer_provider().add_span_processor( + SimpleExportSpanProcessor(ConsoleSpanExporter()) +) +set_global_httptextformat(TraceContextHTTPTextFormat) + + +@app.route("/publish_request") +def publish_request(): + + with tracer.start_as_current_span( + "publish_request", propagators.extract(get_as_list, request.headers) + ): + hello_str = request.args.get("helloStr") + print(hello_str) + return "published" + + +if __name__ == "__main__": + app.run(port=8082) diff --git a/examples/auto_instrumentation/publisher_uninstrumented.py b/examples/auto_instrumentation/publisher_uninstrumented.py new file mode 100644 index 00000000000..79d06b592e9 --- /dev/null +++ b/examples/auto_instrumentation/publisher_uninstrumented.py @@ -0,0 +1,41 @@ +# Copyright 2020, 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. + +from flask import Flask, request + +from opentelemetry import trace +from opentelemetry.sdk.trace import TracerProvider +from opentelemetry.sdk.trace.export import ( + ConsoleSpanExporter, + SimpleExportSpanProcessor, +) + +app = Flask(__name__) + +trace.set_preferred_tracer_provider_implementation(lambda T: TracerProvider()) + +trace.tracer_provider().add_span_processor( + SimpleExportSpanProcessor(ConsoleSpanExporter()) +) + + +@app.route("/publish_request") +def publish_request(): + hello_str = request.args.get("helloStr") + print(hello_str) + return "published" + + +if __name__ == "__main__": + app.run(port=8082) diff --git a/examples/auto_instrumentation/utils.py b/examples/auto_instrumentation/utils.py new file mode 100644 index 00000000000..0fa82af694b --- /dev/null +++ b/examples/auto_instrumentation/utils.py @@ -0,0 +1,21 @@ +# Copyright 2020, 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. + + +def get_as_list(dict_object, key): + value = dict_object.get(key) + return value if value is not None else [] + + +__all__ = ["get_as_list"] diff --git a/examples/opentelemetry-example-app/src/opentelemetry_example_app/flask_example.py b/examples/opentelemetry-example-app/src/opentelemetry_example_app/flask_example.py new file mode 100644 index 00000000000..baa5a52cc50 --- /dev/null +++ b/examples/opentelemetry-example-app/src/opentelemetry_example_app/flask_example.py @@ -0,0 +1,78 @@ +# Copyright 2019, 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. +# +""" +This module serves as an example to integrate with flask, using +the requests library to perform downstream requests +""" +import flask +import pkg_resources +import requests + +import opentelemetry.ext.http_requests +from opentelemetry import trace +from opentelemetry.ext.flask import FlaskPatcher +from opentelemetry.sdk.trace import TracerProvider + + +def configure_opentelemetry(): + """Configure a flask application to use OpenTelemetry. + + This activates the specific components: + + * sets tracer to the SDK's Tracer + * enables requests integration on the Tracer + * uses a WSGI middleware to enable configuration + + TODO: + + * processors? + * exporters? + """ + # Start by configuring all objects required to ensure + # a complete end to end workflow. + # The preferred implementation of these objects must be set, + # as the opentelemetry-api defines the interface with a no-op + # implementation. + trace.set_preferred_tracer_provider_implementation( + lambda _: TracerProvider() + ) + + # Next, we need to configure how the values that are used by + # traces and metrics are propagated (such as what specific headers + # carry this value). + # 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. + opentelemetry.ext.http_requests.enable(trace.tracer_provider()) + + +FlaskPatcher().patch() +app = flask.Flask(__name__) + + +@app.route("/") +def hello(): + # emit a trace that measures how long the + # sleep takes + version = pkg_resources.get_distribution( + "opentelemetry-example-app" + ).version + tracer = trace.get_tracer(__name__, version) + with tracer.start_as_current_span("example-request"): + requests.get("http://www.example.com") + return "hello" + + +configure_opentelemetry() diff --git a/ext/opentelemetry-ext-flask/setup.py b/ext/opentelemetry-ext-flask/setup.py index 34b27c60342..13313eca777 100644 --- a/ext/opentelemetry-ext-flask/setup.py +++ b/ext/opentelemetry-ext-flask/setup.py @@ -23,4 +23,11 @@ with open(VERSION_FILENAME) as f: exec(f.read(), PACKAGE_INFO) -setuptools.setup(version=PACKAGE_INFO["__version__"]) +setuptools.setup( + version=PACKAGE_INFO["__version__"], + entry_points={ + "opentelemetry_auto_instrumentation_patcher": [ + "flask = opentelemetry.ext.flask:FlaskPatcher" + ] + }, +) diff --git a/ext/opentelemetry-ext-flask/src/opentelemetry/ext/flask/__init__.py b/ext/opentelemetry-ext-flask/src/opentelemetry/ext/flask/__init__.py index b30b42d3fd2..d759cdc7544 100644 --- a/ext/opentelemetry-ext-flask/src/opentelemetry/ext/flask/__init__.py +++ b/ext/opentelemetry-ext-flask/src/opentelemetry/ext/flask/__init__.py @@ -3,12 +3,12 @@ import logging -from flask import request as flask_request +import flask import opentelemetry.ext.wsgi as otel_wsgi from opentelemetry import context, propagators, trace +from opentelemetry.auto_instrumentation.patcher import BasePatcher from opentelemetry.ext.flask.version import __version__ -from opentelemetry.trace.propagation import get_span_from_context from opentelemetry.util import time_ns logger = logging.getLogger(__name__) @@ -19,82 +19,107 @@ _ENVIRON_TOKEN = "opentelemetry-flask.token" -def instrument_app(flask): - """Makes the passed-in Flask object traced by OpenTelemetry. - - You must not call this function multiple times on the same Flask object. - """ +class _PatchedFlask(flask.Flask): + def __init__(self, *args, **kwargs): + + super().__init__(*args, **kwargs) + + # Single use variable here to avoid recursion issues. + wsgi = self.wsgi_app + + def wrapped_app(environ, start_response): + # We want to measure the time for route matching, etc. + # In theory, we could start the span here and use + # update_name later but that API is "highly discouraged" so + # we better avoid it. + environ[_ENVIRON_STARTTIME_KEY] = time_ns() + + def _start_response(status, response_headers, *args, **kwargs): + span = flask.request.environ.get(_ENVIRON_SPAN_KEY) + if span: + otel_wsgi.add_response_attributes( + span, status, response_headers + ) + else: + logger.warning( + "Flask environ's OpenTelemetry span " + "missing at _start_response(%s)", + status, + ) + + return start_response( + status, response_headers, *args, **kwargs + ) - wsgi = flask.wsgi_app + return wsgi(environ, _start_response) - def wrapped_app(environ, start_response): - # We want to measure the time for route matching, etc. - # In theory, we could start the span here and use update_name later - # but that API is "highly discouraged" so we better avoid it. - environ[_ENVIRON_STARTTIME_KEY] = time_ns() + self.wsgi_app = wrapped_app - def _start_response(status, response_headers, *args, **kwargs): - span = flask_request.environ.get(_ENVIRON_SPAN_KEY) - if span: - otel_wsgi.add_response_attributes( - span, status, response_headers + @self.before_request + def _before_flask_request(): + environ = flask.request.environ + span_name = ( + flask.request.endpoint + or otel_wsgi.get_default_span_name(environ) + ) + token = context.attach( + propagators.extract( + otel_wsgi.get_header_from_environ, environ ) - else: + ) + + tracer = trace.get_tracer(__name__, __version__) + + attributes = otel_wsgi.collect_request_attributes(environ) + if flask.request.url_rule: + # For 404 that result from no route found, etc, we + # don't have a url_rule. + attributes["http.route"] = flask.request.url_rule.rule + span = tracer.start_span( + span_name, + kind=trace.SpanKind.SERVER, + attributes=attributes, + start_time=environ.get(_ENVIRON_STARTTIME_KEY), + ) + activation = tracer.use_span(span, end_on_exit=True) + activation.__enter__() + environ[_ENVIRON_ACTIVATION_KEY] = activation + environ[_ENVIRON_SPAN_KEY] = span + environ[_ENVIRON_TOKEN] = token + + @self.teardown_request + def _teardown_flask_request(exc): + activation = flask.request.environ.get(_ENVIRON_ACTIVATION_KEY) + if not activation: logger.warning( - "Flask environ's OpenTelemetry span missing at _start_response(%s)", - status, + "Flask environ's OpenTelemetry activation missing" + "at _teardown_flask_request(%s)", + exc, + ) + return + + if exc is None: + activation.__exit__(None, None, None) + else: + activation.__exit__( + type(exc), exc, getattr(exc, "__traceback__", None) ) - return start_response(status, response_headers, *args, **kwargs) - - return wsgi(environ, _start_response) - - flask.wsgi_app = wrapped_app - - flask.before_request(_before_flask_request) - flask.teardown_request(_teardown_flask_request) - - -def _before_flask_request(): - environ = flask_request.environ - span_name = flask_request.endpoint or otel_wsgi.get_default_span_name( - environ - ) - token = context.attach( - propagators.extract(otel_wsgi.get_header_from_environ, environ) - ) - - tracer = trace.get_tracer(__name__, __version__) - - attributes = otel_wsgi.collect_request_attributes(environ) - if flask_request.url_rule: - # For 404 that result from no route found, etc, we don't have a url_rule. - attributes["http.route"] = flask_request.url_rule.rule - span = tracer.start_span( - span_name, - kind=trace.SpanKind.SERVER, - attributes=attributes, - start_time=environ.get(_ENVIRON_STARTTIME_KEY), - ) - activation = tracer.use_span(span, end_on_exit=True) - activation.__enter__() - environ[_ENVIRON_ACTIVATION_KEY] = activation - environ[_ENVIRON_SPAN_KEY] = span - environ[_ENVIRON_TOKEN] = token - - -def _teardown_flask_request(exc): - activation = flask_request.environ.get(_ENVIRON_ACTIVATION_KEY) - if not activation: - logger.warning( - "Flask environ's OpenTelemetry activation missing at _teardown_flask_request(%s)", - exc, - ) - return - - if exc is None: - activation.__exit__(None, None, None) - else: - activation.__exit__( - type(exc), exc, getattr(exc, "__traceback__", None) - ) - context.detach(flask_request.environ.get(_ENVIRON_TOKEN)) + context.detach(flask.request.environ.get(_ENVIRON_TOKEN)) + + +class FlaskPatcher(BasePatcher): + """A patcher for flask.Flask + + See `BasePatcher` + """ + + def __init__(self): + super().__init__() + self._original_flask = None + + def _patch(self): + self._original_flask = flask.Flask + flask.Flask = _PatchedFlask + + def _unpatch(self): + flask.Flask = self._original_flask diff --git a/ext/opentelemetry-ext-flask/tests/conftest.py b/ext/opentelemetry-ext-flask/tests/conftest.py new file mode 100644 index 00000000000..e3c59b6dad4 --- /dev/null +++ b/ext/opentelemetry-ext-flask/tests/conftest.py @@ -0,0 +1,24 @@ +# Copyright 2020, 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. +from opentelemetry.ext.flask import FlaskPatcher + +_FLASK_PATCHER = FlaskPatcher() + + +def pytest_sessionstart(session): # pylint: disable=unused-argument + _FLASK_PATCHER.patch() + + +def pytest_sessionfinish(session): # pylint: disable=unused-argument + _FLASK_PATCHER.unpatch() diff --git a/ext/opentelemetry-ext-flask/tests/test_flask_integration.py b/ext/opentelemetry-ext-flask/tests/test_flask_integration.py index 9d2f2560118..b81ad673cbe 100644 --- a/ext/opentelemetry-ext-flask/tests/test_flask_integration.py +++ b/ext/opentelemetry-ext-flask/tests/test_flask_integration.py @@ -18,7 +18,6 @@ from werkzeug.test import Client from werkzeug.wrappers import BaseResponse -import opentelemetry.ext.flask as otel_flask from opentelemetry import trace as trace_api from opentelemetry.ext.testutil.wsgitestutil import WsgiTestBase @@ -54,7 +53,6 @@ def hello_endpoint(helloid): self.app.route("/hello/")(hello_endpoint) - otel_flask.instrument_app(self.app) self.client = Client(self.app, BaseResponse) def test_only_strings_in_environ(self): diff --git a/opentelemetry-auto-instrumentation/CHANGELOG.md b/opentelemetry-auto-instrumentation/CHANGELOG.md new file mode 100644 index 00000000000..825c32f0d03 --- /dev/null +++ b/opentelemetry-auto-instrumentation/CHANGELOG.md @@ -0,0 +1 @@ +# Changelog diff --git a/opentelemetry-auto-instrumentation/MANIFEST.in b/opentelemetry-auto-instrumentation/MANIFEST.in new file mode 100644 index 00000000000..191b7d19592 --- /dev/null +++ b/opentelemetry-auto-instrumentation/MANIFEST.in @@ -0,0 +1,7 @@ +prune tests +graft src +global-exclude *.pyc +global-exclude *.pyo +global-exclude __pycache__/* +include MANIFEST.in +include README.rst diff --git a/opentelemetry-auto-instrumentation/README.rst b/opentelemetry-auto-instrumentation/README.rst new file mode 100644 index 00000000000..d7b34d1ab95 --- /dev/null +++ b/opentelemetry-auto-instrumentation/README.rst @@ -0,0 +1,32 @@ +OpenTelemetry Auto Instrumentation +============================================================================ + +|pypi| + +.. |pypi| image:: https://badge.fury.io/py/opentelemetry-api.svg + :target: https://pypi.org/project/opentelemetry-auto-instrumentation/ + +Installation +------------ + +:: + + pip install opentelemetry-auto-instrumentation + +References +---------- + +* `OpenTelemetry Project `_ + +Usage +----- + +This package provides a command that automatically instruments a program: + +:: + + opentelemetry-auto-instrumentation program.py + +The code in ``program.py`` needs to use one of the packages for which there is +an OpenTelemetry extension. For a list of the available extensions please check +`here `_. diff --git a/opentelemetry-auto-instrumentation/setup.cfg b/opentelemetry-auto-instrumentation/setup.cfg new file mode 100644 index 00000000000..49fcd38b01a --- /dev/null +++ b/opentelemetry-auto-instrumentation/setup.cfg @@ -0,0 +1,50 @@ +# Copyright 2019, 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. +# +[metadata] +name = opentelemetry-auto-instrumentation +description = Auto Instrumentation for OpenTelemetry Python +long_description = file: README.rst +long_description_content_type = text/x-rst +author = OpenTelemetry Authors +author_email = cncf-opentelemetry-contributors@lists.cncf.io +url = https://github.com/open-telemetry/opentelemetry-python/tree/master/opentelemetry-auto-instrumentation" +platforms = any +license = Apache-2.0 +classifiers = + Development Status :: 3 - Alpha + Intended Audience :: Developers + License :: OSI Approved :: Apache Software License + Programming Language :: Python + Programming Language :: Python :: 3 + Programming Language :: Python :: 3.4 + Programming Language :: Python :: 3.5 + Programming Language :: Python :: 3.6 + Programming Language :: Python :: 3.7 + +[options] +python_requires = >=3.4 +package_dir= + =src +packages=find_namespace: +zip_safe = False +include_package_data = True +install_requires = opentelemetry-api==0.5.dev0 + +[options.packages.find] +where = src + +[options.entry_points] +console_scripts = + opentelemetry-auto-instrumentation = opentelemetry.auto_instrumentation.auto_instrumentation:run diff --git a/opentelemetry-auto-instrumentation/setup.py b/opentelemetry-auto-instrumentation/setup.py new file mode 100644 index 00000000000..8d6300384a4 --- /dev/null +++ b/opentelemetry-auto-instrumentation/setup.py @@ -0,0 +1,27 @@ +# Copyright 2020, 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 os + +import setuptools + +BASE_DIR = os.path.dirname(__file__) +VERSION_FILENAME = os.path.join( + BASE_DIR, "src", "opentelemetry", "auto_instrumentation", "version.py" +) +PACKAGE_INFO = {} +with open(VERSION_FILENAME) as f: + exec(f.read(), PACKAGE_INFO) + +setuptools.setup(version=PACKAGE_INFO["__version__"],) diff --git a/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/__init__.py b/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/auto_instrumentation.py b/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/auto_instrumentation.py new file mode 100644 index 00000000000..44651e4964b --- /dev/null +++ b/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/auto_instrumentation.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python3 + +# Copyright 2020, 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. + +from logging import getLogger +from runpy import run_path +from sys import argv + +from pkg_resources import iter_entry_points + +_LOG = getLogger(__file__) + + +def run() -> None: + + for entry_point in iter_entry_points( + "opentelemetry_auto_instrumentation_patcher" + ): + try: + entry_point.load()().patch() # type: ignore + _LOG.debug("Patched %s", entry_point.name) + + except Exception: # pylint: disable=broad-except + _LOG.exception("Patching of %s failed", entry_point.name) + + run_path(argv[1], run_name="__main__") # type: ignore diff --git a/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/patcher.py b/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/patcher.py new file mode 100644 index 00000000000..ee5d3c68a15 --- /dev/null +++ b/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/patcher.py @@ -0,0 +1,65 @@ +# Copyright 2020, 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. +# type: ignore + +""" +OpenTelemetry Auto Instrumentation Patcher +""" + +from abc import ABC, abstractmethod +from logging import getLogger + +_LOG = getLogger(__name__) + + +class BasePatcher(ABC): + """An ABC for patchers""" + + def __init__(self): + self._is_patched = False + + @abstractmethod + def _patch(self) -> None: + """Patch""" + + @abstractmethod + def _unpatch(self) -> None: + """Unpatch""" + + def patch(self) -> None: + """Patch""" + + if not self._is_patched: + result = self._patch() + self._is_patched = True + return result + + _LOG.warning("Attempting to patch while already patched") + + return None + + def unpatch(self) -> None: + """Unpatch""" + + if self._is_patched: + result = self._unpatch() + self._is_patched = False + return result + + _LOG.warning("Attempting to unpatch while already unpatched") + + return None + + +__all__ = ["BasePatcher"] diff --git a/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/version.py b/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/version.py new file mode 100644 index 00000000000..f48cb5bee5c --- /dev/null +++ b/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/version.py @@ -0,0 +1,15 @@ +# Copyright 2020, 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. + +__version__ = "0.5.dev0" diff --git a/opentelemetry-auto-instrumentation/tests/__init__.py b/opentelemetry-auto-instrumentation/tests/__init__.py new file mode 100644 index 00000000000..6ab2e961ec4 --- /dev/null +++ b/opentelemetry-auto-instrumentation/tests/__init__.py @@ -0,0 +1,13 @@ +# Copyright 2020, 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. diff --git a/opentelemetry-auto-instrumentation/tests/test_patcher.py b/opentelemetry-auto-instrumentation/tests/test_patcher.py new file mode 100644 index 00000000000..8e9e45b5d3e --- /dev/null +++ b/opentelemetry-auto-instrumentation/tests/test_patcher.py @@ -0,0 +1,44 @@ +# Copyright 2020, 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. +# type: ignore + +from logging import WARNING +from unittest import TestCase + +from opentelemetry.auto_instrumentation.patcher import BasePatcher + + +class TestPatcher(TestCase): + def test_protect(self): + class Patcher(BasePatcher): + def _patch(self): + return "patched" + + def _unpatch(self): + return "unpatched" + + patcher = Patcher() + + with self.assertLogs(level=WARNING): + self.assertIs(patcher.unpatch(), None) + + self.assertEqual(patcher.patch(), "patched") + + with self.assertLogs(level=WARNING): + self.assertIs(patcher.patch(), None) + + self.assertEqual(patcher.unpatch(), "unpatched") + + with self.assertLogs(level=WARNING): + self.assertIs(patcher.unpatch(), None) diff --git a/tox.ini b/tox.ini index 52c82eba075..4517b74b906 100644 --- a/tox.ini +++ b/tox.ini @@ -12,6 +12,10 @@ envlist = py3{4,5,6,7,8}-test-sdk pypy3-test-sdk + ; opentelemetry-auto-instrumentation + py3{4,5,6,7,8}-test-auto-instrumentation + pypy3-test-auto-instrumentation + ; opentelemetry-example-app py3{4,5,6,7,8}-test-example-app pypy3-test-example-app @@ -43,6 +47,7 @@ envlist = ; opentelemetry-ext-mysql py3{4,5,6,7,8}-test-ext-mysql pypy3-test-ext-mysql + ; opentelemetry-ext-otcollector py3{4,5,6,7,8}-test-ext-otcollector ; ext-otcollector intentionally excluded from pypy3 @@ -101,6 +106,7 @@ setenv = changedir = test-api: opentelemetry-api/tests test-sdk: opentelemetry-sdk/tests + test-auto-instrumentation: opentelemetry-auto-instrumentation/tests test-ext-http-requests: ext/opentelemetry-ext-http-requests/tests test-ext-jaeger: ext/opentelemetry-ext-jaeger/tests test-ext-dbapi: ext/opentelemetry-ext-dbapi/tests @@ -122,7 +128,9 @@ commands_pre = python -m pip install -U pip setuptools wheel test: pip install {toxinidir}/opentelemetry-api test-sdk: pip install {toxinidir}/opentelemetry-sdk + test-auto-instrumentation: pip install {toxinidir}/opentelemetry-auto-instrumentation example-app: pip install {toxinidir}/opentelemetry-sdk + example-app: pip install {toxinidir}/opentelemetry-auto-instrumentation example-app: pip install {toxinidir}/ext/opentelemetry-ext-http-requests example-app: pip install {toxinidir}/ext/opentelemetry-ext-wsgi example-app: pip install {toxinidir}/ext/opentelemetry-ext-flask @@ -139,6 +147,7 @@ commands_pre = wsgi,flask: pip install {toxinidir}/ext/opentelemetry-ext-testutil wsgi,flask: pip install {toxinidir}/ext/opentelemetry-ext-wsgi wsgi,flask: pip install {toxinidir}/opentelemetry-sdk + flask: pip install {toxinidir}/opentelemetry-auto-instrumentation flask: pip install {toxinidir}/ext/opentelemetry-ext-flask[test] dbapi: pip install {toxinidir}/ext/opentelemetry-ext-dbapi mysql: pip install {toxinidir}/ext/opentelemetry-ext-dbapi From e59f4d05923fe7574fee4faed34dd519ab92d58b Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Tue, 17 Mar 2020 13:01:35 -0600 Subject: [PATCH 02/27] Remove unused app --- .../flask_example.py | 4 +- .../flask_example.py | 78 ------------------- 2 files changed, 2 insertions(+), 80 deletions(-) delete mode 100644 examples/opentelemetry-example-app/src/opentelemetry_example_app/flask_example.py diff --git a/docs/examples/opentelemetry-example-app/src/opentelemetry_example_app/flask_example.py b/docs/examples/opentelemetry-example-app/src/opentelemetry_example_app/flask_example.py index d523224d13a..3518b1ba051 100644 --- a/docs/examples/opentelemetry-example-app/src/opentelemetry_example_app/flask_example.py +++ b/docs/examples/opentelemetry-example-app/src/opentelemetry_example_app/flask_example.py @@ -21,21 +21,21 @@ import opentelemetry.ext.http_requests from opentelemetry import trace -from opentelemetry.ext.flask import instrument_app from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace.export import ( ConsoleSpanExporter, SimpleExportSpanProcessor, ) +from opentelemetry.ext.flask import FlaskPatcher trace.set_tracer_provider(TracerProvider()) trace.get_tracer_provider().add_span_processor( SimpleExportSpanProcessor(ConsoleSpanExporter()) ) +FlaskPatcher().patch() app = flask.Flask(__name__) opentelemetry.ext.http_requests.enable(trace.get_tracer_provider()) -instrument_app(app) @app.route("/") diff --git a/examples/opentelemetry-example-app/src/opentelemetry_example_app/flask_example.py b/examples/opentelemetry-example-app/src/opentelemetry_example_app/flask_example.py deleted file mode 100644 index baa5a52cc50..00000000000 --- a/examples/opentelemetry-example-app/src/opentelemetry_example_app/flask_example.py +++ /dev/null @@ -1,78 +0,0 @@ -# Copyright 2019, 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. -# -""" -This module serves as an example to integrate with flask, using -the requests library to perform downstream requests -""" -import flask -import pkg_resources -import requests - -import opentelemetry.ext.http_requests -from opentelemetry import trace -from opentelemetry.ext.flask import FlaskPatcher -from opentelemetry.sdk.trace import TracerProvider - - -def configure_opentelemetry(): - """Configure a flask application to use OpenTelemetry. - - This activates the specific components: - - * sets tracer to the SDK's Tracer - * enables requests integration on the Tracer - * uses a WSGI middleware to enable configuration - - TODO: - - * processors? - * exporters? - """ - # Start by configuring all objects required to ensure - # a complete end to end workflow. - # The preferred implementation of these objects must be set, - # as the opentelemetry-api defines the interface with a no-op - # implementation. - trace.set_preferred_tracer_provider_implementation( - lambda _: TracerProvider() - ) - - # Next, we need to configure how the values that are used by - # traces and metrics are propagated (such as what specific headers - # carry this value). - # 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. - opentelemetry.ext.http_requests.enable(trace.tracer_provider()) - - -FlaskPatcher().patch() -app = flask.Flask(__name__) - - -@app.route("/") -def hello(): - # emit a trace that measures how long the - # sleep takes - version = pkg_resources.get_distribution( - "opentelemetry-example-app" - ).version - tracer = trace.get_tracer(__name__, version) - with tracer.start_as_current_span("example-request"): - requests.get("http://www.example.com") - return "hello" - - -configure_opentelemetry() From 4f79a0e6b3cd216bc8e7278ddc5c99dfbf2fde6e Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Tue, 17 Mar 2020 14:31:54 -0600 Subject: [PATCH 03/27] Move example --- .../example}/README.md | 2 +- .../example}/formatter.py | 6 +++--- .../example}/hello.py | 0 .../example}/publisher_instrumented.py | 0 .../example}/publisher_uninstrumented.py | 0 .../example}/utils.py | 0 6 files changed, 4 insertions(+), 4 deletions(-) rename {examples/auto_instrumentation => opentelemetry-auto-instrumentation/example}/README.md (97%) rename {examples/auto_instrumentation => opentelemetry-auto-instrumentation/example}/formatter.py (89%) rename {examples/auto_instrumentation => opentelemetry-auto-instrumentation/example}/hello.py (100%) rename {examples/auto_instrumentation => opentelemetry-auto-instrumentation/example}/publisher_instrumented.py (100%) rename {examples/auto_instrumentation => opentelemetry-auto-instrumentation/example}/publisher_uninstrumented.py (100%) rename {examples/auto_instrumentation => opentelemetry-auto-instrumentation/example}/utils.py (100%) diff --git a/examples/auto_instrumentation/README.md b/opentelemetry-auto-instrumentation/example/README.md similarity index 97% rename from examples/auto_instrumentation/README.md rename to opentelemetry-auto-instrumentation/example/README.md index 431593e3f4c..ea5afd5d861 100644 --- a/examples/auto_instrumentation/README.md +++ b/opentelemetry-auto-instrumentation/example/README.md @@ -73,7 +73,7 @@ This is done in 3 separate consoles, one to run each of the scripts that make up ```sh $ source auto_instrumentation/bin/activate -$ python3 opentelemetry-python/examples/auto_instrumentation/formatter.py +$ python3 opentelemetry-python/opentelemetry-auto-instrumentation/example/formatter.py ``` ```sh diff --git a/examples/auto_instrumentation/formatter.py b/opentelemetry-auto-instrumentation/example/formatter.py similarity index 89% rename from examples/auto_instrumentation/formatter.py rename to opentelemetry-auto-instrumentation/example/formatter.py index 5e16f89938e..8ca4110fb46 100644 --- a/examples/auto_instrumentation/formatter.py +++ b/opentelemetry-auto-instrumentation/example/formatter.py @@ -28,10 +28,10 @@ app = Flask(__name__) -trace.set_preferred_tracer_provider_implementation(lambda T: TracerProvider()) -tracer = trace.tracer_provider().get_tracer(__name__) +trace.set_tracer_provider(TracerProvider()) +tracer = trace.get_tracer_provider().get_tracer(__name__) -trace.tracer_provider().add_span_processor( +trace.get_tracer_provider().add_span_processor( SimpleExportSpanProcessor(ConsoleSpanExporter()) ) set_global_httptextformat(TraceContextHTTPTextFormat) diff --git a/examples/auto_instrumentation/hello.py b/opentelemetry-auto-instrumentation/example/hello.py similarity index 100% rename from examples/auto_instrumentation/hello.py rename to opentelemetry-auto-instrumentation/example/hello.py diff --git a/examples/auto_instrumentation/publisher_instrumented.py b/opentelemetry-auto-instrumentation/example/publisher_instrumented.py similarity index 100% rename from examples/auto_instrumentation/publisher_instrumented.py rename to opentelemetry-auto-instrumentation/example/publisher_instrumented.py diff --git a/examples/auto_instrumentation/publisher_uninstrumented.py b/opentelemetry-auto-instrumentation/example/publisher_uninstrumented.py similarity index 100% rename from examples/auto_instrumentation/publisher_uninstrumented.py rename to opentelemetry-auto-instrumentation/example/publisher_uninstrumented.py diff --git a/examples/auto_instrumentation/utils.py b/opentelemetry-auto-instrumentation/example/utils.py similarity index 100% rename from examples/auto_instrumentation/utils.py rename to opentelemetry-auto-instrumentation/example/utils.py From 9125b7e128111260f901035f7de66dde07f137e3 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Tue, 17 Mar 2020 16:44:40 -0600 Subject: [PATCH 04/27] More fixes --- opentelemetry-auto-instrumentation/example/formatter.py | 2 +- opentelemetry-auto-instrumentation/example/hello.py | 8 ++++---- .../example/publisher_instrumented.py | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/opentelemetry-auto-instrumentation/example/formatter.py b/opentelemetry-auto-instrumentation/example/formatter.py index 8ca4110fb46..1064ba8f391 100644 --- a/opentelemetry-auto-instrumentation/example/formatter.py +++ b/opentelemetry-auto-instrumentation/example/formatter.py @@ -15,7 +15,7 @@ from flask import Flask, request from opentelemetry import propagators, trace -from opentelemetry.context.propagation.tracecontexthttptextformat import ( +from opentelemetry.trace.propagation.tracecontexthttptextformat import ( TraceContextHTTPTextFormat, ) from opentelemetry.propagators import set_global_httptextformat diff --git a/opentelemetry-auto-instrumentation/example/hello.py b/opentelemetry-auto-instrumentation/example/hello.py index 85108006f71..dad4f68e9f0 100644 --- a/opentelemetry-auto-instrumentation/example/hello.py +++ b/opentelemetry-auto-instrumentation/example/hello.py @@ -18,7 +18,7 @@ from requests import get from opentelemetry import propagators, trace -from opentelemetry.context.propagation.tracecontexthttptextformat import ( +from opentelemetry.trace.propagation.tracecontexthttptextformat import ( TraceContextHTTPTextFormat, ) from opentelemetry.propagators import set_global_httptextformat @@ -30,10 +30,10 @@ app = Flask(__name__) -trace.set_preferred_tracer_provider_implementation(lambda T: TracerProvider()) -tracer = trace.tracer_provider().get_tracer(__name__) +trace.set_tracer_provider(TracerProvider()) +tracer = trace.get_tracer_provider().get_tracer(__name__) -trace.tracer_provider().add_span_processor( +trace.get_tracer_provider().add_span_processor( SimpleExportSpanProcessor(ConsoleSpanExporter()) ) set_global_httptextformat(TraceContextHTTPTextFormat) diff --git a/opentelemetry-auto-instrumentation/example/publisher_instrumented.py b/opentelemetry-auto-instrumentation/example/publisher_instrumented.py index 328c5cbb37c..0e1114a733f 100644 --- a/opentelemetry-auto-instrumentation/example/publisher_instrumented.py +++ b/opentelemetry-auto-instrumentation/example/publisher_instrumented.py @@ -15,7 +15,7 @@ from flask import Flask, request from opentelemetry import propagators, trace -from opentelemetry.context.propagation.tracecontexthttptextformat import ( +from opentelemetry.trace.propagation.tracecontexthttptextformat import ( TraceContextHTTPTextFormat, ) from opentelemetry.propagators import set_global_httptextformat From 3524ccecc3b705cfb2c53016259ad68c2452b4b8 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Tue, 17 Mar 2020 18:07:48 -0600 Subject: [PATCH 05/27] More fixes --- .../trace/propagation/tracecontexthttptextformat.py | 1 + opentelemetry-auto-instrumentation/example/formatter.py | 2 +- opentelemetry-auto-instrumentation/example/hello.py | 5 ++--- .../example/publisher_instrumented.py | 8 ++++---- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/opentelemetry-api/src/opentelemetry/trace/propagation/tracecontexthttptextformat.py b/opentelemetry-api/src/opentelemetry/trace/propagation/tracecontexthttptextformat.py index 28db4e45575..4cf027a4a81 100644 --- a/opentelemetry-api/src/opentelemetry/trace/propagation/tracecontexthttptextformat.py +++ b/opentelemetry-api/src/opentelemetry/trace/propagation/tracecontexthttptextformat.py @@ -129,6 +129,7 @@ def inject( span_context.span_id, span_context.trace_flags, ) + print(self) set_in_carrier( carrier, self._TRACEPARENT_HEADER_NAME, traceparent_string ) diff --git a/opentelemetry-auto-instrumentation/example/formatter.py b/opentelemetry-auto-instrumentation/example/formatter.py index 1064ba8f391..2a7eab97bf7 100644 --- a/opentelemetry-auto-instrumentation/example/formatter.py +++ b/opentelemetry-auto-instrumentation/example/formatter.py @@ -34,7 +34,7 @@ trace.get_tracer_provider().add_span_processor( SimpleExportSpanProcessor(ConsoleSpanExporter()) ) -set_global_httptextformat(TraceContextHTTPTextFormat) +set_global_httptextformat(TraceContextHTTPTextFormat()) @app.route("/format_request") diff --git a/opentelemetry-auto-instrumentation/example/hello.py b/opentelemetry-auto-instrumentation/example/hello.py index dad4f68e9f0..027ff4ea5ae 100644 --- a/opentelemetry-auto-instrumentation/example/hello.py +++ b/opentelemetry-auto-instrumentation/example/hello.py @@ -36,14 +36,13 @@ trace.get_tracer_provider().add_span_processor( SimpleExportSpanProcessor(ConsoleSpanExporter()) ) -set_global_httptextformat(TraceContextHTTPTextFormat) +set_global_httptextformat(TraceContextHTTPTextFormat()) def http_get(port, path, param, value): headers = {} - propagators.inject(tracer, dict.__setitem__, headers) - + propagators.inject(dict.__setitem__, headers) requested = get( "http://localhost:{}/{}".format(port, path), params={param: value}, diff --git a/opentelemetry-auto-instrumentation/example/publisher_instrumented.py b/opentelemetry-auto-instrumentation/example/publisher_instrumented.py index 0e1114a733f..be60f89f18c 100644 --- a/opentelemetry-auto-instrumentation/example/publisher_instrumented.py +++ b/opentelemetry-auto-instrumentation/example/publisher_instrumented.py @@ -28,13 +28,13 @@ app = Flask(__name__) -trace.set_preferred_tracer_provider_implementation(lambda T: TracerProvider()) -tracer = trace.tracer_provider().get_tracer(__name__) +trace.set_tracer_provider(TracerProvider()) +tracer = trace.get_tracer_provider().get_tracer(__name__) -trace.tracer_provider().add_span_processor( +trace.get_tracer_provider().add_span_processor( SimpleExportSpanProcessor(ConsoleSpanExporter()) ) -set_global_httptextformat(TraceContextHTTPTextFormat) +set_global_httptextformat(TraceContextHTTPTextFormat()) @app.route("/publish_request") From ef5b329f680f432fcc3c062470f98dbe08a0210e Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Wed, 18 Mar 2020 10:37:49 -0600 Subject: [PATCH 06/27] Use current-span --- opentelemetry-auto-instrumentation/example/formatter.py | 4 +++- .../example/publisher_instrumented.py | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/opentelemetry-auto-instrumentation/example/formatter.py b/opentelemetry-auto-instrumentation/example/formatter.py index 2a7eab97bf7..f4b9e7ddb59 100644 --- a/opentelemetry-auto-instrumentation/example/formatter.py +++ b/opentelemetry-auto-instrumentation/example/formatter.py @@ -42,7 +42,9 @@ def format_request(): with tracer.start_as_current_span( "format_request", - parent=propagators.extract(get_as_list, request.headers), + parent=propagators.extract( + get_as_list, request.headers + )["current-span"], ): hello_to = request.args.get("helloTo") return "Hello, %s!" % hello_to diff --git a/opentelemetry-auto-instrumentation/example/publisher_instrumented.py b/opentelemetry-auto-instrumentation/example/publisher_instrumented.py index be60f89f18c..0137e61411f 100644 --- a/opentelemetry-auto-instrumentation/example/publisher_instrumented.py +++ b/opentelemetry-auto-instrumentation/example/publisher_instrumented.py @@ -41,7 +41,10 @@ def publish_request(): with tracer.start_as_current_span( - "publish_request", propagators.extract(get_as_list, request.headers) + "publish_request", + parent=propagators.extract( + get_as_list, request.headers + )["current-span"] ): hello_str = request.args.get("helloStr") print(hello_str) From 2eaf7e49c378e316d9ddd765cae71f8559ac8c5b Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Wed, 18 Mar 2020 17:19:11 -0600 Subject: [PATCH 07/27] More lint fixes --- .../src/opentelemetry/ext/flask/__init__.py | 4 +--- .../example/formatter.py | 12 ++++++------ opentelemetry-auto-instrumentation/example/hello.py | 6 +++--- .../example/publisher_instrumented.py | 12 ++++++------ 4 files changed, 16 insertions(+), 18 deletions(-) diff --git a/ext/opentelemetry-ext-flask/src/opentelemetry/ext/flask/__init__.py b/ext/opentelemetry-ext-flask/src/opentelemetry/ext/flask/__init__.py index d759cdc7544..7364b0fe211 100644 --- a/ext/opentelemetry-ext-flask/src/opentelemetry/ext/flask/__init__.py +++ b/ext/opentelemetry-ext-flask/src/opentelemetry/ext/flask/__init__.py @@ -63,9 +63,7 @@ def _before_flask_request(): or otel_wsgi.get_default_span_name(environ) ) token = context.attach( - propagators.extract( - otel_wsgi.get_header_from_environ, environ - ) + propagators.extract(otel_wsgi.get_header_from_environ, environ) ) tracer = trace.get_tracer(__name__, __version__) diff --git a/opentelemetry-auto-instrumentation/example/formatter.py b/opentelemetry-auto-instrumentation/example/formatter.py index f4b9e7ddb59..fd294f5d216 100644 --- a/opentelemetry-auto-instrumentation/example/formatter.py +++ b/opentelemetry-auto-instrumentation/example/formatter.py @@ -15,15 +15,15 @@ from flask import Flask, request from opentelemetry import propagators, trace -from opentelemetry.trace.propagation.tracecontexthttptextformat import ( - TraceContextHTTPTextFormat, -) from opentelemetry.propagators import set_global_httptextformat from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace.export import ( ConsoleSpanExporter, SimpleExportSpanProcessor, ) +from opentelemetry.trace.propagation.tracecontexthttptextformat import ( + TraceContextHTTPTextFormat, +) from utils import get_as_list app = Flask(__name__) @@ -42,9 +42,9 @@ def format_request(): with tracer.start_as_current_span( "format_request", - parent=propagators.extract( - get_as_list, request.headers - )["current-span"], + parent=propagators.extract(get_as_list, request.headers)[ + "current-span" + ], ): hello_to = request.args.get("helloTo") return "Hello, %s!" % hello_to diff --git a/opentelemetry-auto-instrumentation/example/hello.py b/opentelemetry-auto-instrumentation/example/hello.py index 027ff4ea5ae..7d13b4cb733 100644 --- a/opentelemetry-auto-instrumentation/example/hello.py +++ b/opentelemetry-auto-instrumentation/example/hello.py @@ -18,15 +18,15 @@ from requests import get from opentelemetry import propagators, trace -from opentelemetry.trace.propagation.tracecontexthttptextformat import ( - TraceContextHTTPTextFormat, -) from opentelemetry.propagators import set_global_httptextformat from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace.export import ( ConsoleSpanExporter, SimpleExportSpanProcessor, ) +from opentelemetry.trace.propagation.tracecontexthttptextformat import ( + TraceContextHTTPTextFormat, +) app = Flask(__name__) diff --git a/opentelemetry-auto-instrumentation/example/publisher_instrumented.py b/opentelemetry-auto-instrumentation/example/publisher_instrumented.py index 0137e61411f..e13008020b2 100644 --- a/opentelemetry-auto-instrumentation/example/publisher_instrumented.py +++ b/opentelemetry-auto-instrumentation/example/publisher_instrumented.py @@ -15,15 +15,15 @@ from flask import Flask, request from opentelemetry import propagators, trace -from opentelemetry.trace.propagation.tracecontexthttptextformat import ( - TraceContextHTTPTextFormat, -) from opentelemetry.propagators import set_global_httptextformat from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace.export import ( ConsoleSpanExporter, SimpleExportSpanProcessor, ) +from opentelemetry.trace.propagation.tracecontexthttptextformat import ( + TraceContextHTTPTextFormat, +) from utils import get_as_list app = Flask(__name__) @@ -42,9 +42,9 @@ def publish_request(): with tracer.start_as_current_span( "publish_request", - parent=propagators.extract( - get_as_list, request.headers - )["current-span"] + parent=propagators.extract(get_as_list, request.headers)[ + "current-span" + ], ): hello_str = request.args.get("helloStr") print(hello_str) From 9c479b068ef5d32d7ae9bb61ce819bb0d197df5e Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Wed, 18 Mar 2020 17:54:40 -0600 Subject: [PATCH 08/27] More lint fixes --- .../src/opentelemetry_example_app/flask_example.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/examples/opentelemetry-example-app/src/opentelemetry_example_app/flask_example.py b/docs/examples/opentelemetry-example-app/src/opentelemetry_example_app/flask_example.py index 3518b1ba051..bf4b4646ef5 100644 --- a/docs/examples/opentelemetry-example-app/src/opentelemetry_example_app/flask_example.py +++ b/docs/examples/opentelemetry-example-app/src/opentelemetry_example_app/flask_example.py @@ -21,12 +21,12 @@ import opentelemetry.ext.http_requests from opentelemetry import trace +from opentelemetry.ext.flask import FlaskPatcher from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace.export import ( ConsoleSpanExporter, SimpleExportSpanProcessor, ) -from opentelemetry.ext.flask import FlaskPatcher trace.set_tracer_provider(TracerProvider()) trace.get_tracer_provider().add_span_processor( From fa069c3701d9b3324450c820f40fa68fec456e25 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Wed, 18 Mar 2020 18:24:57 -0600 Subject: [PATCH 09/27] Fix example --- .../example/README.md | 21 +++++++++++-------- .../example/publisher_uninstrumented.py | 4 ++-- opentelemetry-auto-instrumentation/setup.cfg | 2 +- .../auto_instrumentation/version.py | 2 +- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/opentelemetry-auto-instrumentation/example/README.md b/opentelemetry-auto-instrumentation/example/README.md index ea5afd5d861..f8518794f44 100644 --- a/opentelemetry-auto-instrumentation/example/README.md +++ b/opentelemetry-auto-instrumentation/example/README.md @@ -23,7 +23,10 @@ In order to understand this better, here is the relevant part of both scripts: def publish_request(): with tracer.start_as_current_span( - "publish_request", propagators.extract(get_as_list, request.headers) + "publish_request", + parent=propagators.extract(get_as_list, request.headers)[ + "current-span" + ], ): hello_str = request.args.get("helloStr") print(hello_str) @@ -78,20 +81,20 @@ $ python3 opentelemetry-python/opentelemetry-auto-instrumentation/example/format ```sh $ source auto_instrumentation/bin/activate -$ python3 opentelemetry-python/examples/auto_instrumentation/publisher_instrumented.py +$ python3 opentelemetry-python/opentelemetry-auto-instrumentation/example/publisher_instrumented.py ``` ```sh $ source auto_instrumentation/bin/activate -$ python3 opentelemetry-python/examples/auto_instrumentation/hello.py testing +$ python3 opentelemetry-python/opentelemetry-auto-instrumentation/example/hello.py testing ``` The execution of `publisher_instrumented.py` should return an output similar to: ```sh Hello, testing! -Span(name="publish", context=SpanContext(trace_id=0xd18be4c644d3be57a8623bbdbdbcef76, span_id=0x6162c475bab8d365, trace_state={}), kind=SpanKind.SERVER, parent=SpanContext(trace_id=0xd18be4c644d3be57a8623bbdbdbcef76, span_id=0xdafb264c5b1b6ed0, trace_state={}), start_time=2019-12-19T01:11:12.172866Z, end_time=2019-12-19T01:11:12.173383Z) -127.0.0.1 - - [18/Dec/2019 19:11:12] "GET /publish?helloStr=Hello%2C+testing%21 HTTP/1.1" 200 - +Span(name="publish_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 /publish_request?helloStr=Hello%2C+testing%21 HTTP/1.1" 200 - ``` ## Execution of an automatically instrumented publisher @@ -99,21 +102,21 @@ Span(name="publish", context=SpanContext(trace_id=0xd18be4c644d3be57a8623bbdbdbc Now, kill the execution of `publisher_instrumented.py` with `ctrl + c` and run this instead: ```sh -$ opentelemetry-auto-instrumentation opentelemetry-python/examples/auto_instrumentation/publisher_uninstrumented.py +$ opentelemetry-auto-instrumentation opentelemetry-python/opentelemetry-auto-instrumentation/example/publisher_uninstrumented.py ``` In the console where you previously executed `hello.py`, run again this again: ```sh -$ python3 opentelemetry-python/examples/auto_instrumentation/hello.py testing +$ python3 opentelemetry-python/opentelemetry-auto-instrumentation/example/hello.py testing ``` The execution of `publisher_uninstrumented.py` should return an output similar to: ```sh Hello, testing! -Span(name="publish", context=SpanContext(trace_id=0xd18be4c644d3be57a8623bbdbdbcef76, span_id=0x6162c475bab8d365, trace_state={}), kind=SpanKind.SERVER, parent=SpanContext(trace_id=0xd18be4c644d3be57a8623bbdbdbcef76, span_id=0xdafb264c5b1b6ed0, trace_state={}), start_time=2019-12-19T01:11:12.172866Z, end_time=2019-12-19T01:11:12.173383Z) -127.0.0.1 - - [18/Dec/2019 19:11:12] "GET /publish?helloStr=Hello%2C+testing%21 HTTP/1.1" 200 - +Span(name="publish_request", context=SpanContext(trace_id=0xf26b28b5243e48f5f96bfc753f95f3f0, span_id=0xbeb179a095d087ed, trace_state={}), kind=SpanKind.SERVER, parent=, 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 /publish_request?helloStr=Hello%2C+testing%21 HTTP/1.1" 200 - ``` As you can see, both outputs are equal since the automatic instrumentation does what the manual instrumentation does too. diff --git a/opentelemetry-auto-instrumentation/example/publisher_uninstrumented.py b/opentelemetry-auto-instrumentation/example/publisher_uninstrumented.py index 79d06b592e9..da8ca38a02c 100644 --- a/opentelemetry-auto-instrumentation/example/publisher_uninstrumented.py +++ b/opentelemetry-auto-instrumentation/example/publisher_uninstrumented.py @@ -23,9 +23,9 @@ app = Flask(__name__) -trace.set_preferred_tracer_provider_implementation(lambda T: TracerProvider()) +trace.set_tracer_provider(TracerProvider()) -trace.tracer_provider().add_span_processor( +trace.get_tracer_provider().add_span_processor( SimpleExportSpanProcessor(ConsoleSpanExporter()) ) diff --git a/opentelemetry-auto-instrumentation/setup.cfg b/opentelemetry-auto-instrumentation/setup.cfg index 49fcd38b01a..182b15866fc 100644 --- a/opentelemetry-auto-instrumentation/setup.cfg +++ b/opentelemetry-auto-instrumentation/setup.cfg @@ -40,7 +40,7 @@ package_dir= packages=find_namespace: zip_safe = False include_package_data = True -install_requires = opentelemetry-api==0.5.dev0 +install_requires = opentelemetry-api==0.6.dev0 [options.packages.find] where = src diff --git a/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/version.py b/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/version.py index f48cb5bee5c..9fe0d7a99e3 100644 --- a/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/version.py +++ b/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.5.dev0" +__version__ = "0.1.dev0" From 2b97ab03c95285f0acb96cdd3aa3434774907001 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Fri, 20 Mar 2020 18:03:18 -0600 Subject: [PATCH 10/27] Rename patcher to instrumentor --- 0001-Rename-to-auto_instrumentor.patch | 280 ++++++++++++++++++ .../flask_example.py | 4 +- ext/opentelemetry-ext-flask/setup.py | 4 +- .../src/opentelemetry/ext/flask/__init__.py | 16 +- ext/opentelemetry-ext-flask/tests/conftest.py | 8 +- .../auto_instrumentation.py | 8 +- .../{patcher.py => instrumentor.py} | 42 +-- .../{test_patcher.py => test_instrumentor.py} | 26 +- 8 files changed, 334 insertions(+), 54 deletions(-) create mode 100644 0001-Rename-to-auto_instrumentor.patch rename opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/{patcher.py => instrumentor.py} (52%) rename opentelemetry-auto-instrumentation/tests/{test_patcher.py => test_instrumentor.py} (55%) diff --git a/0001-Rename-to-auto_instrumentor.patch b/0001-Rename-to-auto_instrumentor.patch new file mode 100644 index 00000000000..bb75dd11d44 --- /dev/null +++ b/0001-Rename-to-auto_instrumentor.patch @@ -0,0 +1,280 @@ +From 8586bdf43b03211b5e12b85430355bfb97b212bc Mon Sep 17 00:00:00 2001 +From: Diego Hurtado +Date: Fri, 20 Mar 2020 17:00:39 -0600 +Subject: [PATCH] Rename to auto_instrumentor + +--- + .../flask_example.py | 4 +- + ext/opentelemetry-ext-flask/setup.py | 4 +- + .../src/opentelemetry/ext/flask/__init__.py | 16 +++---- + ext/opentelemetry-ext-flask/tests/conftest.py | 8 ++-- + .../auto_instrumentation.py | 8 ++-- + .../{patcher.py => instrumentor.py} | 42 +++++++++---------- + .../{test_patcher.py => test_instrumentor.py} | 26 ++++++------ + 7 files changed, 54 insertions(+), 54 deletions(-) + rename opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/{patcher.py => instrumentor.py} (52%) + rename opentelemetry-auto-instrumentation/tests/{test_patcher.py => test_instrumentor.py} (55%) + +diff --git a/docs/examples/opentelemetry-example-app/src/opentelemetry_example_app/flask_example.py b/docs/examples/opentelemetry-example-app/src/opentelemetry_example_app/flask_example.py +index bf4b4646..544fe8cd 100644 +--- a/docs/examples/opentelemetry-example-app/src/opentelemetry_example_app/flask_example.py ++++ b/docs/examples/opentelemetry-example-app/src/opentelemetry_example_app/flask_example.py +@@ -21,7 +21,7 @@ import requests + + import opentelemetry.ext.http_requests + from opentelemetry import trace +-from opentelemetry.ext.flask import FlaskPatcher ++from opentelemetry.ext.flask import FlaskInstrumentor + from opentelemetry.sdk.trace import TracerProvider + from opentelemetry.sdk.trace.export import ( + ConsoleSpanExporter, +@@ -33,7 +33,7 @@ trace.get_tracer_provider().add_span_processor( + SimpleExportSpanProcessor(ConsoleSpanExporter()) + ) + +-FlaskPatcher().patch() ++FlaskInstrumentor().instrument() + app = flask.Flask(__name__) + opentelemetry.ext.http_requests.enable(trace.get_tracer_provider()) + +diff --git a/ext/opentelemetry-ext-flask/setup.py b/ext/opentelemetry-ext-flask/setup.py +index 13313eca..75d2f277 100644 +--- a/ext/opentelemetry-ext-flask/setup.py ++++ b/ext/opentelemetry-ext-flask/setup.py +@@ -26,8 +26,8 @@ with open(VERSION_FILENAME) as f: + setuptools.setup( + version=PACKAGE_INFO["__version__"], + entry_points={ +- "opentelemetry_auto_instrumentation_patcher": [ +- "flask = opentelemetry.ext.flask:FlaskPatcher" ++ "opentelemetry_auto_instrumentation_instrumentor": [ ++ "flask = opentelemetry.ext.flask:FlaskInstrumentor" + ] + }, + ) +diff --git a/ext/opentelemetry-ext-flask/src/opentelemetry/ext/flask/__init__.py b/ext/opentelemetry-ext-flask/src/opentelemetry/ext/flask/__init__.py +index 7364b0fe..09e22b8d 100644 +--- a/ext/opentelemetry-ext-flask/src/opentelemetry/ext/flask/__init__.py ++++ b/ext/opentelemetry-ext-flask/src/opentelemetry/ext/flask/__init__.py +@@ -7,7 +7,7 @@ import flask + + import opentelemetry.ext.wsgi as otel_wsgi + from opentelemetry import context, propagators, trace +-from opentelemetry.auto_instrumentation.patcher import BasePatcher ++from opentelemetry.auto_instrumentation.instrumentor import BaseInstrumentor + from opentelemetry.ext.flask.version import __version__ + from opentelemetry.util import time_ns + +@@ -19,7 +19,7 @@ _ENVIRON_ACTIVATION_KEY = "opentelemetry-flask.activation_key" + _ENVIRON_TOKEN = "opentelemetry-flask.token" + + +-class _PatchedFlask(flask.Flask): ++class _InstrumentedFlask(flask.Flask): + def __init__(self, *args, **kwargs): + + super().__init__(*args, **kwargs) +@@ -105,19 +105,19 @@ class _PatchedFlask(flask.Flask): + context.detach(flask.request.environ.get(_ENVIRON_TOKEN)) + + +-class FlaskPatcher(BasePatcher): +- """A patcher for flask.Flask ++class FlaskInstrumentor(BaseInstrumentor): ++ """A instrumentor for flask.Flask + +- See `BasePatcher` ++ See `BaseInstrumentor` + """ + + def __init__(self): + super().__init__() + self._original_flask = None + +- def _patch(self): ++ def _instrument(self): + self._original_flask = flask.Flask +- flask.Flask = _PatchedFlask ++ flask.Flask = _InstrumentedFlask + +- def _unpatch(self): ++ def _uninstrument(self): + flask.Flask = self._original_flask +diff --git a/ext/opentelemetry-ext-flask/tests/conftest.py b/ext/opentelemetry-ext-flask/tests/conftest.py +index e3c59b6d..22a587ab 100644 +--- a/ext/opentelemetry-ext-flask/tests/conftest.py ++++ b/ext/opentelemetry-ext-flask/tests/conftest.py +@@ -11,14 +11,14 @@ + # 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. +-from opentelemetry.ext.flask import FlaskPatcher ++from opentelemetry.ext.flask import FlaskInstrumentor + +-_FLASK_PATCHER = FlaskPatcher() ++_FLASK_INSTRUMENTOR = FlaskInstrumentor() + + + def pytest_sessionstart(session): # pylint: disable=unused-argument +- _FLASK_PATCHER.patch() ++ _FLASK_INSTRUMENTOR.instrument() + + + def pytest_sessionfinish(session): # pylint: disable=unused-argument +- _FLASK_PATCHER.unpatch() ++ _FLASK_INSTRUMENTOR.uninstrument() +diff --git a/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/auto_instrumentation.py b/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/auto_instrumentation.py +index 44651e49..124f8694 100644 +--- a/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/auto_instrumentation.py ++++ b/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/auto_instrumentation.py +@@ -26,13 +26,13 @@ _LOG = getLogger(__file__) + def run() -> None: + + for entry_point in iter_entry_points( +- "opentelemetry_auto_instrumentation_patcher" ++ "opentelemetry_auto_instrumentation_instrumentor" + ): + try: +- entry_point.load()().patch() # type: ignore +- _LOG.debug("Patched %s", entry_point.name) ++ entry_point.load()().instrument() # type: ignore ++ _LOG.debug("Instrumented %s", entry_point.name) + + except Exception: # pylint: disable=broad-except +- _LOG.exception("Patching of %s failed", entry_point.name) ++ _LOG.exception("Instrumenting of %s failed", entry_point.name) + + run_path(argv[1], run_name="__main__") # type: ignore +diff --git a/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/patcher.py b/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/instrumentor.py +similarity index 52% +rename from opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/patcher.py +rename to opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/instrumentor.py +index ee5d3c68..a5ee0b90 100644 +--- a/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/patcher.py ++++ b/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/instrumentor.py +@@ -14,7 +14,7 @@ + # type: ignore + + """ +-OpenTelemetry Auto Instrumentation Patcher ++OpenTelemetry Base Instrumentor + """ + + from abc import ABC, abstractmethod +@@ -23,43 +23,43 @@ from logging import getLogger + _LOG = getLogger(__name__) + + +-class BasePatcher(ABC): +- """An ABC for patchers""" ++class BaseInstrumentor(ABC): ++ """An ABC for instrumentors""" + + def __init__(self): +- self._is_patched = False ++ self._is_instrumented = False + + @abstractmethod +- def _patch(self) -> None: +- """Patch""" ++ def _instrument(self) -> None: ++ """Instrument""" + + @abstractmethod +- def _unpatch(self) -> None: +- """Unpatch""" ++ def _uninstrument(self) -> None: ++ """Uninstrument""" + +- def patch(self) -> None: +- """Patch""" ++ def instrument(self) -> None: ++ """Instrument""" + +- if not self._is_patched: +- result = self._patch() +- self._is_patched = True ++ if not self._is_instrumented: ++ result = self._instrument() ++ self._is_instrumented = True + return result + +- _LOG.warning("Attempting to patch while already patched") ++ _LOG.warning("Attempting to instrument while already instrumented") + + return None + +- def unpatch(self) -> None: +- """Unpatch""" ++ def uninstrument(self) -> None: ++ """Uninstrument""" + +- if self._is_patched: +- result = self._unpatch() +- self._is_patched = False ++ if self._is_instrumented: ++ result = self._uninstrument() ++ self._is_instrumented = False + return result + +- _LOG.warning("Attempting to unpatch while already unpatched") ++ _LOG.warning("Attempting to uninstrument while already uninstrumented") + + return None + + +-__all__ = ["BasePatcher"] ++__all__ = ["BaseInstrumentor"] +diff --git a/opentelemetry-auto-instrumentation/tests/test_patcher.py b/opentelemetry-auto-instrumentation/tests/test_instrumentor.py +similarity index 55% +rename from opentelemetry-auto-instrumentation/tests/test_patcher.py +rename to opentelemetry-auto-instrumentation/tests/test_instrumentor.py +index 8e9e45b5..cf887724 100644 +--- a/opentelemetry-auto-instrumentation/tests/test_patcher.py ++++ b/opentelemetry-auto-instrumentation/tests/test_instrumentor.py +@@ -16,29 +16,29 @@ + from logging import WARNING + from unittest import TestCase + +-from opentelemetry.auto_instrumentation.patcher import BasePatcher ++from opentelemetry.auto_instrumentation.instrumentor import BaseInstrumentor + + +-class TestPatcher(TestCase): ++class TestInstrumentor(TestCase): + def test_protect(self): +- class Patcher(BasePatcher): +- def _patch(self): +- return "patched" ++ class Instrumentor(BaseInstrumentor): ++ def _instrument(self): ++ return "instrumented" + +- def _unpatch(self): +- return "unpatched" ++ def _uninstrument(self): ++ return "uninstrumented" + +- patcher = Patcher() ++ instrumentor = Instrumentor() + + with self.assertLogs(level=WARNING): +- self.assertIs(patcher.unpatch(), None) ++ self.assertIs(instrumentor.uninstrument(), None) + +- self.assertEqual(patcher.patch(), "patched") ++ self.assertEqual(instrumentor.instrument(), "instrumented") + + with self.assertLogs(level=WARNING): +- self.assertIs(patcher.patch(), None) ++ self.assertIs(instrumentor.instrument(), None) + +- self.assertEqual(patcher.unpatch(), "unpatched") ++ self.assertEqual(instrumentor.uninstrument(), "uninstrumented") + + with self.assertLogs(level=WARNING): +- self.assertIs(patcher.unpatch(), None) ++ self.assertIs(instrumentor.uninstrument(), None) +-- +2.17.1 + diff --git a/docs/examples/opentelemetry-example-app/src/opentelemetry_example_app/flask_example.py b/docs/examples/opentelemetry-example-app/src/opentelemetry_example_app/flask_example.py index bf4b4646ef5..544fe8cdbf9 100644 --- a/docs/examples/opentelemetry-example-app/src/opentelemetry_example_app/flask_example.py +++ b/docs/examples/opentelemetry-example-app/src/opentelemetry_example_app/flask_example.py @@ -21,7 +21,7 @@ import opentelemetry.ext.http_requests from opentelemetry import trace -from opentelemetry.ext.flask import FlaskPatcher +from opentelemetry.ext.flask import FlaskInstrumentor from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace.export import ( ConsoleSpanExporter, @@ -33,7 +33,7 @@ SimpleExportSpanProcessor(ConsoleSpanExporter()) ) -FlaskPatcher().patch() +FlaskInstrumentor().instrument() app = flask.Flask(__name__) opentelemetry.ext.http_requests.enable(trace.get_tracer_provider()) diff --git a/ext/opentelemetry-ext-flask/setup.py b/ext/opentelemetry-ext-flask/setup.py index 13313eca777..75d2f2778c8 100644 --- a/ext/opentelemetry-ext-flask/setup.py +++ b/ext/opentelemetry-ext-flask/setup.py @@ -26,8 +26,8 @@ setuptools.setup( version=PACKAGE_INFO["__version__"], entry_points={ - "opentelemetry_auto_instrumentation_patcher": [ - "flask = opentelemetry.ext.flask:FlaskPatcher" + "opentelemetry_auto_instrumentation_instrumentor": [ + "flask = opentelemetry.ext.flask:FlaskInstrumentor" ] }, ) diff --git a/ext/opentelemetry-ext-flask/src/opentelemetry/ext/flask/__init__.py b/ext/opentelemetry-ext-flask/src/opentelemetry/ext/flask/__init__.py index 7364b0fe211..09e22b8d01a 100644 --- a/ext/opentelemetry-ext-flask/src/opentelemetry/ext/flask/__init__.py +++ b/ext/opentelemetry-ext-flask/src/opentelemetry/ext/flask/__init__.py @@ -7,7 +7,7 @@ import opentelemetry.ext.wsgi as otel_wsgi from opentelemetry import context, propagators, trace -from opentelemetry.auto_instrumentation.patcher import BasePatcher +from opentelemetry.auto_instrumentation.instrumentor import BaseInstrumentor from opentelemetry.ext.flask.version import __version__ from opentelemetry.util import time_ns @@ -19,7 +19,7 @@ _ENVIRON_TOKEN = "opentelemetry-flask.token" -class _PatchedFlask(flask.Flask): +class _InstrumentedFlask(flask.Flask): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -105,19 +105,19 @@ def _teardown_flask_request(exc): context.detach(flask.request.environ.get(_ENVIRON_TOKEN)) -class FlaskPatcher(BasePatcher): - """A patcher for flask.Flask +class FlaskInstrumentor(BaseInstrumentor): + """A instrumentor for flask.Flask - See `BasePatcher` + See `BaseInstrumentor` """ def __init__(self): super().__init__() self._original_flask = None - def _patch(self): + def _instrument(self): self._original_flask = flask.Flask - flask.Flask = _PatchedFlask + flask.Flask = _InstrumentedFlask - def _unpatch(self): + def _uninstrument(self): flask.Flask = self._original_flask diff --git a/ext/opentelemetry-ext-flask/tests/conftest.py b/ext/opentelemetry-ext-flask/tests/conftest.py index e3c59b6dad4..22a587ab2e6 100644 --- a/ext/opentelemetry-ext-flask/tests/conftest.py +++ b/ext/opentelemetry-ext-flask/tests/conftest.py @@ -11,14 +11,14 @@ # 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. -from opentelemetry.ext.flask import FlaskPatcher +from opentelemetry.ext.flask import FlaskInstrumentor -_FLASK_PATCHER = FlaskPatcher() +_FLASK_INSTRUMENTOR = FlaskInstrumentor() def pytest_sessionstart(session): # pylint: disable=unused-argument - _FLASK_PATCHER.patch() + _FLASK_INSTRUMENTOR.instrument() def pytest_sessionfinish(session): # pylint: disable=unused-argument - _FLASK_PATCHER.unpatch() + _FLASK_INSTRUMENTOR.uninstrument() diff --git a/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/auto_instrumentation.py b/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/auto_instrumentation.py index 44651e4964b..124f8694533 100644 --- a/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/auto_instrumentation.py +++ b/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/auto_instrumentation.py @@ -26,13 +26,13 @@ def run() -> None: for entry_point in iter_entry_points( - "opentelemetry_auto_instrumentation_patcher" + "opentelemetry_auto_instrumentation_instrumentor" ): try: - entry_point.load()().patch() # type: ignore - _LOG.debug("Patched %s", entry_point.name) + entry_point.load()().instrument() # type: ignore + _LOG.debug("Instrumented %s", entry_point.name) except Exception: # pylint: disable=broad-except - _LOG.exception("Patching of %s failed", entry_point.name) + _LOG.exception("Instrumenting of %s failed", entry_point.name) run_path(argv[1], run_name="__main__") # type: ignore diff --git a/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/patcher.py b/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/instrumentor.py similarity index 52% rename from opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/patcher.py rename to opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/instrumentor.py index ee5d3c68a15..a5ee0b90e59 100644 --- a/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/patcher.py +++ b/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/instrumentor.py @@ -14,7 +14,7 @@ # type: ignore """ -OpenTelemetry Auto Instrumentation Patcher +OpenTelemetry Base Instrumentor """ from abc import ABC, abstractmethod @@ -23,43 +23,43 @@ _LOG = getLogger(__name__) -class BasePatcher(ABC): - """An ABC for patchers""" +class BaseInstrumentor(ABC): + """An ABC for instrumentors""" def __init__(self): - self._is_patched = False + self._is_instrumented = False @abstractmethod - def _patch(self) -> None: - """Patch""" + def _instrument(self) -> None: + """Instrument""" @abstractmethod - def _unpatch(self) -> None: - """Unpatch""" + def _uninstrument(self) -> None: + """Uninstrument""" - def patch(self) -> None: - """Patch""" + def instrument(self) -> None: + """Instrument""" - if not self._is_patched: - result = self._patch() - self._is_patched = True + if not self._is_instrumented: + result = self._instrument() + self._is_instrumented = True return result - _LOG.warning("Attempting to patch while already patched") + _LOG.warning("Attempting to instrument while already instrumented") return None - def unpatch(self) -> None: - """Unpatch""" + def uninstrument(self) -> None: + """Uninstrument""" - if self._is_patched: - result = self._unpatch() - self._is_patched = False + if self._is_instrumented: + result = self._uninstrument() + self._is_instrumented = False return result - _LOG.warning("Attempting to unpatch while already unpatched") + _LOG.warning("Attempting to uninstrument while already uninstrumented") return None -__all__ = ["BasePatcher"] +__all__ = ["BaseInstrumentor"] diff --git a/opentelemetry-auto-instrumentation/tests/test_patcher.py b/opentelemetry-auto-instrumentation/tests/test_instrumentor.py similarity index 55% rename from opentelemetry-auto-instrumentation/tests/test_patcher.py rename to opentelemetry-auto-instrumentation/tests/test_instrumentor.py index 8e9e45b5d3e..cf887724c83 100644 --- a/opentelemetry-auto-instrumentation/tests/test_patcher.py +++ b/opentelemetry-auto-instrumentation/tests/test_instrumentor.py @@ -16,29 +16,29 @@ from logging import WARNING from unittest import TestCase -from opentelemetry.auto_instrumentation.patcher import BasePatcher +from opentelemetry.auto_instrumentation.instrumentor import BaseInstrumentor -class TestPatcher(TestCase): +class TestInstrumentor(TestCase): def test_protect(self): - class Patcher(BasePatcher): - def _patch(self): - return "patched" + class Instrumentor(BaseInstrumentor): + def _instrument(self): + return "instrumented" - def _unpatch(self): - return "unpatched" + def _uninstrument(self): + return "uninstrumented" - patcher = Patcher() + instrumentor = Instrumentor() with self.assertLogs(level=WARNING): - self.assertIs(patcher.unpatch(), None) + self.assertIs(instrumentor.uninstrument(), None) - self.assertEqual(patcher.patch(), "patched") + self.assertEqual(instrumentor.instrument(), "instrumented") with self.assertLogs(level=WARNING): - self.assertIs(patcher.patch(), None) + self.assertIs(instrumentor.instrument(), None) - self.assertEqual(patcher.unpatch(), "unpatched") + self.assertEqual(instrumentor.uninstrument(), "uninstrumented") with self.assertLogs(level=WARNING): - self.assertIs(patcher.unpatch(), None) + self.assertIs(instrumentor.uninstrument(), None) From 7a11b3bc18f22240379e6c4a78d8e50c620b7a1b Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Mon, 23 Mar 2020 16:15:58 -0600 Subject: [PATCH 11/27] More fixes --- 0001-Rename-to-auto_instrumentor.patch | 280 ------------------ .../propagation/tracecontexthttptextformat.py | 1 - .../example/formatter.py | 5 - .../example/hello.py | 5 - .../example/publisher_instrumented.py | 5 - .../auto_instrumentation/version.py | 2 +- 6 files changed, 1 insertion(+), 297 deletions(-) delete mode 100644 0001-Rename-to-auto_instrumentor.patch diff --git a/0001-Rename-to-auto_instrumentor.patch b/0001-Rename-to-auto_instrumentor.patch deleted file mode 100644 index bb75dd11d44..00000000000 --- a/0001-Rename-to-auto_instrumentor.patch +++ /dev/null @@ -1,280 +0,0 @@ -From 8586bdf43b03211b5e12b85430355bfb97b212bc Mon Sep 17 00:00:00 2001 -From: Diego Hurtado -Date: Fri, 20 Mar 2020 17:00:39 -0600 -Subject: [PATCH] Rename to auto_instrumentor - ---- - .../flask_example.py | 4 +- - ext/opentelemetry-ext-flask/setup.py | 4 +- - .../src/opentelemetry/ext/flask/__init__.py | 16 +++---- - ext/opentelemetry-ext-flask/tests/conftest.py | 8 ++-- - .../auto_instrumentation.py | 8 ++-- - .../{patcher.py => instrumentor.py} | 42 +++++++++---------- - .../{test_patcher.py => test_instrumentor.py} | 26 ++++++------ - 7 files changed, 54 insertions(+), 54 deletions(-) - rename opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/{patcher.py => instrumentor.py} (52%) - rename opentelemetry-auto-instrumentation/tests/{test_patcher.py => test_instrumentor.py} (55%) - -diff --git a/docs/examples/opentelemetry-example-app/src/opentelemetry_example_app/flask_example.py b/docs/examples/opentelemetry-example-app/src/opentelemetry_example_app/flask_example.py -index bf4b4646..544fe8cd 100644 ---- a/docs/examples/opentelemetry-example-app/src/opentelemetry_example_app/flask_example.py -+++ b/docs/examples/opentelemetry-example-app/src/opentelemetry_example_app/flask_example.py -@@ -21,7 +21,7 @@ import requests - - import opentelemetry.ext.http_requests - from opentelemetry import trace --from opentelemetry.ext.flask import FlaskPatcher -+from opentelemetry.ext.flask import FlaskInstrumentor - from opentelemetry.sdk.trace import TracerProvider - from opentelemetry.sdk.trace.export import ( - ConsoleSpanExporter, -@@ -33,7 +33,7 @@ trace.get_tracer_provider().add_span_processor( - SimpleExportSpanProcessor(ConsoleSpanExporter()) - ) - --FlaskPatcher().patch() -+FlaskInstrumentor().instrument() - app = flask.Flask(__name__) - opentelemetry.ext.http_requests.enable(trace.get_tracer_provider()) - -diff --git a/ext/opentelemetry-ext-flask/setup.py b/ext/opentelemetry-ext-flask/setup.py -index 13313eca..75d2f277 100644 ---- a/ext/opentelemetry-ext-flask/setup.py -+++ b/ext/opentelemetry-ext-flask/setup.py -@@ -26,8 +26,8 @@ with open(VERSION_FILENAME) as f: - setuptools.setup( - version=PACKAGE_INFO["__version__"], - entry_points={ -- "opentelemetry_auto_instrumentation_patcher": [ -- "flask = opentelemetry.ext.flask:FlaskPatcher" -+ "opentelemetry_auto_instrumentation_instrumentor": [ -+ "flask = opentelemetry.ext.flask:FlaskInstrumentor" - ] - }, - ) -diff --git a/ext/opentelemetry-ext-flask/src/opentelemetry/ext/flask/__init__.py b/ext/opentelemetry-ext-flask/src/opentelemetry/ext/flask/__init__.py -index 7364b0fe..09e22b8d 100644 ---- a/ext/opentelemetry-ext-flask/src/opentelemetry/ext/flask/__init__.py -+++ b/ext/opentelemetry-ext-flask/src/opentelemetry/ext/flask/__init__.py -@@ -7,7 +7,7 @@ import flask - - import opentelemetry.ext.wsgi as otel_wsgi - from opentelemetry import context, propagators, trace --from opentelemetry.auto_instrumentation.patcher import BasePatcher -+from opentelemetry.auto_instrumentation.instrumentor import BaseInstrumentor - from opentelemetry.ext.flask.version import __version__ - from opentelemetry.util import time_ns - -@@ -19,7 +19,7 @@ _ENVIRON_ACTIVATION_KEY = "opentelemetry-flask.activation_key" - _ENVIRON_TOKEN = "opentelemetry-flask.token" - - --class _PatchedFlask(flask.Flask): -+class _InstrumentedFlask(flask.Flask): - def __init__(self, *args, **kwargs): - - super().__init__(*args, **kwargs) -@@ -105,19 +105,19 @@ class _PatchedFlask(flask.Flask): - context.detach(flask.request.environ.get(_ENVIRON_TOKEN)) - - --class FlaskPatcher(BasePatcher): -- """A patcher for flask.Flask -+class FlaskInstrumentor(BaseInstrumentor): -+ """A instrumentor for flask.Flask - -- See `BasePatcher` -+ See `BaseInstrumentor` - """ - - def __init__(self): - super().__init__() - self._original_flask = None - -- def _patch(self): -+ def _instrument(self): - self._original_flask = flask.Flask -- flask.Flask = _PatchedFlask -+ flask.Flask = _InstrumentedFlask - -- def _unpatch(self): -+ def _uninstrument(self): - flask.Flask = self._original_flask -diff --git a/ext/opentelemetry-ext-flask/tests/conftest.py b/ext/opentelemetry-ext-flask/tests/conftest.py -index e3c59b6d..22a587ab 100644 ---- a/ext/opentelemetry-ext-flask/tests/conftest.py -+++ b/ext/opentelemetry-ext-flask/tests/conftest.py -@@ -11,14 +11,14 @@ - # 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. --from opentelemetry.ext.flask import FlaskPatcher -+from opentelemetry.ext.flask import FlaskInstrumentor - --_FLASK_PATCHER = FlaskPatcher() -+_FLASK_INSTRUMENTOR = FlaskInstrumentor() - - - def pytest_sessionstart(session): # pylint: disable=unused-argument -- _FLASK_PATCHER.patch() -+ _FLASK_INSTRUMENTOR.instrument() - - - def pytest_sessionfinish(session): # pylint: disable=unused-argument -- _FLASK_PATCHER.unpatch() -+ _FLASK_INSTRUMENTOR.uninstrument() -diff --git a/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/auto_instrumentation.py b/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/auto_instrumentation.py -index 44651e49..124f8694 100644 ---- a/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/auto_instrumentation.py -+++ b/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/auto_instrumentation.py -@@ -26,13 +26,13 @@ _LOG = getLogger(__file__) - def run() -> None: - - for entry_point in iter_entry_points( -- "opentelemetry_auto_instrumentation_patcher" -+ "opentelemetry_auto_instrumentation_instrumentor" - ): - try: -- entry_point.load()().patch() # type: ignore -- _LOG.debug("Patched %s", entry_point.name) -+ entry_point.load()().instrument() # type: ignore -+ _LOG.debug("Instrumented %s", entry_point.name) - - except Exception: # pylint: disable=broad-except -- _LOG.exception("Patching of %s failed", entry_point.name) -+ _LOG.exception("Instrumenting of %s failed", entry_point.name) - - run_path(argv[1], run_name="__main__") # type: ignore -diff --git a/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/patcher.py b/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/instrumentor.py -similarity index 52% -rename from opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/patcher.py -rename to opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/instrumentor.py -index ee5d3c68..a5ee0b90 100644 ---- a/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/patcher.py -+++ b/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/instrumentor.py -@@ -14,7 +14,7 @@ - # type: ignore - - """ --OpenTelemetry Auto Instrumentation Patcher -+OpenTelemetry Base Instrumentor - """ - - from abc import ABC, abstractmethod -@@ -23,43 +23,43 @@ from logging import getLogger - _LOG = getLogger(__name__) - - --class BasePatcher(ABC): -- """An ABC for patchers""" -+class BaseInstrumentor(ABC): -+ """An ABC for instrumentors""" - - def __init__(self): -- self._is_patched = False -+ self._is_instrumented = False - - @abstractmethod -- def _patch(self) -> None: -- """Patch""" -+ def _instrument(self) -> None: -+ """Instrument""" - - @abstractmethod -- def _unpatch(self) -> None: -- """Unpatch""" -+ def _uninstrument(self) -> None: -+ """Uninstrument""" - -- def patch(self) -> None: -- """Patch""" -+ def instrument(self) -> None: -+ """Instrument""" - -- if not self._is_patched: -- result = self._patch() -- self._is_patched = True -+ if not self._is_instrumented: -+ result = self._instrument() -+ self._is_instrumented = True - return result - -- _LOG.warning("Attempting to patch while already patched") -+ _LOG.warning("Attempting to instrument while already instrumented") - - return None - -- def unpatch(self) -> None: -- """Unpatch""" -+ def uninstrument(self) -> None: -+ """Uninstrument""" - -- if self._is_patched: -- result = self._unpatch() -- self._is_patched = False -+ if self._is_instrumented: -+ result = self._uninstrument() -+ self._is_instrumented = False - return result - -- _LOG.warning("Attempting to unpatch while already unpatched") -+ _LOG.warning("Attempting to uninstrument while already uninstrumented") - - return None - - --__all__ = ["BasePatcher"] -+__all__ = ["BaseInstrumentor"] -diff --git a/opentelemetry-auto-instrumentation/tests/test_patcher.py b/opentelemetry-auto-instrumentation/tests/test_instrumentor.py -similarity index 55% -rename from opentelemetry-auto-instrumentation/tests/test_patcher.py -rename to opentelemetry-auto-instrumentation/tests/test_instrumentor.py -index 8e9e45b5..cf887724 100644 ---- a/opentelemetry-auto-instrumentation/tests/test_patcher.py -+++ b/opentelemetry-auto-instrumentation/tests/test_instrumentor.py -@@ -16,29 +16,29 @@ - from logging import WARNING - from unittest import TestCase - --from opentelemetry.auto_instrumentation.patcher import BasePatcher -+from opentelemetry.auto_instrumentation.instrumentor import BaseInstrumentor - - --class TestPatcher(TestCase): -+class TestInstrumentor(TestCase): - def test_protect(self): -- class Patcher(BasePatcher): -- def _patch(self): -- return "patched" -+ class Instrumentor(BaseInstrumentor): -+ def _instrument(self): -+ return "instrumented" - -- def _unpatch(self): -- return "unpatched" -+ def _uninstrument(self): -+ return "uninstrumented" - -- patcher = Patcher() -+ instrumentor = Instrumentor() - - with self.assertLogs(level=WARNING): -- self.assertIs(patcher.unpatch(), None) -+ self.assertIs(instrumentor.uninstrument(), None) - -- self.assertEqual(patcher.patch(), "patched") -+ self.assertEqual(instrumentor.instrument(), "instrumented") - - with self.assertLogs(level=WARNING): -- self.assertIs(patcher.patch(), None) -+ self.assertIs(instrumentor.instrument(), None) - -- self.assertEqual(patcher.unpatch(), "unpatched") -+ self.assertEqual(instrumentor.uninstrument(), "uninstrumented") - - with self.assertLogs(level=WARNING): -- self.assertIs(patcher.unpatch(), None) -+ self.assertIs(instrumentor.uninstrument(), None) --- -2.17.1 - diff --git a/opentelemetry-api/src/opentelemetry/trace/propagation/tracecontexthttptextformat.py b/opentelemetry-api/src/opentelemetry/trace/propagation/tracecontexthttptextformat.py index 4cf027a4a81..28db4e45575 100644 --- a/opentelemetry-api/src/opentelemetry/trace/propagation/tracecontexthttptextformat.py +++ b/opentelemetry-api/src/opentelemetry/trace/propagation/tracecontexthttptextformat.py @@ -129,7 +129,6 @@ def inject( span_context.span_id, span_context.trace_flags, ) - print(self) set_in_carrier( carrier, self._TRACEPARENT_HEADER_NAME, traceparent_string ) diff --git a/opentelemetry-auto-instrumentation/example/formatter.py b/opentelemetry-auto-instrumentation/example/formatter.py index fd294f5d216..190eb7efbfb 100644 --- a/opentelemetry-auto-instrumentation/example/formatter.py +++ b/opentelemetry-auto-instrumentation/example/formatter.py @@ -15,15 +15,11 @@ from flask import Flask, request from opentelemetry import propagators, trace -from opentelemetry.propagators import set_global_httptextformat from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace.export import ( ConsoleSpanExporter, SimpleExportSpanProcessor, ) -from opentelemetry.trace.propagation.tracecontexthttptextformat import ( - TraceContextHTTPTextFormat, -) from utils import get_as_list app = Flask(__name__) @@ -34,7 +30,6 @@ trace.get_tracer_provider().add_span_processor( SimpleExportSpanProcessor(ConsoleSpanExporter()) ) -set_global_httptextformat(TraceContextHTTPTextFormat()) @app.route("/format_request") diff --git a/opentelemetry-auto-instrumentation/example/hello.py b/opentelemetry-auto-instrumentation/example/hello.py index 7d13b4cb733..003c74afe28 100644 --- a/opentelemetry-auto-instrumentation/example/hello.py +++ b/opentelemetry-auto-instrumentation/example/hello.py @@ -18,15 +18,11 @@ from requests import get from opentelemetry import propagators, trace -from opentelemetry.propagators import set_global_httptextformat from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace.export import ( ConsoleSpanExporter, SimpleExportSpanProcessor, ) -from opentelemetry.trace.propagation.tracecontexthttptextformat import ( - TraceContextHTTPTextFormat, -) app = Flask(__name__) @@ -36,7 +32,6 @@ trace.get_tracer_provider().add_span_processor( SimpleExportSpanProcessor(ConsoleSpanExporter()) ) -set_global_httptextformat(TraceContextHTTPTextFormat()) def http_get(port, path, param, value): diff --git a/opentelemetry-auto-instrumentation/example/publisher_instrumented.py b/opentelemetry-auto-instrumentation/example/publisher_instrumented.py index e13008020b2..7fc9f97dff5 100644 --- a/opentelemetry-auto-instrumentation/example/publisher_instrumented.py +++ b/opentelemetry-auto-instrumentation/example/publisher_instrumented.py @@ -15,15 +15,11 @@ from flask import Flask, request from opentelemetry import propagators, trace -from opentelemetry.propagators import set_global_httptextformat from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace.export import ( ConsoleSpanExporter, SimpleExportSpanProcessor, ) -from opentelemetry.trace.propagation.tracecontexthttptextformat import ( - TraceContextHTTPTextFormat, -) from utils import get_as_list app = Flask(__name__) @@ -34,7 +30,6 @@ trace.get_tracer_provider().add_span_processor( SimpleExportSpanProcessor(ConsoleSpanExporter()) ) -set_global_httptextformat(TraceContextHTTPTextFormat()) @app.route("/publish_request") diff --git a/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/version.py b/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/version.py index 9fe0d7a99e3..373ae92cb85 100644 --- a/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/version.py +++ b/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.1.dev0" +__version__ = "0.6.dev0" From 31ec6c36ce5e6291884a0f08ac91601e66a707ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mauricio=20V=C3=A1squez?= Date: Wed, 25 Mar 2020 11:41:18 -0500 Subject: [PATCH 12/27] fix documents --- docs/auto_instrumentation/auto_instrumentation.rst | 7 +++++++ docs/auto_instrumentation/instrumentor.rst | 7 +++++++ docs/index.rst | 4 +--- docs/opentelemetry.auto_instrumentation.patcher.rst | 8 -------- 4 files changed, 15 insertions(+), 11 deletions(-) create mode 100644 docs/auto_instrumentation/auto_instrumentation.rst create mode 100644 docs/auto_instrumentation/instrumentor.rst delete mode 100644 docs/opentelemetry.auto_instrumentation.patcher.rst diff --git a/docs/auto_instrumentation/auto_instrumentation.rst b/docs/auto_instrumentation/auto_instrumentation.rst new file mode 100644 index 00000000000..a45512f7f9d --- /dev/null +++ b/docs/auto_instrumentation/auto_instrumentation.rst @@ -0,0 +1,7 @@ +OpenTelemetry Python Autoinstrumentation +======================================== + +.. toctree:: + :maxdepth: 1 + + instrumentor diff --git a/docs/auto_instrumentation/instrumentor.rst b/docs/auto_instrumentation/instrumentor.rst new file mode 100644 index 00000000000..c94c0237f57 --- /dev/null +++ b/docs/auto_instrumentation/instrumentor.rst @@ -0,0 +1,7 @@ +opentelemetry.auto_instrumentation.instrumentor package +======================================================= + +.. automodule:: opentelemetry.auto_instrumentation.instrumentor + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/index.rst b/docs/index.rst index 777bd0dfde4..2cfaaae833d 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -68,6 +68,7 @@ install api/api sdk/sdk + auto_instrumentation/auto_instrumentation .. toctree:: :maxdepth: 1 @@ -82,9 +83,6 @@ install :caption: Examples :name: examples :glob: - :caption: OpenTelemetry Auto Instrumentation: - - opentelemetry.auto_instrumentation.patcher examples/** diff --git a/docs/opentelemetry.auto_instrumentation.patcher.rst b/docs/opentelemetry.auto_instrumentation.patcher.rst deleted file mode 100644 index 731d03d6e07..00000000000 --- a/docs/opentelemetry.auto_instrumentation.patcher.rst +++ /dev/null @@ -1,8 +0,0 @@ -opentelemetry.auto_instrumentation.patcher package -================================================== - - -Module contents ---------------- - -.. automodule:: opentelemetry.auto_instrumentation.patcher From b18efe3301c16ac7715e46ef3010318606499546 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Wed, 25 Mar 2020 16:14:34 -0600 Subject: [PATCH 13/27] Add comment --- ext/opentelemetry-ext-flask/tests/test_flask_integration.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ext/opentelemetry-ext-flask/tests/test_flask_integration.py b/ext/opentelemetry-ext-flask/tests/test_flask_integration.py index b81ad673cbe..cd7709596f0 100644 --- a/ext/opentelemetry-ext-flask/tests/test_flask_integration.py +++ b/ext/opentelemetry-ext-flask/tests/test_flask_integration.py @@ -42,6 +42,8 @@ def expected_attributes(override_attributes): class TestFlaskIntegration(WsgiTestBase): def setUp(self): + # No instrumentation code is here because it is present in the + # conftest.py file next to this file. super().setUp() self.app = Flask(__name__) From bc7a9a70b327e31f01fd4aeff74b86d5f10265ef Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Wed, 25 Mar 2020 16:17:00 -0600 Subject: [PATCH 14/27] Update opentelemetry-auto-instrumentation/README.rst MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Mauricio Vásquez --- opentelemetry-auto-instrumentation/README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opentelemetry-auto-instrumentation/README.rst b/opentelemetry-auto-instrumentation/README.rst index d7b34d1ab95..c3263c08400 100644 --- a/opentelemetry-auto-instrumentation/README.rst +++ b/opentelemetry-auto-instrumentation/README.rst @@ -3,7 +3,7 @@ OpenTelemetry Auto Instrumentation |pypi| -.. |pypi| image:: https://badge.fury.io/py/opentelemetry-api.svg +.. |pypi| image:: https://badge.fury.io/py/opentelemetry-auto-instrumentation.svg :target: https://pypi.org/project/opentelemetry-auto-instrumentation/ Installation From 06e5a2bd848e4b70770e9d193bb7ef0ff8a13049 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Wed, 25 Mar 2020 16:17:33 -0600 Subject: [PATCH 15/27] Update opentelemetry-auto-instrumentation/README.rst MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Mauricio Vásquez --- opentelemetry-auto-instrumentation/README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opentelemetry-auto-instrumentation/README.rst b/opentelemetry-auto-instrumentation/README.rst index c3263c08400..5205ecca0e4 100644 --- a/opentelemetry-auto-instrumentation/README.rst +++ b/opentelemetry-auto-instrumentation/README.rst @@ -1,5 +1,5 @@ OpenTelemetry Auto Instrumentation -============================================================================ +============================ |pypi| From f23d0046a60e5863e6ea6d8c3a508a3e09890cfa Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Wed, 25 Mar 2020 16:27:06 -0600 Subject: [PATCH 16/27] Move description to the package docstring --- opentelemetry-auto-instrumentation/README.rst | 13 --------- .../auto_instrumentation/__init__.py | 28 +++++++++++++++++++ .../auto_instrumentation/version.py | 2 +- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/opentelemetry-auto-instrumentation/README.rst b/opentelemetry-auto-instrumentation/README.rst index 5205ecca0e4..7f66da2c388 100644 --- a/opentelemetry-auto-instrumentation/README.rst +++ b/opentelemetry-auto-instrumentation/README.rst @@ -17,16 +17,3 @@ References ---------- * `OpenTelemetry Project `_ - -Usage ------ - -This package provides a command that automatically instruments a program: - -:: - - opentelemetry-auto-instrumentation program.py - -The code in ``program.py`` needs to use one of the packages for which there is -an OpenTelemetry extension. For a list of the available extensions please check -`here `_. diff --git a/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/__init__.py b/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/__init__.py index e69de29bb2d..dfafb5386a9 100644 --- a/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/__init__.py +++ b/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/__init__.py @@ -0,0 +1,28 @@ +# 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. + +""" +Usage +----- + +This package provides a command that automatically instruments a program: + +:: + + opentelemetry-auto-instrumentation program.py + +The code in ``program.py`` needs to use one of the packages for which there is +an OpenTelemetry extension. For a list of the available extensions please check +`here `_. +""" diff --git a/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/version.py b/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/version.py index 373ae92cb85..0941210ca3f 100644 --- a/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/version.py +++ b/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/version.py @@ -1,4 +1,4 @@ -# Copyright 2020, OpenTelemetry Authors +# 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. From 3218bff52a8f3ae851de7517dbbfb36284b5a17c Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Wed, 25 Mar 2020 16:38:22 -0600 Subject: [PATCH 17/27] Update opentelemetry-auto-instrumentation/example/README.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Mauricio Vásquez --- .../example/README.md | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/opentelemetry-auto-instrumentation/example/README.md b/opentelemetry-auto-instrumentation/example/README.md index f8518794f44..553996d0ba6 100644 --- a/opentelemetry-auto-instrumentation/example/README.md +++ b/opentelemetry-auto-instrumentation/example/README.md @@ -58,14 +58,12 @@ $ source auto_instrumentation/bin/activate # Installation ```sh -$ git clone git@github.com:open-telemetry/opentelemetry-python.git -$ cd opentelemetry-python -$ pip3 install -e opentelemetry-api -$ pip3 install -e opentelemetry-sdk -$ pip3 install -e opentelemetry-auto-instrumentation -$ pip3 install -e ext/opentelemetry-ext-flask -$ pip3 install flask -$ pip3 install requests +$ pip install opentelemetry-api +$ pip install opentelemetry-sdk +$ pip install opentelemetry-auto-instrumentation +$ pip install ext/opentelemetry-ext-flask +$ pip install flask +$ pip install requests ``` # Execution From 6f36a3330671fc696b46ff9bc1afa6bb6af784d4 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Wed, 25 Mar 2020 16:43:22 -0600 Subject: [PATCH 18/27] Use python instead of python3 --- opentelemetry-auto-instrumentation/README.rst | 2 +- opentelemetry-auto-instrumentation/example/README.md | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/opentelemetry-auto-instrumentation/README.rst b/opentelemetry-auto-instrumentation/README.rst index 7f66da2c388..b153072ae5a 100644 --- a/opentelemetry-auto-instrumentation/README.rst +++ b/opentelemetry-auto-instrumentation/README.rst @@ -1,5 +1,5 @@ OpenTelemetry Auto Instrumentation -============================ +================================== |pypi| diff --git a/opentelemetry-auto-instrumentation/example/README.md b/opentelemetry-auto-instrumentation/example/README.md index 553996d0ba6..8ea8a1e430d 100644 --- a/opentelemetry-auto-instrumentation/example/README.md +++ b/opentelemetry-auto-instrumentation/example/README.md @@ -74,17 +74,17 @@ This is done in 3 separate consoles, one to run each of the scripts that make up ```sh $ source auto_instrumentation/bin/activate -$ python3 opentelemetry-python/opentelemetry-auto-instrumentation/example/formatter.py +$ python opentelemetry-python/opentelemetry-auto-instrumentation/example/formatter.py ``` ```sh $ source auto_instrumentation/bin/activate -$ python3 opentelemetry-python/opentelemetry-auto-instrumentation/example/publisher_instrumented.py +$ python opentelemetry-python/opentelemetry-auto-instrumentation/example/publisher_instrumented.py ``` ```sh $ source auto_instrumentation/bin/activate -$ python3 opentelemetry-python/opentelemetry-auto-instrumentation/example/hello.py testing +$ python opentelemetry-python/opentelemetry-auto-instrumentation/example/hello.py testing ``` The execution of `publisher_instrumented.py` should return an output similar to: @@ -106,7 +106,7 @@ $ opentelemetry-auto-instrumentation opentelemetry-python/opentelemetry-auto-ins In the console where you previously executed `hello.py`, run again this again: ```sh -$ python3 opentelemetry-python/opentelemetry-auto-instrumentation/example/hello.py testing +$ python opentelemetry-python/opentelemetry-auto-instrumentation/example/hello.py testing ``` The execution of `publisher_uninstrumented.py` should return an output similar to: From f0f182eacb28f3f846a94c535a74625d17386db0 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Wed, 25 Mar 2020 17:37:10 -0600 Subject: [PATCH 19/27] Remove formatter --- .../example/README.md | 75 +++++++++---------- .../example/{formatter.py => client.py} | 29 +++---- .../example/hello.py | 61 --------------- ...instrumented.py => server_instrumented.py} | 18 ++--- ...strumented.py => server_uninstrumented.py} | 9 +-- .../example/utils.py | 21 ------ 6 files changed, 61 insertions(+), 152 deletions(-) rename opentelemetry-auto-instrumentation/example/{formatter.py => client.py} (68%) delete mode 100644 opentelemetry-auto-instrumentation/example/hello.py rename opentelemetry-auto-instrumentation/example/{publisher_instrumented.py => server_instrumented.py} (78%) rename opentelemetry-auto-instrumentation/example/{publisher_uninstrumented.py => server_uninstrumented.py} (87%) delete mode 100644 opentelemetry-auto-instrumentation/example/utils.py diff --git a/opentelemetry-auto-instrumentation/example/README.md b/opentelemetry-auto-instrumentation/example/README.md index 8ea8a1e430d..40ff5c4bc4d 100644 --- a/opentelemetry-auto-instrumentation/example/README.md +++ b/opentelemetry-auto-instrumentation/example/README.md @@ -5,44 +5,42 @@ for OpenTracing that can be found [here](https://github.com/yurishkuro/opentraci This example uses 2 scripts whose main difference is they being instrumented manually or not: -1. `publisher_instrumented.py` which has been instrumented manually -2. `publisher_uninstrumented.py` which has not been instrumented manually +1. `server_instrumented.py` which has been instrumented manually +2. `server_uninstrumented.py` which has not been instrumented manually The former will be run without the automatic instrumentation agent and the latter with the automatic instrumentation -agent. They should produce an equal result, showing that the automatic instrumentation agent does the equivalent +agent. They should produce the same result, showing that the automatic instrumentation agent does the equivalent of what manual instrumentation does. In order to understand this better, here is the relevant part of both scripts: -## Publisher instrumented manually +## Manually instrumented server -`publisher_instrumented.py` +`server_instrumented.py` ```python -@app.route("/publish_request") -def publish_request(): +@app.route("/server_request") +def server_request(): with tracer.start_as_current_span( - "publish_request", - parent=propagators.extract(get_as_list, request.headers)[ - "current-span" - ], + "server_request", + parent=propagators.extract( + lambda dict_, key: dict_.get(key, []), request.headers + )["current-span"], ): - hello_str = request.args.get("helloStr") - print(hello_str) - return "published" + print(request.args.get("param")) + return "served" ``` ## Publisher not instrumented manually -`publisher_uninstrumented.py` +`server_uninstrumented.py` ```python -@app.route("/publish_request") -def publish_request(): - hello_str = request.args.get("helloStr") - print(hello_str) - return "published" +@app.route("/server_request") +def server_request(): + print(request.args.get("param")) + return "served" ``` # Preparation @@ -68,53 +66,48 @@ $ pip install requests # Execution -## Execution of the manually instrumented publisher +## Execution of the manually instrumented server -This is done in 3 separate consoles, one to run each of the scripts that make up this example: +This is done in 2 separate consoles, one to run each of the scripts that make up this example: ```sh $ source auto_instrumentation/bin/activate -$ python opentelemetry-python/opentelemetry-auto-instrumentation/example/formatter.py +$ python opentelemetry-python/opentelemetry-auto-instrumentation/example/server_instrumented.py ``` ```sh $ source auto_instrumentation/bin/activate -$ python opentelemetry-python/opentelemetry-auto-instrumentation/example/publisher_instrumented.py +$ python opentelemetry-python/opentelemetry-auto-instrumentation/example/client.py testing ``` -```sh -$ source auto_instrumentation/bin/activate -$ python opentelemetry-python/opentelemetry-auto-instrumentation/example/hello.py testing -``` - -The execution of `publisher_instrumented.py` should return an output similar to: +The execution of `server_instrumented.py` should return an output similar to: ```sh Hello, testing! -Span(name="publish_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 /publish_request?helloStr=Hello%2C+testing%21 HTTP/1.1" 200 - +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 - ``` -## Execution of an automatically instrumented publisher +## Execution of an automatically instrumented server -Now, kill the execution of `publisher_instrumented.py` with `ctrl + c` and run this instead: +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/publisher_uninstrumented.py +$ opentelemetry-auto-instrumentation opentelemetry-python/opentelemetry-auto-instrumentation/example/server_uninstrumented.py ``` -In the console where you previously executed `hello.py`, run again this again: +In the console where you previously executed `client.py`, run again this again: ```sh -$ python opentelemetry-python/opentelemetry-auto-instrumentation/example/hello.py testing +$ python opentelemetry-python/opentelemetry-auto-instrumentation/example/client.py testing ``` -The execution of `publisher_uninstrumented.py` should return an output similar to: +The execution of `server_uninstrumented.py` should return an output similar to: ```sh Hello, testing! -Span(name="publish_request", context=SpanContext(trace_id=0xf26b28b5243e48f5f96bfc753f95f3f0, span_id=0xbeb179a095d087ed, trace_state={}), kind=SpanKind.SERVER, parent=, 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 /publish_request?helloStr=Hello%2C+testing%21 HTTP/1.1" 200 - +Span(name="serv_request", context=SpanContext(trace_id=0xf26b28b5243e48f5f96bfc753f95f3f0, span_id=0xbeb179a095d087ed, trace_state={}), kind=SpanKind.SERVER, parent=, 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 - ``` -As you can see, both outputs are equal since the automatic instrumentation does what the manual instrumentation does too. +As you can see, both outputs are equivalentsince the automatic instrumentation does what the manual instrumentation does too. diff --git a/opentelemetry-auto-instrumentation/example/formatter.py b/opentelemetry-auto-instrumentation/example/client.py similarity index 68% rename from opentelemetry-auto-instrumentation/example/formatter.py rename to opentelemetry-auto-instrumentation/example/client.py index 190eb7efbfb..656640d0f62 100644 --- a/opentelemetry-auto-instrumentation/example/formatter.py +++ b/opentelemetry-auto-instrumentation/example/client.py @@ -12,7 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -from flask import Flask, request +from sys import argv + +from flask import Flask +from requests import get from opentelemetry import propagators, trace from opentelemetry.sdk.trace import TracerProvider @@ -20,7 +23,6 @@ ConsoleSpanExporter, SimpleExportSpanProcessor, ) -from utils import get_as_list app = Flask(__name__) @@ -32,18 +34,17 @@ ) -@app.route("/format_request") -def format_request(): +assert len(argv) == 2 - with tracer.start_as_current_span( - "format_request", - parent=propagators.extract(get_as_list, request.headers)[ - "current-span" - ], - ): - hello_to = request.args.get("helloTo") - return "Hello, %s!" % hello_to +with tracer.start_as_current_span("client"): + with tracer.start_as_current_span("client-server"): + headers = {} + propagators.inject(dict.__setitem__, headers) + requested = get( + "http://localhost:8082/server_request", + params={"param": argv[1]}, + headers=headers, + ) -if __name__ == "__main__": - app.run(port=8081) + assert requested.status_code == 200 diff --git a/opentelemetry-auto-instrumentation/example/hello.py b/opentelemetry-auto-instrumentation/example/hello.py deleted file mode 100644 index 003c74afe28..00000000000 --- a/opentelemetry-auto-instrumentation/example/hello.py +++ /dev/null @@ -1,61 +0,0 @@ -# Copyright 2020, 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. - -from sys import argv - -from flask import Flask -from requests import get - -from opentelemetry import propagators, trace -from opentelemetry.sdk.trace import TracerProvider -from opentelemetry.sdk.trace.export import ( - ConsoleSpanExporter, - SimpleExportSpanProcessor, -) - -app = Flask(__name__) - -trace.set_tracer_provider(TracerProvider()) -tracer = trace.get_tracer_provider().get_tracer(__name__) - -trace.get_tracer_provider().add_span_processor( - SimpleExportSpanProcessor(ConsoleSpanExporter()) -) - - -def http_get(port, path, param, value): - - headers = {} - propagators.inject(dict.__setitem__, headers) - requested = get( - "http://localhost:{}/{}".format(port, path), - params={param: value}, - headers=headers, - ) - - assert requested.status_code == 200 - return requested.text - - -assert len(argv) == 2 - -hello_to = argv[1] - -with tracer.start_as_current_span("hello") as hello_span: - - with tracer.start_as_current_span("hello-format", parent=hello_span): - hello_str = http_get(8081, "format_request", "helloTo", hello_to) - - with tracer.start_as_current_span("hello-publish", parent=hello_span): - http_get(8082, "publish_request", "helloStr", hello_str) diff --git a/opentelemetry-auto-instrumentation/example/publisher_instrumented.py b/opentelemetry-auto-instrumentation/example/server_instrumented.py similarity index 78% rename from opentelemetry-auto-instrumentation/example/publisher_instrumented.py rename to opentelemetry-auto-instrumentation/example/server_instrumented.py index 7fc9f97dff5..8f9c27d274e 100644 --- a/opentelemetry-auto-instrumentation/example/publisher_instrumented.py +++ b/opentelemetry-auto-instrumentation/example/server_instrumented.py @@ -20,7 +20,6 @@ ConsoleSpanExporter, SimpleExportSpanProcessor, ) -from utils import get_as_list app = Flask(__name__) @@ -32,18 +31,17 @@ ) -@app.route("/publish_request") -def publish_request(): +@app.route("/server_request") +def server_request(): with tracer.start_as_current_span( - "publish_request", - parent=propagators.extract(get_as_list, request.headers)[ - "current-span" - ], + "server_request", + parent=propagators.extract( + lambda dict_, key: dict_.get(key, []), request.headers + )["current-span"], ): - hello_str = request.args.get("helloStr") - print(hello_str) - return "published" + print(request.args.get("param")) + return "served" if __name__ == "__main__": diff --git a/opentelemetry-auto-instrumentation/example/publisher_uninstrumented.py b/opentelemetry-auto-instrumentation/example/server_uninstrumented.py similarity index 87% rename from opentelemetry-auto-instrumentation/example/publisher_uninstrumented.py rename to opentelemetry-auto-instrumentation/example/server_uninstrumented.py index da8ca38a02c..1a8d0641f8e 100644 --- a/opentelemetry-auto-instrumentation/example/publisher_uninstrumented.py +++ b/opentelemetry-auto-instrumentation/example/server_uninstrumented.py @@ -30,11 +30,10 @@ ) -@app.route("/publish_request") -def publish_request(): - hello_str = request.args.get("helloStr") - print(hello_str) - return "published" +@app.route("/server_request") +def server_request(): + print(request.args.get("param")) + return "served" if __name__ == "__main__": diff --git a/opentelemetry-auto-instrumentation/example/utils.py b/opentelemetry-auto-instrumentation/example/utils.py deleted file mode 100644 index 0fa82af694b..00000000000 --- a/opentelemetry-auto-instrumentation/example/utils.py +++ /dev/null @@ -1,21 +0,0 @@ -# Copyright 2020, 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. - - -def get_as_list(dict_object, key): - value = dict_object.get(key) - return value if value is not None else [] - - -__all__ = ["get_as_list"] From 0f65460fb009aa05134a38f4879c997890931292 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Wed, 25 Mar 2020 17:40:58 -0600 Subject: [PATCH 20/27] Change logger --- .../auto_instrumentation/auto_instrumentation.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/auto_instrumentation.py b/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/auto_instrumentation.py index 124f8694533..7a64c1759fe 100644 --- a/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/auto_instrumentation.py +++ b/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/auto_instrumentation.py @@ -20,7 +20,7 @@ from pkg_resources import iter_entry_points -_LOG = getLogger(__file__) +logger = getLogger(__file__) def run() -> None: @@ -30,9 +30,9 @@ def run() -> None: ): try: entry_point.load()().instrument() # type: ignore - _LOG.debug("Instrumented %s", entry_point.name) + logger.debug("Instrumented %s", entry_point.name) except Exception: # pylint: disable=broad-except - _LOG.exception("Instrumenting of %s failed", entry_point.name) + logger.exception("Instrumenting of %s failed", entry_point.name) run_path(argv[1], run_name="__main__") # type: ignore From 49076638d4e6aa189265e3b5523bf4a12062712f Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Wed, 25 Mar 2020 17:44:37 -0600 Subject: [PATCH 21/27] Update opentelemetry-auto-instrumentation/tests/__init__.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Mauricio Vásquez --- .../tests/__init__.py | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/opentelemetry-auto-instrumentation/tests/__init__.py b/opentelemetry-auto-instrumentation/tests/__init__.py index 6ab2e961ec4..8b137891791 100644 --- a/opentelemetry-auto-instrumentation/tests/__init__.py +++ b/opentelemetry-auto-instrumentation/tests/__init__.py @@ -1,13 +1 @@ -# Copyright 2020, 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. + From 94f6167e6284df5d8beb5ab0a7c8394c148655ed Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Wed, 25 Mar 2020 17:43:42 -0600 Subject: [PATCH 22/27] Remove year --- opentelemetry-auto-instrumentation/example/client.py | 2 +- .../example/server_instrumented.py | 2 +- .../example/server_uninstrumented.py | 2 +- opentelemetry-auto-instrumentation/setup.py | 2 +- .../opentelemetry/auto_instrumentation/auto_instrumentation.py | 2 +- .../src/opentelemetry/auto_instrumentation/instrumentor.py | 2 +- opentelemetry-auto-instrumentation/tests/test_instrumentor.py | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/opentelemetry-auto-instrumentation/example/client.py b/opentelemetry-auto-instrumentation/example/client.py index 656640d0f62..c8301003be7 100644 --- a/opentelemetry-auto-instrumentation/example/client.py +++ b/opentelemetry-auto-instrumentation/example/client.py @@ -1,4 +1,4 @@ -# Copyright 2020, OpenTelemetry Authors +# 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. diff --git a/opentelemetry-auto-instrumentation/example/server_instrumented.py b/opentelemetry-auto-instrumentation/example/server_instrumented.py index 8f9c27d274e..e42b8057c1f 100644 --- a/opentelemetry-auto-instrumentation/example/server_instrumented.py +++ b/opentelemetry-auto-instrumentation/example/server_instrumented.py @@ -1,4 +1,4 @@ -# Copyright 2020, OpenTelemetry Authors +# 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. diff --git a/opentelemetry-auto-instrumentation/example/server_uninstrumented.py b/opentelemetry-auto-instrumentation/example/server_uninstrumented.py index 1a8d0641f8e..b8360341ab2 100644 --- a/opentelemetry-auto-instrumentation/example/server_uninstrumented.py +++ b/opentelemetry-auto-instrumentation/example/server_uninstrumented.py @@ -1,4 +1,4 @@ -# Copyright 2020, OpenTelemetry Authors +# 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. diff --git a/opentelemetry-auto-instrumentation/setup.py b/opentelemetry-auto-instrumentation/setup.py index 8d6300384a4..86f8faedbcf 100644 --- a/opentelemetry-auto-instrumentation/setup.py +++ b/opentelemetry-auto-instrumentation/setup.py @@ -1,4 +1,4 @@ -# Copyright 2020, OpenTelemetry Authors +# 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. diff --git a/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/auto_instrumentation.py b/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/auto_instrumentation.py index 7a64c1759fe..7aa831ec355 100644 --- a/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/auto_instrumentation.py +++ b/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/auto_instrumentation.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 -# Copyright 2020, OpenTelemetry Authors +# 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. diff --git a/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/instrumentor.py b/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/instrumentor.py index a5ee0b90e59..9deb6b15238 100644 --- a/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/instrumentor.py +++ b/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/instrumentor.py @@ -1,4 +1,4 @@ -# Copyright 2020, OpenTelemetry Authors +# 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. diff --git a/opentelemetry-auto-instrumentation/tests/test_instrumentor.py b/opentelemetry-auto-instrumentation/tests/test_instrumentor.py index cf887724c83..1324213536c 100644 --- a/opentelemetry-auto-instrumentation/tests/test_instrumentor.py +++ b/opentelemetry-auto-instrumentation/tests/test_instrumentor.py @@ -1,4 +1,4 @@ -# Copyright 2020, OpenTelemetry Authors +# 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. From 91803f9b452d9b98d516d73e76f0baa99a34ce9e Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Thu, 26 Mar 2020 14:09:33 -0600 Subject: [PATCH 23/27] Remove line --- opentelemetry-auto-instrumentation/example/README.md | 1 - .../example/server_instrumented.py | 1 - 2 files changed, 2 deletions(-) diff --git a/opentelemetry-auto-instrumentation/example/README.md b/opentelemetry-auto-instrumentation/example/README.md index 40ff5c4bc4d..46b0b44b2c8 100644 --- a/opentelemetry-auto-instrumentation/example/README.md +++ b/opentelemetry-auto-instrumentation/example/README.md @@ -21,7 +21,6 @@ In order to understand this better, here is the relevant part of both scripts: ```python @app.route("/server_request") def server_request(): - with tracer.start_as_current_span( "server_request", parent=propagators.extract( diff --git a/opentelemetry-auto-instrumentation/example/server_instrumented.py b/opentelemetry-auto-instrumentation/example/server_instrumented.py index e42b8057c1f..1c78aab15d8 100644 --- a/opentelemetry-auto-instrumentation/example/server_instrumented.py +++ b/opentelemetry-auto-instrumentation/example/server_instrumented.py @@ -33,7 +33,6 @@ @app.route("/server_request") def server_request(): - with tracer.start_as_current_span( "server_request", parent=propagators.extract( From 410817e42cf2d385da28122ed537059a4ebdeac1 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Thu, 26 Mar 2020 14:12:07 -0600 Subject: [PATCH 24/27] Move examples --- .../examples}/example/README.md | 0 .../examples}/example/client.py | 0 .../examples}/example/server_instrumented.py | 0 .../examples}/example/server_uninstrumented.py | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename {opentelemetry-auto-instrumentation => docs/examples}/example/README.md (100%) rename {opentelemetry-auto-instrumentation => docs/examples}/example/client.py (100%) rename {opentelemetry-auto-instrumentation => docs/examples}/example/server_instrumented.py (100%) rename {opentelemetry-auto-instrumentation => docs/examples}/example/server_uninstrumented.py (100%) diff --git a/opentelemetry-auto-instrumentation/example/README.md b/docs/examples/example/README.md similarity index 100% rename from opentelemetry-auto-instrumentation/example/README.md rename to docs/examples/example/README.md diff --git a/opentelemetry-auto-instrumentation/example/client.py b/docs/examples/example/client.py similarity index 100% rename from opentelemetry-auto-instrumentation/example/client.py rename to docs/examples/example/client.py diff --git a/opentelemetry-auto-instrumentation/example/server_instrumented.py b/docs/examples/example/server_instrumented.py similarity index 100% rename from opentelemetry-auto-instrumentation/example/server_instrumented.py rename to docs/examples/example/server_instrumented.py diff --git a/opentelemetry-auto-instrumentation/example/server_uninstrumented.py b/docs/examples/example/server_uninstrumented.py similarity index 100% rename from opentelemetry-auto-instrumentation/example/server_uninstrumented.py rename to docs/examples/example/server_uninstrumented.py From fdf1774afd424e348f84c389934abaf87f605d78 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Thu, 26 Mar 2020 14:13:26 -0600 Subject: [PATCH 25/27] Remove blank line --- opentelemetry-auto-instrumentation/tests/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/opentelemetry-auto-instrumentation/tests/__init__.py b/opentelemetry-auto-instrumentation/tests/__init__.py index 8b137891791..e69de29bb2d 100644 --- a/opentelemetry-auto-instrumentation/tests/__init__.py +++ b/opentelemetry-auto-instrumentation/tests/__init__.py @@ -1 +0,0 @@ - From c8df74bfa1d24006234d0063f61d8478df613865 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Thu, 26 Mar 2020 17:53:22 -0600 Subject: [PATCH 26/27] Rename directory --- docs/examples/{example => auto-instrumentation}/README.md | 0 docs/examples/{example => auto-instrumentation}/client.py | 0 .../{example => auto-instrumentation}/server_instrumented.py | 0 .../{example => auto-instrumentation}/server_uninstrumented.py | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename docs/examples/{example => auto-instrumentation}/README.md (100%) rename docs/examples/{example => auto-instrumentation}/client.py (100%) rename docs/examples/{example => auto-instrumentation}/server_instrumented.py (100%) rename docs/examples/{example => auto-instrumentation}/server_uninstrumented.py (100%) diff --git a/docs/examples/example/README.md b/docs/examples/auto-instrumentation/README.md similarity index 100% rename from docs/examples/example/README.md rename to docs/examples/auto-instrumentation/README.md diff --git a/docs/examples/example/client.py b/docs/examples/auto-instrumentation/client.py similarity index 100% rename from docs/examples/example/client.py rename to docs/examples/auto-instrumentation/client.py diff --git a/docs/examples/example/server_instrumented.py b/docs/examples/auto-instrumentation/server_instrumented.py similarity index 100% rename from docs/examples/example/server_instrumented.py rename to docs/examples/auto-instrumentation/server_instrumented.py diff --git a/docs/examples/example/server_uninstrumented.py b/docs/examples/auto-instrumentation/server_uninstrumented.py similarity index 100% rename from docs/examples/example/server_uninstrumented.py rename to docs/examples/auto-instrumentation/server_uninstrumented.py From 5bb20d15de7bf3ac7f70f6df728d32fb39eb3f72 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Mon, 30 Mar 2020 13:23:49 -0600 Subject: [PATCH 27/27] Shorten entry point --- ext/opentelemetry-ext-flask/setup.py | 2 +- .../auto_instrumentation/auto_instrumentation.py | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/ext/opentelemetry-ext-flask/setup.py b/ext/opentelemetry-ext-flask/setup.py index 18e8b85aa1d..84b33c23b22 100644 --- a/ext/opentelemetry-ext-flask/setup.py +++ b/ext/opentelemetry-ext-flask/setup.py @@ -26,7 +26,7 @@ setuptools.setup( version=PACKAGE_INFO["__version__"], entry_points={ - "opentelemetry_auto_instrumentation_instrumentor": [ + "opentelemetry_instrumentor": [ "flask = opentelemetry.ext.flask:FlaskInstrumentor" ] }, diff --git a/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/auto_instrumentation.py b/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/auto_instrumentation.py index 7aa831ec355..00ccf6a0ea9 100644 --- a/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/auto_instrumentation.py +++ b/opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/auto_instrumentation.py @@ -25,9 +25,7 @@ def run() -> None: - for entry_point in iter_entry_points( - "opentelemetry_auto_instrumentation_instrumentor" - ): + for entry_point in iter_entry_points("opentelemetry_instrumentor"): try: entry_point.load()().instrument() # type: ignore logger.debug("Instrumented %s", entry_point.name)