Skip to content

Commit

Permalink
Add OTEL trace instrument for signing (release-engineering#31)
Browse files Browse the repository at this point in the history
* Add OTEL trace instrument for signing

Also disallow type checks for tracing decorators since tracing
decorators and hookspecs from pubtools are untyped at the moment.
  • Loading branch information
zxiong authored Apr 3, 2024
1 parent ed20fcc commit ba2a013
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 1 deletion.
2 changes: 2 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -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
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
3 changes: 3 additions & 0 deletions src/pubtools/sign/clients/msg_recv_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")


Expand Down Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions src/pubtools/sign/clients/msg_send_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")


Expand Down Expand Up @@ -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(
Expand Down
5 changes: 5 additions & 0 deletions src/pubtools/sign/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit ba2a013

Please sign in to comment.