-
Notifications
You must be signed in to change notification settings - Fork 132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix TLS support after tracing feature #1370
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
import inspect | ||
import sys | ||
from functools import wraps | ||
from pynipap import AuthOptions | ||
|
||
if sys.version_info[0] < 3: | ||
import xmlrpclib | ||
|
@@ -45,6 +44,7 @@ def decorated(*args, **kwargs): | |
""" | ||
""" | ||
|
||
from pynipap import AuthOptions | ||
signature = inspect.signature(f) | ||
|
||
if args[0].__class__ == type: | ||
|
@@ -103,6 +103,39 @@ def send_content(self, connection, request_body): | |
current_span.get_span_context().span_id)[2:].zfill(16) + "-01") | ||
|
||
super().send_content(connection, request_body) | ||
|
||
|
||
class TracingXMLSafeTransport(xmlrpclib.SafeTransport): | ||
|
||
def __init__(self, use_datetime=False, use_builtin_types=False, | ||
*, headers=(), context=None): | ||
super().__init__(use_datetime=use_datetime, | ||
use_builtin_types=use_builtin_types, | ||
headers=headers, context=context) | ||
|
||
def request(self, host, handler, request_body, verbose=False): | ||
with tracer.start_as_current_span("POST XML request", context.get_current(), SpanKind.CLIENT): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. line too long (106 > 79 characters) |
||
current_span = trace.get_current_span() | ||
try: | ||
result = super().request(host, handler, request_body, verbose) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. line too long (82 > 79 characters) |
||
current_span.set_attribute("http.status_code", 200) | ||
except xmlrpclib.ProtocolError as protocolError: | ||
current_span.set_attribute("http.status_code", protocolError.errcode) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. line too long (89 > 79 characters) |
||
current_span.record_exception(protocolError) | ||
raise protocolError | ||
return result | ||
|
||
def send_content(self, connection, request_body): | ||
current_span = trace.get_current_span() | ||
if current_span != INVALID_SPAN: | ||
current_span.set_attribute("net.peer.ip", connection.host) | ||
current_span.set_attribute("net.peer.port", connection.port) | ||
current_span.set_attribute("net.peer.transport", "ip_tcp") | ||
connection.putheader("traceparent", "00-" + hex(current_span.get_span_context().trace_id)[2:].zfill(32) + "-" + hex( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. line too long (132 > 79 characters) |
||
current_span.get_span_context().span_id)[2:].zfill(16) + "-01") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. line too long (83 > 79 characters) |
||
|
||
super().send_content(connection, request_body) | ||
|
||
except ImportError: | ||
def create_span(f): | ||
@wraps(f) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
too many blank lines (2)