Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 2 additions & 0 deletions quotientai/_constants.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
TRACER_NAME = "quotient.sdk.python"
DEFAULT_TRACING_ENDPOINT = "https://otel.quotientai.co/v1/traces"
# DEFAULT_TRACING_ENDPOINT = "http://localhost:4318/v1/traces"
Copy link
Member

Choose a reason for hiding this comment

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

Cruft?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I lowkey wanted to keep it in here just for dev purposes. Ill remove it along w/ the other fixes

Copy link
Member

Choose a reason for hiding this comment

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

If you want to do that you could make this an env var.

Suggested change
# DEFAULT_TRACING_ENDPOINT = "http://localhost:4318/v1/traces"
OTLP_TRACING_ENDPOINT = os.environ.get(“OTLP_TRACING_ENDPOINT”, “https://otel.quotientai.co/v1/traces”)



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_id = 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_id = None
Copy link
Member

Choose a reason for hiding this comment

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

I suggest calling this self.__user

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_id = 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_id = 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_id(self):
"""
Get user_id from client.
Returns the user_id or None if not found.
"""
if hasattr(self._client, 'user_id'):
return self._client.user_id
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_id": self._get_user_id(),
Copy link
Member

Choose a reason for hiding this comment

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

Let's add this to QuotientAttributes as quotient.user

}

if detections is not None:
Expand Down