-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathheaders.py
More file actions
49 lines (34 loc) · 1.41 KB
/
headers.py
File metadata and controls
49 lines (34 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import platform
from typing import Optional
from uuid import uuid4
from cycode import __version__
from cycode.cli import consts
from cycode.cli.user_settings.configuration_manager import ConfigurationManager
from cycode.cli.utils.sentry import add_correlation_id_to_scope
from cycode.cyclient.logger import logger
def get_cli_user_agent() -> str:
"""Return base User-Agent of CLI.
Example: CycodeCLI/0.2.3 (OS: Darwin; Arch: arm64; Python: 3.8.16; InstallID: *uuid4*)
"""
version = __version__
os = platform.system()
arch = platform.machine()
python_version = platform.python_version()
install_id = ConfigurationManager().get_or_create_installation_id()
return f'{consts.APP_NAME}/{version} (OS: {os}; Arch: {arch}; Python: {python_version}; InstallID: {install_id})'
class _CorrelationId:
_id: Optional[str] = None
def get_correlation_id(self) -> str:
"""Get correlation ID.
Notes:
Used across all requests to correlate logs and metrics.
It doesn't depend on client instances.
Lifetime is the same as the process.
"""
if self._id is None:
# example: 16fd2706-8baf-433b-82eb-8c7fada847da
self._id = str(uuid4())
logger.debug('Correlation ID: %s', self._id)
add_correlation_id_to_scope(self._id)
return self._id
get_correlation_id = _CorrelationId().get_correlation_id