|
11 | 11 | from datetime import datetime |
12 | 12 | from tb.a.api import AsyncAPI as AsyncTinybird |
13 | 13 | from tb.api import API as Tinybird |
| 14 | +import logging |
14 | 15 |
|
15 | 16 |
|
16 | 17 | class CustomJSONEncoder(json.JSONEncoder): |
@@ -90,33 +91,44 @@ def __init__(self, *args, **kwargs): |
90 | 91 | super().__init__(*args, **kwargs) |
91 | 92 |
|
92 | 93 | def log_success_event(self, kwargs, response_obj, start_time, end_time): |
93 | | - data = self._extract_data(kwargs, response_obj, start_time, end_time) |
94 | | - self.api.send( |
95 | | - f"events?name={self.datasource_name}", |
96 | | - data=data |
97 | | - ) |
98 | | - |
| 94 | + try: |
| 95 | + data = self._extract_data(kwargs, response_obj, start_time, end_time) |
| 96 | + self.api.send( |
| 97 | + f"events?name={self.datasource_name}", |
| 98 | + data=data |
| 99 | + ) |
| 100 | + except Exception as e: |
| 101 | + logging.error(f"Error logging success event: {e}") |
99 | 102 | def log_failure_event(self, kwargs, response_obj, start_time, end_time): |
100 | | - data = self._extract_data(kwargs, response_obj, start_time, end_time) |
101 | | - self.api.send( |
102 | | - f"events?name={self.datasource_name}", |
103 | | - data=data |
104 | | - ) |
| 103 | + try: |
| 104 | + data = self._extract_data(kwargs, response_obj, start_time, end_time) |
| 105 | + self.api.send( |
| 106 | + f"events?name={self.datasource_name}", |
| 107 | + data=data |
| 108 | + ) |
| 109 | + except Exception as e: |
| 110 | + logging.error(f"Error logging failure event: {e}") |
105 | 111 |
|
106 | 112 | class TinybirdLitellmAsyncHandler(TinybirdLitellmHandler): |
107 | 113 | def __init__(self, *args, **kwargs): |
108 | 114 | super().__init__(*args, **kwargs) |
109 | 115 |
|
110 | 116 | async def async_log_success_event(self, kwargs, response_obj, start_time, end_time): |
111 | | - data = self._extract_data(kwargs, response_obj, start_time, end_time) |
112 | | - await self.async_api.send( |
113 | | - f"events?name={self.datasource_name}", |
114 | | - data=data |
115 | | - ) |
| 117 | + try: |
| 118 | + data = self._extract_data(kwargs, response_obj, start_time, end_time) |
| 119 | + await self.async_api.send( |
| 120 | + f"events?name={self.datasource_name}", |
| 121 | + data=data |
| 122 | + ) |
| 123 | + except Exception as e: |
| 124 | + logging.error(f"Error logging success event: {e}") |
116 | 125 |
|
117 | 126 | async def async_log_failure_event(self, kwargs, response_obj, start_time, end_time): |
118 | | - data = self._extract_data(kwargs, response_obj, start_time, end_time) |
119 | | - await self.async_api.send( |
120 | | - f"events?name={self.datasource_name}", |
121 | | - data=data |
122 | | - ) |
| 127 | + try: |
| 128 | + data = self._extract_data(kwargs, response_obj, start_time, end_time) |
| 129 | + await self.async_api.send( |
| 130 | + f"events?name={self.datasource_name}", |
| 131 | + data=data |
| 132 | + ) |
| 133 | + except Exception as e: |
| 134 | + logging.error(f"Error logging failure event: {e}") |
0 commit comments