-
Notifications
You must be signed in to change notification settings - Fork 22
Default to adding idempotecy-key to audit-logs/events if not present, added in retryability logic to endpoints #492
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
/review |
Greptile OverviewGreptile SummaryThis PR implements automatic retry logic with exponential backoff and idempotency key auto-generation for audit log events. Key Changes
Implementation Details
The implementation follows best practices for resilient HTTP clients and includes excellent test coverage. The cursor configuration files ( Confidence Score: 5/5
Important Files ChangedFile Analysis
Sequence DiagramsequenceDiagram
participant Client as SDK Client
participant AuditLogs as AuditLogs Module
participant HTTPClient as HTTP Client
participant Retry as Retry Logic
participant API as WorkOS API
Client->>AuditLogs: create_event(organization_id, event)
AuditLogs->>AuditLogs: Generate UUID v4 for idempotency key
AuditLogs->>HTTPClient: request(path, headers, retry_config)
loop Retry Loop (max 3 attempts)
HTTPClient->>API: POST /audit_logs/events
alt Success (2xx)
API-->>HTTPClient: 200 OK
HTTPClient-->>AuditLogs: Success
AuditLogs-->>Client: None
else Retryable Error (408, 500, 502, 504)
API-->>HTTPClient: Error Response
HTTPClient->>Retry: Check if retryable
Retry->>Retry: Calculate backoff delay
Retry->>Retry: Sleep with exponential backoff + jitter
HTTPClient->>API: Retry POST /audit_logs/events
else Network/Timeout Error
API--xHTTPClient: Connection Error
HTTPClient->>Retry: Check if retryable
Retry->>Retry: Calculate backoff delay
Retry->>Retry: Sleep with exponential backoff + jitter
HTTPClient->>API: Retry POST /audit_logs/events
else Non-Retryable Error (4xx except 408)
API-->>HTTPClient: 4xx Error
HTTPClient-->>AuditLogs: Raise Exception
AuditLogs-->>Client: Exception
end
end
Note over HTTPClient,API: Max retries exhausted
HTTPClient-->>AuditLogs: Raise Exception
AuditLogs-->>Client: Exception
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
11 files reviewed, no comments
nave91
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we return this response object back to the user?
I think we should also add some test cases when the schema validation fails.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯 for using dataclasses, this keeps the retry config abstracted away 👌
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