Skip to content

Commit

Permalink
Add a trace for the workspace tree and test
Browse files Browse the repository at this point in the history
  • Loading branch information
rebkwok committed Mar 19, 2024
1 parent 2795f42 commit 6622fbd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
7 changes: 6 additions & 1 deletion airlock/views/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from django.urls import reverse
from django.views.decorators.http import require_http_methods
from django.views.decorators.vary import vary_on_headers
from opentelemetry import trace

from airlock.business_logic import RequestFileType, UrlPath, bll
from airlock.file_browser_api import get_workspace_tree
Expand All @@ -15,6 +16,9 @@
from .helpers import get_path_item_from_tree_or_404, get_workspace_or_raise, serve_file


tracer = trace.get_tracer_provider().get_tracer(__name__)


def grouped_workspaces(workspaces):
workspaces_by_project = defaultdict(list)
for workspace in workspaces:
Expand Down Expand Up @@ -43,7 +47,8 @@ def workspace_view(request, workspace_name: str, path: str = ""):
template = "file_browser/contents.html"
selected_only = True

tree = get_workspace_tree(workspace, path, selected_only)
with tracer.start_as_current_span("build_workspace_tree") as _span:
tree = get_workspace_tree(workspace, path, selected_only)

path_item = get_path_item_from_tree_or_404(tree, path)

Expand Down
7 changes: 7 additions & 0 deletions tests/integration/views/test_workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from airlock.business_logic import RequestFileType, UrlPath
from tests import factories
from tests.conftest import get_trace


pytestmark = pytest.mark.django_db
Expand All @@ -22,6 +23,12 @@ def test_workspace_view(airlock_client):
assert "file.txt" in response.rendered_content
assert "release-request-button" not in response.rendered_content

traces = get_trace()
# We have one trace in this view, for the workspace tree
assert len(traces) == 1
trace = traces[0]
assert trace.name == "build_workspace_tree"


def test_workspace_view_with_existing_request_for_user(airlock_client):
user = factories.create_user(output_checker=True)
Expand Down

0 comments on commit 6622fbd

Please sign in to comment.