Skip to content

Commit 2371239

Browse files
committed
Add user agent to all requests
1 parent 420e73f commit 2371239

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

src/blueapi/client/rest.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939

4040
LOGGER = logging.getLogger(__name__)
4141

42+
USER_AGENT = f"blueapi cli {__version__}"
43+
4244

4345
class UnauthorisedAccessError(Exception):
4446
pass
@@ -277,14 +279,15 @@ def _request_and_deserialize(
277279
) -> T:
278280
url = self._config.url.unicode_string().removesuffix("/") + suffix
279281
# Get the trace context to propagate to the REST API
280-
carr = get_context_propagator()
282+
headers = get_context_propagator()
283+
headers["User-Agent"] = USER_AGENT
281284
try:
282285
response = self._pool.request(
283286
method,
284287
url,
285288
json=data,
286289
params=params,
287-
headers=carr,
290+
headers=headers,
288291
auth=JWTAuth(self._session_manager),
289292
)
290293
except requests.exceptions.ConnectionError as ce:
@@ -312,14 +315,14 @@ def _request_and_deserialize(
312315

313316
def run_blocking(self, req: TaskRequest):
314317
url = self._ws_address().unicode_string().removesuffix("/") + "/run_plan"
315-
headers = {}
318+
headers = get_context_propagator()
316319
if self._session_manager:
317320
auth = self._session_manager.get_valid_access_token()
318321
headers["Authorization"] = f"Bearer {auth}"
319322
with connect(
320323
url,
321324
additional_headers=headers,
322-
user_agent_header="blueapi cli",
325+
user_agent_header=USER_AGENT,
323326
) as ws:
324327
ws.send(req.model_dump_json())
325328
for message in ws:

0 commit comments

Comments
 (0)