Default to adding idempotecy-key to audit-logs/events if not present, added in retryability logic to endpoints#492
Conversation
|
/review |
Greptile Summary
Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant AuditLogs
participant HTTPClient
participant API
User->>AuditLogs: "create_event(org_id, event)"
AuditLogs->>AuditLogs: "Generate idempotency key if not provided"
AuditLogs->>HTTPClient: "request with retry configuration"
loop Retry up to 3 times
HTTPClient->>API: "POST audit logs events"
alt Status 200
API-->>HTTPClient: "Response body"
HTTPClient-->>AuditLogs: "Return JSON"
else Status 408, 500, 502, or 504
API-->>HTTPClient: "Error response"
HTTPClient->>HTTPClient: "Wait with exponential backoff"
else Network or Timeout Error
HTTPClient->>HTTPClient: "Wait with exponential backoff"
end
end
AuditLogs->>AuditLogs: "Parse to AuditLogEventResponse"
AuditLogs-->>User: "Return response object"
|
nave91
left a comment
There was a problem hiding this comment.
The changes are perfect!
I found an issue before with this sdk: Can we return the response object when creating the audit log event? Especially for cases where schema validation fails for an event, the caller has no way of knowing that.
workos/audit_logs.py
Outdated
| headers["idempotency-key"] = idempotency_key | ||
|
|
||
| # Enable retries for audit log event creation with default retryConfig | ||
| self._http_client.request( |
There was a problem hiding this comment.
Can we return this response object back to the user?
I think we should also add some test cases when the schema validation fails.
There was a problem hiding this comment.
@nave91 updated to return the response back and added some validations
workos/audit_logs.py
Outdated
| headers["idempotency-key"] = idempotency_key | ||
| # Auto-generate UUID v4 if not provided | ||
| if idempotency_key is None: | ||
| idempotency_key = str(uuid.uuid4()) |
There was a problem hiding this comment.
Same question - should we prefix with a string so we can differentiate sdk generated key vs customer?
|
|
||
|
|
||
| @dataclass | ||
| class RetryConfig: |
There was a problem hiding this comment.
💯 for using dataclasses, this keeps the retry config abstracted away 👌
|
@greptile re-review please |
There was a problem hiding this comment.
7 files reviewed, no comments
Edit Code Review Agent Settings | Greptile
React with 👍 or 👎 to share your feedback on this new summary format
Description
Updating python library sdk to always generating an idempotencyKey if not present when POSTing audit-logs events.
Also updated to add retryability to endpoints. I set it up to not be enabled by default