mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-01-09 23:28:07 -05:00
feat(agent/telemetry): Distinguish between users
This allows us to get a much better sense of how many users actually experience issues, and how issue occurrence is distributed among users.
This commit is contained in:
@@ -25,6 +25,7 @@ from forge.sdk.model import (
|
||||
from forge.sdk.routes.agent_protocol import base_router
|
||||
from hypercorn.asyncio import serve as hypercorn_serve
|
||||
from hypercorn.config import Config as HypercornConfig
|
||||
from sentry_sdk import set_user
|
||||
|
||||
from autogpt.agent_factory.configurators import configure_agent_with_state
|
||||
from autogpt.agent_factory.generators import generate_agent_for_task
|
||||
@@ -121,6 +122,9 @@ class AgentProtocolServer:
|
||||
"""
|
||||
Create a task for the agent.
|
||||
"""
|
||||
if user_id := (task_request.additional_input or {}).get("user_id"):
|
||||
set_user({"id": user_id})
|
||||
|
||||
task = await self.db.create_task(
|
||||
input=task_request.input,
|
||||
additional_input=task_request.additional_input,
|
||||
@@ -180,6 +184,9 @@ class AgentProtocolServer:
|
||||
llm_provider=self._get_task_llm_provider(task),
|
||||
)
|
||||
|
||||
if user_id := (task.additional_input or {}).get("user_id"):
|
||||
set_user({"id": user_id})
|
||||
|
||||
# According to the Agent Protocol spec, the first execute_step request contains
|
||||
# the same task input as the parent create_task request.
|
||||
# To prevent this from interfering with the agent's process, we ignore the input
|
||||
|
||||
@@ -2,7 +2,7 @@ import os
|
||||
|
||||
import click
|
||||
|
||||
from .utils import env_file_exists, set_env_config_value
|
||||
from .utils import env_file_exists, get_git_user_email, set_env_config_value
|
||||
|
||||
|
||||
def setup_telemetry() -> None:
|
||||
@@ -38,3 +38,6 @@ def _setup_sentry() -> None:
|
||||
dsn="https://dc266f2f7a2381194d1c0fa36dff67d8@o4505260022104064.ingest.sentry.io/4506739844710400", # noqa
|
||||
environment=os.getenv("TELEMETRY_ENVIRONMENT"),
|
||||
)
|
||||
|
||||
# Allow Sentry to distinguish between users
|
||||
sentry_sdk.set_user({"email": get_git_user_email(), "ip_address": "{{auto}}"})
|
||||
|
||||
@@ -84,6 +84,14 @@ def get_current_git_branch() -> str:
|
||||
return ""
|
||||
|
||||
|
||||
def get_git_user_email() -> str:
|
||||
try:
|
||||
repo = Repo(search_parent_directories=True)
|
||||
return repo.config_reader().get_value("user", "email", default="")
|
||||
except InvalidGitRepositoryError:
|
||||
return ""
|
||||
|
||||
|
||||
def get_latest_bulletin() -> tuple[str, bool]:
|
||||
exists = os.path.exists("data/CURRENT_BULLETIN.md")
|
||||
current_bulletin = ""
|
||||
|
||||
Reference in New Issue
Block a user