MCPcopy Create free account
hub / github.com/AgentOps-AI/agentops / get_jwt_token_sync

Function get_jwt_token_sync

agentops/validation.py:77–102  ·  view source on GitHub ↗

Synchronous wrapper for get_jwt_token - runs async function in event loop. Args: api_key: Optional API key. If not provided, uses AGENTOPS_API_KEY env var. Returns: JWT bearer token, or None if failed Note: This function never throws exceptions - all error

(api_key: Optional[str] = None)

Source from the content-addressed store, hash-verified

75
76
77def get_jwt_token_sync(api_key: Optional[str] = None) -> Optional[str]:
78 """
79 Synchronous wrapper for get_jwt_token - runs async function in event loop.
80
81 Args:
82 api_key: Optional API key. If not provided, uses AGENTOPS_API_KEY env var.
83
84 Returns:
85 JWT bearer token, or None if failed
86
87 Note:
88 This function never throws exceptions - all errors are handled gracefully
89 """
90 try:
91 import concurrent.futures
92
93 # Always run in a separate thread to avoid event loop issues
94 def run_in_thread():
95 return asyncio.run(get_jwt_token(api_key))
96
97 with concurrent.futures.ThreadPoolExecutor() as executor:
98 future = executor.submit(run_in_thread)
99 return future.result()
100 except Exception as e:
101 logger.warning(f"Failed to get JWT token synchronously: {e}")
102 return None
103
104
105def get_trace_details(trace_id: str, jwt_token: str) -> Dict[str, Any]:

Callers 4

validate_trace_spansFunction · 0.85

Calls

no outgoing calls

Tested by 3

Used in the wild real call sites across dependent graphs

searching dependent graphs…