1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

[opentelemetry][callback] transform args attribute in a list of attributes with redacted user/pass in URL values (#3564)

* [callback][opentelemetry] list of attributes for arguments

* [opentelemetry][callback] list of attributes for the args and redact user/pass from http

* [opentelemetry][callback] remove unused imports

* [opentelemetry][callback] fix E713

* [opentelemetry][callback] remove unused static method

* [opentelemetry][callback] remove duplicated functions

* Apply suggestions from code review

Co-authored-by: Ajpantuso <ajpantuso@gmail.com>

* [opentelemetry][callback] fix ident

* [opentelemetry][callback] add changelog fragment

Co-authored-by: Ajpantuso <ajpantuso@gmail.com>
This commit is contained in:
Victor Martinez 2021-10-24 18:00:00 +01:00 committed by GitHub
parent 996dc617ed
commit 7e1412e5e1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 9 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- opentelemetry callback plugin - transformed args in a list of span attributes in addition it redacted username and password from any URLs (https://github.com/ansible-collections/community.general/pull/3564).

View file

@ -91,8 +91,6 @@ try:
from opentelemetry.trace.propagation.tracecontext import TraceContextTextMapPropagator from opentelemetry.trace.propagation.tracecontext import TraceContextTextMapPropagator
from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import ( from opentelemetry.sdk.trace.export import (
ConsoleSpanExporter,
SimpleSpanProcessor,
BatchSpanProcessor BatchSpanProcessor
) )
from opentelemetry.util._time import _time_ns from opentelemetry.util._time import _time_ns
@ -266,7 +264,11 @@ class OpenTelemetrySource(object):
status = Status(status_code=StatusCode.UNSET) status = Status(status_code=StatusCode.UNSET)
span.set_status(status) span.set_status(status)
self.set_span_attribute(span, "ansible.task.args", self.flat_args(task_data.args)) if isinstance(task_data.args, dict) and "gather_facts" not in task_data.action:
names = tuple(self.transform_ansible_unicode_to_str(k) for k in task_data.args.keys())
values = tuple(self.transform_ansible_unicode_to_str(k) for k in task_data.args.values())
self.set_span_attribute(span, ("ansible.task.args.name"), names)
self.set_span_attribute(span, ("ansible.task.args.value"), values)
self.set_span_attribute(span, "ansible.task.module", task_data.action) self.set_span_attribute(span, "ansible.task.module", task_data.action)
self.set_span_attribute(span, "ansible.task.message", message) self.set_span_attribute(span, "ansible.task.message", message)
self.set_span_attribute(span, "ansible.task.name", name) self.set_span_attribute(span, "ansible.task.name", name)
@ -325,6 +327,13 @@ class OpenTelemetrySource(object):
return "{{" not in url.hostname return "{{" not in url.hostname
return False return False
@staticmethod
def transform_ansible_unicode_to_str(value):
parsed_url = urlparse(str(value))
if OpenTelemetrySource.is_valid_url(parsed_url):
return OpenTelemetrySource.redact_user_password(parsed_url).geturl()
return str(value)
@staticmethod @staticmethod
def get_error_message(result): def get_error_message(result):
if result.get('exception') is not None: if result.get('exception') is not None:
@ -343,12 +352,6 @@ class OpenTelemetrySource(object):
stderr = result.get('stderr') stderr = result.get('stderr')
return ('message: "{0}"\nexception: "{1}"\nstderr: "{2}"').format(message, exception, stderr) return ('message: "{0}"\nexception: "{1}"\nstderr: "{2}"').format(message, exception, stderr)
@staticmethod
def flat_args(args):
if args:
return ', '.join(('%s=%s' % a for a in args.items()))
return None
class CallbackModule(CallbackBase): class CallbackModule(CallbackBase):
""" """