mirror of
https://github.com/open-telemetry/opentelemetry-python-contrib.git
synced 2025-07-31 14:11:50 +08:00
Merge branch 'core-instrumentation-tornado-v0.15b0'
This commit is contained in:
@ -39,13 +39,13 @@ package_dir=
|
|||||||
packages=find_namespace:
|
packages=find_namespace:
|
||||||
install_requires =
|
install_requires =
|
||||||
tornado >= 6.0
|
tornado >= 6.0
|
||||||
opentelemetry-instrumentation == 0.15.dev0
|
opentelemetry-instrumentation == 0.15b0
|
||||||
opentelemetry-api == 0.15.dev0
|
opentelemetry-api == 0.15b0
|
||||||
|
|
||||||
[options.extras_require]
|
[options.extras_require]
|
||||||
test =
|
test =
|
||||||
tornado >= 6.0
|
tornado >= 6.0
|
||||||
opentelemetry-test == 0.15.dev0
|
opentelemetry-test == 0.15b0
|
||||||
|
|
||||||
[options.packages.find]
|
[options.packages.find]
|
||||||
where = src
|
where = src
|
||||||
|
@ -51,9 +51,10 @@ from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
|
|||||||
from opentelemetry.instrumentation.tornado.version import __version__
|
from opentelemetry.instrumentation.tornado.version import __version__
|
||||||
from opentelemetry.instrumentation.utils import (
|
from opentelemetry.instrumentation.utils import (
|
||||||
extract_attributes_from_object,
|
extract_attributes_from_object,
|
||||||
http_status_to_canonical_code,
|
http_status_to_status_code,
|
||||||
unwrap,
|
unwrap,
|
||||||
)
|
)
|
||||||
|
from opentelemetry.trace.propagation.textmap import DictGetter
|
||||||
from opentelemetry.trace.status import Status
|
from opentelemetry.trace.status import Status
|
||||||
from opentelemetry.util import ExcludeList, time_ns
|
from opentelemetry.util import ExcludeList, time_ns
|
||||||
|
|
||||||
@ -84,6 +85,8 @@ def get_traced_request_attrs():
|
|||||||
_excluded_urls = get_excluded_urls()
|
_excluded_urls = get_excluded_urls()
|
||||||
_traced_attrs = get_traced_request_attrs()
|
_traced_attrs = get_traced_request_attrs()
|
||||||
|
|
||||||
|
carrier_getter = DictGetter()
|
||||||
|
|
||||||
|
|
||||||
class TornadoInstrumentor(BaseInstrumentor):
|
class TornadoInstrumentor(BaseInstrumentor):
|
||||||
patched_handlers = []
|
patched_handlers = []
|
||||||
@ -185,13 +188,6 @@ def _log_exception(tracer, func, handler, args, kwargs):
|
|||||||
return func(*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):
|
def _get_attributes_from_request(request):
|
||||||
attrs = {
|
attrs = {
|
||||||
"component": "tornado",
|
"component": "tornado",
|
||||||
@ -218,9 +214,7 @@ def _get_operation_name(handler, request):
|
|||||||
|
|
||||||
def _start_span(tracer, handler, start_time) -> _TraceContext:
|
def _start_span(tracer, handler, start_time) -> _TraceContext:
|
||||||
token = context.attach(
|
token = context.attach(
|
||||||
propagators.extract(
|
propagators.extract(carrier_getter, handler.request.headers,)
|
||||||
_get_header_from_request_headers, handler.request.headers,
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
span = tracer.start_span(
|
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_attribute("http.status_code", status_code)
|
||||||
ctx.span.set_status(
|
ctx.span.set_status(
|
||||||
Status(
|
Status(
|
||||||
canonical_code=http_status_to_canonical_code(status_code),
|
status_code=http_status_to_status_code(status_code),
|
||||||
description=reason,
|
description=reason,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -3,7 +3,7 @@ import functools
|
|||||||
from tornado.httpclient import HTTPError, HTTPRequest
|
from tornado.httpclient import HTTPError, HTTPRequest
|
||||||
|
|
||||||
from opentelemetry import propagators, trace
|
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.trace.status import Status
|
||||||
from opentelemetry.util import time_ns
|
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_attribute("http.status_code", status_code)
|
||||||
span.set_status(
|
span.set_status(
|
||||||
Status(
|
Status(
|
||||||
canonical_code=http_status_to_canonical_code(status_code),
|
status_code=http_status_to_status_code(status_code),
|
||||||
description=description,
|
description=description,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -12,4 +12,4 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
__version__ = "0.15.dev0"
|
__version__ = "0.15b0"
|
||||||
|
Reference in New Issue
Block a user