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)
| 75 | |
| 76 | |
| 77 | def 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 | |
| 105 | def get_trace_details(trace_id: str, jwt_token: str) -> Dict[str, Any]: |
no outgoing calls
searching dependent graphs…