Upload a logfile to the V4 API. Args: body: The logfile content to upload trace_id: The trace ID associated with the logfile Returns: Dictionary containing upload response data Raises: ApiServerException: If the uplo
(self, body: Union[str, bytes], trace_id: str)
| 106 | raise ApiServerException(f"Failed to upload object: {e}") |
| 107 | |
| 108 | def upload_logfile(self, body: Union[str, bytes], trace_id: str) -> Dict[str, Any]: |
| 109 | """ |
| 110 | Upload a logfile to the V4 API. |
| 111 | |
| 112 | Args: |
| 113 | body: The logfile content to upload |
| 114 | trace_id: The trace ID associated with the logfile |
| 115 | |
| 116 | Returns: |
| 117 | Dictionary containing upload response data |
| 118 | |
| 119 | Raises: |
| 120 | ApiServerException: If the upload fails |
| 121 | """ |
| 122 | try: |
| 123 | # Convert bytes to string for consistency with test expectations |
| 124 | if isinstance(body, bytes): |
| 125 | body = body.decode("utf-8") |
| 126 | |
| 127 | headers = {**self.prepare_headers(), "Trace-Id": str(trace_id)} |
| 128 | response = self.post("/v4/logs/upload/", body, headers) |
| 129 | |
| 130 | if response.status_code != 200: |
| 131 | error_msg = f"Upload failed: {response.status_code}" |
| 132 | try: |
| 133 | error_data = response.json() |
| 134 | if "error" in error_data: |
| 135 | error_msg = error_data["error"] |
| 136 | except: |
| 137 | pass |
| 138 | raise ApiServerException(error_msg) |
| 139 | |
| 140 | try: |
| 141 | return response.json() |
| 142 | except Exception as e: |
| 143 | raise ApiServerException(f"Failed to process upload response: {str(e)}") |
| 144 | except requests.exceptions.RequestException as e: |
| 145 | raise ApiServerException(f"Failed to upload logfile: {e}") |