diff --git a/pungi/otel.py b/pungi/otel.py index ec8e4b97..1f2d7d08 100644 --- a/pungi/otel.py +++ b/pungi/otel.py @@ -31,6 +31,9 @@ class DummyTracing: def set_context(self, traceparent): pass + def record_exception(self, exc, set_error_status=True): + pass + class OtelTracing: """This class implements the actual integration with opentelemetry.""" @@ -114,6 +117,17 @@ class OtelTracing: ) context.attach(ctx) + def record_exception(self, exc, set_error_status=True): + """Records an exception for the current span and optionally marks the + span as failed.""" + from opentelemetry import trace + + span = trace.get_current_span() + span.record_exception(exc) + + if set_error_status: + span.set_status(trace.status.StatusCode.ERROR) + class InstrumentedClientSession: """Wrapper around koji.ClientSession that creates spans for each API call. diff --git a/pungi/scripts/pungi_koji.py b/pungi/scripts/pungi_koji.py index 06fec254..f2fb772c 100644 --- a/pungi/scripts/pungi_koji.py +++ b/pungi/scripts/pungi_koji.py @@ -657,6 +657,7 @@ def cli_main(): try: main() except (Exception, KeyboardInterrupt) as ex: + tracing.record_exception(ex) if COMPOSE: COMPOSE.log_error("Compose run failed: %s" % ex) COMPOSE.traceback(show_locals=getattr(ex, "show_locals", True))