Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions quotientai/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def __init__(self, api_key: str):
self.token = None
self.token_expiry = 0
self.token_api_key = None
self._user = None
self._token_path = (
token_dir
/ ".quotient"
Expand Down
1 change: 1 addition & 0 deletions quotientai/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def __init__(self, api_key: str):
self.token = None
self.token_expiry = 0
self.token_api_key = None
self._user = None
self._token_path = (
token_dir
/ ".quotient"
Expand Down
10 changes: 10 additions & 0 deletions quotientai/resources/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ def authenticate(self):
A call to GET /auth/profile to initially authenticate the user.
"""
response = self._client._get("/auth/profile")

# Set the user_id if successful
if response and isinstance(response, dict) and 'user_id' in response:
self._client._user = response['user_id']

return response

class AsyncAuthResource:
Expand All @@ -25,6 +30,11 @@ def authenticate(self):
task = loop.create_task(self._client._get("/auth/profile"))
# Run the task to completion
result = loop.run_until_complete(task)

# Set the user_id if successful
if result and isinstance(result, dict) and 'user_id' in result:
self._client._user = result['user_id']

return result
finally:
loop.close()
Expand Down
12 changes: 12 additions & 0 deletions quotientai/tracing/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,17 @@ def _create_otlp_exporter(self, endpoint: str, headers: dict):
"""
return OTLPSpanExporter(endpoint=endpoint, headers=headers)


def _get_user(self):
"""
Get user_id from client.
Returns the user_id or None if not found.
"""
if hasattr(self._client, '_user'):
return self._client._user
return "None"


@functools.lru_cache()
def _setup_auto_collector(self, app_name: str, environment: str, instruments: Optional[tuple] = None, detections: Optional[str] = None):
"""
Expand All @@ -139,6 +150,7 @@ def _setup_auto_collector(self, app_name: str, environment: str, instruments: Op
resource_attributes = {
QuotientAttributes.app_name: app_name,
QuotientAttributes.environment: environment,
"quotient.user": self._get_user(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this QuotientAttributes.user?

Otherwise LGTM

}

if detections is not None:
Expand Down