summaryrefslogtreecommitdiff
path: root/zuul
diff options
context:
space:
mode:
authorSimon Westphahl <simon.westphahl@bmw.de>2022-09-26 12:35:47 +0200
committerSimon Westphahl <simon.westphahl@bmw.de>2022-09-30 09:50:37 +0200
commitc2063cebea39df42479a43e8c16dc745daf57b66 (patch)
tree94dda7c80e9bf7aca37fda896862c4d8a96535e6 /zuul
parent35b6016df3966fc4060a1298aabf2944a56a19f3 (diff)
downloadzuul-c2063cebea39df42479a43e8c16dc745daf57b66.tar.gz
Trace Gitlab connection events
Change-Id: I75e27fd0c2efd79f817318b5cae8d76c1483d744
Diffstat (limited to 'zuul')
-rw-r--r--zuul/driver/gitlab/gitlabconnection.py26
1 files changed, 21 insertions, 5 deletions
diff --git a/zuul/driver/gitlab/gitlabconnection.py b/zuul/driver/gitlab/gitlabconnection.py
index 71c5488a8..40cac241a 100644
--- a/zuul/driver/gitlab/gitlabconnection.py
+++ b/zuul/driver/gitlab/gitlabconnection.py
@@ -29,10 +29,13 @@ import dateutil.parser
from urllib.parse import quote_plus
from typing import List, Optional
+from opentelemetry import trace
+
from zuul.connection import (
BaseConnection, ZKChangeCacheMixin, ZKBranchCacheMixin
)
from zuul.web.handler import BaseWebController
+from zuul.lib import tracing
from zuul.lib.http import ZuulHTTPAdapter
from zuul.lib.logutil import get_annotated_logger
from zuul.lib.config import any_to_bool
@@ -65,6 +68,7 @@ class GitlabEventConnector(threading.Thread):
"""Move events from Gitlab into the scheduler"""
log = logging.getLogger("zuul.GitlabEventConnector")
+ tracer = trace.get_tracer("zuul")
def __init__(self, connection):
super(GitlabEventConnector, self).__init__()
@@ -106,10 +110,17 @@ class GitlabEventConnector(threading.Thread):
def _run(self):
while not self._stopped:
for event in self.event_queue:
- try:
- self._handleEvent(event)
- finally:
- self.event_queue.ack(event)
+ event_span = tracing.restoreSpanContext(
+ event.get("span_context"))
+ attributes = {"rel": "GitlabEvent"}
+ link = trace.Link(event_span.get_span_context(),
+ attributes=attributes)
+ with self.tracer.start_as_current_span(
+ "GitlabEventProcessing", links=[link]):
+ try:
+ self._handleEvent(event)
+ finally:
+ self.event_queue.ack(event)
if self._stopped:
return
self._process_event.wait(10)
@@ -763,6 +774,7 @@ class GitlabConnection(ZKChangeCacheMixin, ZKBranchCacheMixin, BaseConnection):
class GitlabWebController(BaseWebController):
log = logging.getLogger("zuul.GitlabWebController")
+ tracer = trace.get_tracer("zuul")
def __init__(self, zuul_web, connection):
self.connection = connection
@@ -789,6 +801,7 @@ class GitlabWebController(BaseWebController):
@cherrypy.expose
@cherrypy.tools.json_out(content_type='application/json; charset=utf-8')
+ @tracer.start_as_current_span("GitlabEvent")
def payload(self):
headers = dict()
for key, value in cherrypy.request.headers.items():
@@ -799,7 +812,10 @@ class GitlabWebController(BaseWebController):
self._validate_token(headers)
json_payload = json.loads(body.decode('utf-8'))
- data = {'payload': json_payload}
+ data = {
+ 'payload': json_payload,
+ 'span_context': tracing.getSpanContext(trace.get_current_span()),
+ }
self.event_queue.put(data)
return data