Skip to content

Commit 1efdf66

Browse files
authored
Merge pull request #160 from AgentOps-AI/upgraded-telemetry
update telemetry with result and error
2 parents 4d5e9f7 + 3d6a646 commit 1efdf66

File tree

2 files changed

+62
-46
lines changed

2 files changed

+62
-46
lines changed

agentstack/main.py

Lines changed: 46 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
run_project,
1212
export_template,
1313
)
14-
from agentstack.telemetry import track_cli_command
15-
from agentstack.utils import get_version
14+
from agentstack.telemetry import track_cli_command, update_telemetry
15+
from agentstack.utils import get_version, term_color
1616
from agentstack import generation
1717
from agentstack.update import check_for_updates
1818

@@ -151,46 +151,54 @@ def main():
151151
print(f"AgentStack CLI version: {get_version()}")
152152
sys.exit(0)
153153

154-
track_cli_command(args.command)
154+
telemetry_id = track_cli_command(args.command, " ".join(sys.argv[1:]))
155155
check_for_updates(update_requested=args.command in ('update', 'u'))
156156

157157
# Handle commands
158-
if args.command in ["docs"]:
159-
webbrowser.open("https://docs.agentstack.sh/")
160-
elif args.command in ["quickstart"]:
161-
webbrowser.open("https://docs.agentstack.sh/quickstart")
162-
elif args.command in ["templates"]:
163-
webbrowser.open("https://docs.agentstack.sh/quickstart")
164-
elif args.command in ["init", "i"]:
165-
init_project_builder(args.slug_name, args.template, args.wizard)
166-
elif args.command in ["run", "r"]:
167-
run_project(command=args.function, debug=args.debug, cli_args=extra_args)
168-
elif args.command in ['generate', 'g']:
169-
if args.generate_command in ['agent', 'a']:
170-
if not args.llm:
171-
configure_default_model()
172-
generation.add_agent(args.name, args.role, args.goal, args.backstory, args.llm)
173-
elif args.generate_command in ['task', 't']:
174-
generation.add_task(args.name, args.description, args.expected_output, args.agent)
175-
else:
176-
generate_parser.print_help()
177-
elif args.command in ["tools", "t"]:
178-
if args.tools_command in ["list", "l"]:
179-
list_tools()
180-
elif args.tools_command in ["add", "a"]:
181-
agents = [args.agent] if args.agent else None
182-
agents = args.agents.split(",") if args.agents else agents
183-
add_tool(args.name, agents)
184-
elif args.tools_command in ["remove", "r"]:
185-
generation.remove_tool(args.name)
158+
try:
159+
if args.command in ["docs"]:
160+
webbrowser.open("https://docs.agentstack.sh/")
161+
elif args.command in ["quickstart"]:
162+
webbrowser.open("https://docs.agentstack.sh/quickstart")
163+
elif args.command in ["templates"]:
164+
webbrowser.open("https://docs.agentstack.sh/quickstart")
165+
elif args.command in ["init", "i"]:
166+
init_project_builder(args.slug_name, args.template, args.wizard)
167+
elif args.command in ["run", "r"]:
168+
run_project(command=args.function, debug=args.debug, cli_args=extra_args)
169+
elif args.command in ['generate', 'g']:
170+
if args.generate_command in ['agent', 'a']:
171+
if not args.llm:
172+
configure_default_model()
173+
generation.add_agent(args.name, args.role, args.goal, args.backstory, args.llm)
174+
elif args.generate_command in ['task', 't']:
175+
generation.add_task(args.name, args.description, args.expected_output, args.agent)
176+
else:
177+
generate_parser.print_help()
178+
elif args.command in ["tools", "t"]:
179+
if args.tools_command in ["list", "l"]:
180+
list_tools()
181+
elif args.tools_command in ["add", "a"]:
182+
agents = [args.agent] if args.agent else None
183+
agents = args.agents.split(",") if args.agents else agents
184+
add_tool(args.name, agents)
185+
elif args.tools_command in ["remove", "r"]:
186+
generation.remove_tool(args.name)
187+
else:
188+
tools_parser.print_help()
189+
elif args.command in ['export', 'e']:
190+
export_template(args.filename)
191+
elif args.command in ['update', 'u']:
192+
pass # Update check already done
186193
else:
187-
tools_parser.print_help()
188-
elif args.command in ['export', 'e']:
189-
export_template(args.filename)
190-
elif args.command in ['update', 'u']:
191-
pass # Update check already done
192-
else:
193-
parser.print_help()
194+
parser.print_help()
195+
except Exception as e:
196+
update_telemetry(telemetry_id, result=1, message=str(e))
197+
print(term_color("An error occurred while running your AgentStack command:", "red"))
198+
print(e)
199+
sys.exit(1)
200+
201+
update_telemetry(telemetry_id, result=0)
194202

195203

196204
if __name__ == "__main__":

agentstack/telemetry.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@
55
#
66
# i really hate to put this functionality in and was very
77
# resistant to it. as a human, i value privacy as a fundamental
8-
# human right. but i also value my time.
8+
# human right. but i also value what we're building.
99
#
10-
# i have been putting a lot of my time into building out
11-
# agentstack. i have strong conviction for what this project
12-
# can be. it's showing some great progress, but for me to justify
13-
# spending days and nights building this, i need to know that
14-
# people are actually using it and not just starring the repo
10+
# i have strong conviction for what AgentStack is and will be.
11+
# it's showing some great progress, but for us to know how to
12+
# build it best, i need to know if and how people are using it
1513
#
1614
# if you want to opt-out of telemetry, you can add the following
1715
# configuration to your agentstack.json file:
@@ -26,6 +24,7 @@
2624

2725
import platform
2826
import socket
27+
from typing import Optional
2928
import psutil
3029
import requests
3130
from agentstack import conf
@@ -53,6 +52,9 @@ def collect_machine_telemetry(command: str):
5352
else:
5453
telemetry_data['framework'] = "n/a"
5554

55+
if telemetry_data['framework'] is None:
56+
telemetry_data['framework'] = "n/a"
57+
5658
# Attempt to get general location based on public IP
5759
try:
5860
response = requests.get('https://ipinfo.io/json')
@@ -72,9 +74,15 @@ def collect_machine_telemetry(command: str):
7274
return telemetry_data
7375

7476

75-
def track_cli_command(command: str):
77+
def track_cli_command(command: str, args: Optional[str] = None):
7678
try:
7779
data = collect_machine_telemetry(command)
78-
requests.post(TELEMETRY_URL, json={"command": command, **data})
80+
return requests.post(TELEMETRY_URL, json={"command": command, "args":args, **data}).json().get('id')
7981
except Exception:
8082
pass
83+
84+
def update_telemetry(id: int, result: int, message: Optional[str] = None):
85+
try:
86+
requests.put(TELEMETRY_URL, json={"id": id, "result": result, "message": message})
87+
except Exception:
88+
pass

0 commit comments

Comments
 (0)