diff --git a/mypy.ini b/mypy.ini index 2dbf2be..8c461e4 100644 --- a/mypy.ini +++ b/mypy.ini @@ -1,4 +1,6 @@ [mypy] ignore_missing_imports = True disallow_subclassing_any = False +# Tracing decorators and hookspecs are untyped, this should be removed once the typing has been added +disallow_untyped_decorators = False strict = True diff --git a/pyproject.toml b/pyproject.toml index c68bfe0..a47f898 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -43,7 +43,11 @@ dependencies = [ "marshmallow", "pyOpenSSL", "typing_extensions", - "ansible-core" + "ansible-core", + "pubtools>=1.4.0", + "opentelemetry-api==1.20.0", + "opentelemetry-sdk==1.20.0", + "opentelemetry-exporter-otlp==1.20.0" ] [tool.setuptools.packages.find] diff --git a/src/pubtools/sign/clients/msg_recv_client.py b/src/pubtools/sign/clients/msg_recv_client.py index 4b428cc..f1e7670 100644 --- a/src/pubtools/sign/clients/msg_recv_client.py +++ b/src/pubtools/sign/clients/msg_recv_client.py @@ -11,7 +11,9 @@ import proton.utils from proton.reactor import Container +from pubtools.tracing import get_trace_wrapper +tw = get_trace_wrapper() LOG = logging.getLogger("pubtools.sign.client.msg_recv_client") @@ -51,6 +53,7 @@ def on_start(self, event: proton.Event) -> None: self.receiver = event.container.create_receiver(self.conn, self.topic) self.timer_task = event.container.schedule(self.timeout, self) + @tw.instrument_func() def on_message(self, event: proton.Event) -> None: LOG.debug("RECEIVER: On message (%s)", event) outer_message = json.loads(event.message.body) diff --git a/src/pubtools/sign/clients/msg_send_client.py b/src/pubtools/sign/clients/msg_send_client.py index 136a9cb..f16e89e 100644 --- a/src/pubtools/sign/clients/msg_send_client.py +++ b/src/pubtools/sign/clients/msg_send_client.py @@ -10,6 +10,12 @@ import proton.utils from proton.reactor import Container +from pubtools.tracing import get_trace_wrapper + +from opentelemetry.trace.propagation.tracecontext import TraceContextTextMapPropagator + +tw = get_trace_wrapper() +propagator = TraceContextTextMapPropagator() LOG = logging.getLogger("pubtools.sign.signers.radas") @@ -41,10 +47,13 @@ def on_start(self, event: proton.Event) -> None: ) self.sender = event.container.create_sender(conn) + @tw.instrument_func() def on_sendable(self, event: proton.Event) -> None: LOG.debug("Sender on_sendable") if self.sent < self.total: message = self.messages[self.sent] + # Inject trace context to message properties + propagator.inject(carrier=message.headers) LOG.debug("Sending message: %s %s %s", message.body, message.address, message.headers) event.sender.send( proton.Message( diff --git a/src/pubtools/sign/utils.py b/src/pubtools/sign/utils.py index 839e376..da63bb3 100644 --- a/src/pubtools/sign/utils.py +++ b/src/pubtools/sign/utils.py @@ -6,6 +6,10 @@ from .conf.conf import CONFIG_PATHS +from pubtools.tracing import get_trace_wrapper + +tw = get_trace_wrapper() + def set_log_level(logger: logging.Logger, level: str) -> None: """Set log level for provided logger. @@ -42,6 +46,7 @@ def isodate_now() -> str: return datetime.datetime.utcnow().isoformat() + "Z" +@tw.instrument_func(args_to_attr=True) def run_command(cmd: List[str], env: Union[Dict[str, Any], None] = None) -> Any: """Run external command and return Process instance.""" process = subprocess.Popen(