Merge pull request #121 from NathanielRN/move-instrumentation-tornado

Move instrumentation tornado
This commit is contained in:
alrex
2020-11-02 13:26:02 -08:00
committed by GitHub
4 changed files with 12 additions and 18 deletions

View File

@ -39,13 +39,13 @@ package_dir=
packages=find_namespace:
install_requires =
tornado >= 6.0
opentelemetry-instrumentation == 0.15.dev0
opentelemetry-api == 0.15.dev0
opentelemetry-instrumentation == 0.15b0
opentelemetry-api == 0.15b0
[options.extras_require]
test =
tornado >= 6.0
opentelemetry-test == 0.15.dev0
opentelemetry-test == 0.15b0
[options.packages.find]
where = src

View File

@ -51,9 +51,10 @@ from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
from opentelemetry.instrumentation.tornado.version import __version__
from opentelemetry.instrumentation.utils import (
extract_attributes_from_object,
http_status_to_canonical_code,
http_status_to_status_code,
unwrap,
)
from opentelemetry.trace.propagation.textmap import DictGetter
from opentelemetry.trace.status import Status
from opentelemetry.util import ExcludeList, time_ns
@ -84,6 +85,8 @@ def get_traced_request_attrs():
_excluded_urls = get_excluded_urls()
_traced_attrs = get_traced_request_attrs()
carrier_getter = DictGetter()
class TornadoInstrumentor(BaseInstrumentor):
patched_handlers = []
@ -185,13 +188,6 @@ def _log_exception(tracer, func, handler, args, kwargs):
return func(*args, **kwargs)
def _get_header_from_request_headers(
headers: dict, header_name: str
) -> typing.List[str]:
header = headers.get(header_name)
return [header] if header else []
def _get_attributes_from_request(request):
attrs = {
"component": "tornado",
@ -218,9 +214,7 @@ def _get_operation_name(handler, request):
def _start_span(tracer, handler, start_time) -> _TraceContext:
token = context.attach(
propagators.extract(
_get_header_from_request_headers, handler.request.headers,
)
propagators.extract(carrier_getter, handler.request.headers,)
)
span = tracer.start_span(
@ -269,7 +263,7 @@ def _finish_span(tracer, handler, error=None):
ctx.span.set_attribute("http.status_code", status_code)
ctx.span.set_status(
Status(
canonical_code=http_status_to_canonical_code(status_code),
status_code=http_status_to_status_code(status_code),
description=reason,
)
)

View File

@ -3,7 +3,7 @@ import functools
from tornado.httpclient import HTTPError, HTTPRequest
from opentelemetry import propagators, trace
from opentelemetry.instrumentation.utils import http_status_to_canonical_code
from opentelemetry.instrumentation.utils import http_status_to_status_code
from opentelemetry.trace.status import Status
from opentelemetry.util import time_ns
@ -74,7 +74,7 @@ def _finish_tracing_callback(future, span):
span.set_attribute("http.status_code", status_code)
span.set_status(
Status(
canonical_code=http_status_to_canonical_code(status_code),
status_code=http_status_to_status_code(status_code),
description=description,
)
)

View File

@ -12,4 +12,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.
__version__ = "0.15.dev0"
__version__ = "0.15b0"