mirror of
https://github.com/Pythagora-io/gpt-pilot.git
synced 2026-01-09 13:17:55 -05:00
Improved Sentry integration
This commit is contained in:
@@ -5,6 +5,14 @@ import sys
|
|||||||
from argparse import Namespace
|
from argparse import Namespace
|
||||||
from asyncio import run
|
from asyncio import run
|
||||||
|
|
||||||
|
try:
|
||||||
|
import sentry_sdk
|
||||||
|
from sentry_sdk.integrations.asyncio import AsyncioIntegration
|
||||||
|
|
||||||
|
SENTRY_AVAILABLE = True
|
||||||
|
except ImportError:
|
||||||
|
SENTRY_AVAILABLE = False
|
||||||
|
|
||||||
from core.agents.orchestrator import Orchestrator
|
from core.agents.orchestrator import Orchestrator
|
||||||
from core.cli.helpers import delete_project, init, list_projects, list_projects_json, load_project, show_config
|
from core.cli.helpers import delete_project, init, list_projects, list_projects_json, load_project, show_config
|
||||||
from core.config import LLMProvider, get_config
|
from core.config import LLMProvider, get_config
|
||||||
@@ -23,6 +31,21 @@ log = get_logger(__name__)
|
|||||||
telemetry_sent = False
|
telemetry_sent = False
|
||||||
|
|
||||||
|
|
||||||
|
def init_sentry():
|
||||||
|
if SENTRY_AVAILABLE:
|
||||||
|
sentry_sdk.init(
|
||||||
|
dsn="https://4101633bc5560bae67d6eab013ba9686@o4508731634221056.ingest.us.sentry.io/4508732401909760",
|
||||||
|
send_default_pii=True,
|
||||||
|
traces_sample_rate=1.0,
|
||||||
|
integrations=[AsyncioIntegration()],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def capture_exception(err):
|
||||||
|
if SENTRY_AVAILABLE:
|
||||||
|
sentry_sdk.capture_exception(err)
|
||||||
|
|
||||||
|
|
||||||
async def cleanup(ui: UIBase):
|
async def cleanup(ui: UIBase):
|
||||||
global telemetry_sent
|
global telemetry_sent
|
||||||
if not telemetry_sent:
|
if not telemetry_sent:
|
||||||
@@ -62,6 +85,8 @@ async def run_project(sm: StateManager, ui: UIBase, args) -> bool:
|
|||||||
await sm.rollback()
|
await sm.rollback()
|
||||||
except APIError as err:
|
except APIError as err:
|
||||||
log.warning(f"LLM API error occurred: {err.message}")
|
log.warning(f"LLM API error occurred: {err.message}")
|
||||||
|
init_sentry()
|
||||||
|
capture_exception(err)
|
||||||
await ui.send_message(
|
await ui.send_message(
|
||||||
f"Stopping Pythagora due to an error while calling the LLM API: {err.message}",
|
f"Stopping Pythagora due to an error while calling the LLM API: {err.message}",
|
||||||
source=pythagora_source,
|
source=pythagora_source,
|
||||||
@@ -70,6 +95,8 @@ async def run_project(sm: StateManager, ui: UIBase, args) -> bool:
|
|||||||
await sm.rollback()
|
await sm.rollback()
|
||||||
except CustomAssertionError as err:
|
except CustomAssertionError as err:
|
||||||
log.warning(f"Anthropic assertion error occurred: {str(err)}")
|
log.warning(f"Anthropic assertion error occurred: {str(err)}")
|
||||||
|
init_sentry()
|
||||||
|
capture_exception(err)
|
||||||
await ui.send_message(
|
await ui.send_message(
|
||||||
f"Stopping Pythagora due to an error inside Anthropic SDK. {str(err)}",
|
f"Stopping Pythagora due to an error inside Anthropic SDK. {str(err)}",
|
||||||
source=pythagora_source,
|
source=pythagora_source,
|
||||||
@@ -78,6 +105,9 @@ async def run_project(sm: StateManager, ui: UIBase, args) -> bool:
|
|||||||
await sm.rollback()
|
await sm.rollback()
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
log.error(f"Uncaught exception: {err}", exc_info=True)
|
log.error(f"Uncaught exception: {err}", exc_info=True)
|
||||||
|
init_sentry()
|
||||||
|
capture_exception(err)
|
||||||
|
|
||||||
stack_trace = telemetry.record_crash(err)
|
stack_trace = telemetry.record_crash(err)
|
||||||
await sm.rollback()
|
await sm.rollback()
|
||||||
await ui.send_message(
|
await ui.send_message(
|
||||||
@@ -278,6 +308,9 @@ async def async_main(
|
|||||||
|
|
||||||
telemetry.set("user_contact", args.email)
|
telemetry.set("user_contact", args.email)
|
||||||
|
|
||||||
|
if SENTRY_AVAILABLE and args.email:
|
||||||
|
sentry_sdk.set_user({"email": args.email})
|
||||||
|
|
||||||
if args.extension_version:
|
if args.extension_version:
|
||||||
telemetry.set("is_extension", True)
|
telemetry.set("is_extension", True)
|
||||||
telemetry.set("extension_version", args.extension_version)
|
telemetry.set("extension_version", args.extension_version)
|
||||||
@@ -317,6 +350,11 @@ async def async_main(
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
success = await run_pythagora_session(sm, ui, args)
|
success = await run_pythagora_session(sm, ui, args)
|
||||||
|
except Exception as err:
|
||||||
|
log.error(f"Uncaught exception in main session: {err}", exc_info=True)
|
||||||
|
init_sentry()
|
||||||
|
capture_exception(err)
|
||||||
|
raise
|
||||||
finally:
|
finally:
|
||||||
await cleanup(ui)
|
await cleanup(ui)
|
||||||
|
|
||||||
|
|||||||
15
main.py
15
main.py
@@ -2,21 +2,6 @@
|
|||||||
import os.path
|
import os.path
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
try:
|
|
||||||
import sentry_sdk
|
|
||||||
from sentry_sdk.integrations.asyncio import AsyncioIntegration
|
|
||||||
|
|
||||||
sentry_sdk.init(
|
|
||||||
dsn="https://4101633bc5560bae67d6eab013ba9686@o4508731634221056.ingest.us.sentry.io/4508732401909760",
|
|
||||||
send_default_pii=True,
|
|
||||||
traces_sample_rate=1.0,
|
|
||||||
integrations=[AsyncioIntegration()],
|
|
||||||
)
|
|
||||||
|
|
||||||
sentry_sdk.profiler.start_profiler()
|
|
||||||
except ImportError:
|
|
||||||
SENTRY_ENABLED = False
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from core.cli.main import run_pythagora
|
from core.cli.main import run_pythagora
|
||||||
except ImportError as err:
|
except ImportError as err:
|
||||||
|
|||||||
Reference in New Issue
Block a user