File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import logging
2+ import pytest
3+ import time
4+ import uuid
5+ from urllib .parse import urlparse
6+ import requests
7+
8+ @pytest .fixture
9+ def tracing_endpoint (request ):
10+ endpoint = request .config .getoption ("--tracing-endpoint" )
11+ if endpoint is None :
12+ pytest .exit ("Missing required option: --tracing-endpoint" )
13+ return endpoint
14+
15+ def locate_span (data , operation , tag ):
16+ if not data :
17+ return None
18+
19+ for spans in data :
20+ for span in spans :
21+ if span .get ('name' ) == operation :
22+ if span .get ('tags' , {}).get ('test.tag' ) == tag :
23+ return span
24+
25+ def test_tracing (tracing_endpoint , host ):
26+ operation = "xe observer-list"
27+ url = urlparse (tracing_endpoint )
28+ api = f"{ url .scheme } ://{ url .netloc } /api/v2/traces"
29+ tag = str (uuid .uuid4 ())
30+ logging .info (f"Peforming operation tagged with: { tag } " )
31+ o = host .ssh (f'BAGGAGE="test.tag={ tag } " { operation } ' )
32+ params = { "spanName" : operation }
33+
34+ logging .info (f"Querying endpoint to locate our root span" )
35+ root_span = None
36+ for i in range (15 ):
37+ response = requests .get (api , params = params )
38+ data = response .json ()
39+ root_span = locate_span (data , operation , tag )
40+ if root_span :
41+ break
42+ time .sleep (5 )
43+
44+ if not root_span :
45+ pytest .fail ("Could not find our operation's span in time" )
You can’t perform that action at this time.
0 commit comments