Skip to content

feat: add configurable request logging - #359

Closed
jbeckwith-oai wants to merge 2 commits into
codex/request-response-logging-basefrom
codex/request-response-logging
Closed

feat: add configurable request logging#359
jbeckwith-oai wants to merge 2 commits into
codex/request-response-logging-basefrom
codex/request-response-logging

Conversation

@jbeckwith-oai

Copy link
Copy Markdown
Contributor

Summary

  • add opt-in request diagnostics through logger: and log_level: client options
  • support OPENAI_LOG with :off, :error, :warn, :info, and :debug levels
  • report retries, terminal errors, request IDs, attempt counts, and durations without changing request semantics
  • redact credentials and bound or omit sensitive body diagnostics
  • document the API and keep logger failures isolated from API results
client = OpenAI::Client.new(
  logger: Rails.logger,
  log_level: :info
)

Closes #306.

Stacking and API compatibility

This PR is intentionally stacked on #262 because both changes touch the core transport pipeline. Since #262 comes from a fork and GitHub cannot use its head as an upstream base, codex/request-response-logging-base is an exact mirror of #262 head commit 44c62911. The combined implementation routes ordinary and raw responses through the same logging lifecycle. This PR will be retargeted to main after #262 merges.

I reviewed the other open PRs. #293 also touches BaseClient, but introduces no competing public logging API; #347 and #358 overlap only generated release/docs surfaces. No open PR defines logger, log_level, or OPENAI_LOG.

Safety

  • logging is off by default
  • info/warn/error events exclude headers and bodies
  • debug output redacts credential-bearing headers, URL userinfo, sensitive query fields, and sensitive JSON fields
  • multipart, binary, oversized JSON, opaque payloads, and server-sent event contents are omitted
  • response streams are observed only as callers consume them
  • logger and log-formatting failures never replace API results or errors
  • log text is explicitly documented as diagnostic, not a stable structured-event API

Validation

  • thermo-nuclear code-quality review completed; integration and redaction findings addressed
  • Ruby 4.0.6: 588 runs, 3,066 assertions, 0 failures/errors
  • Ruby 3.3.12: 588 runs, 3,066 assertions, 0 failures/errors
  • repository lint: 2,611 files, 0 offenses
  • RBS: 1,216 files validated
  • Sorbet: no errors
  • gem build: successful

@jbeckwith-oai jbeckwith-oai added the generator Touches generated SDK files label Aug 11, 2026

@HAYDEN-OAI HAYDEN-OAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found three substantive logging correctness/redaction issues inline.

Comment thread lib/openai/internal/logging.rb Outdated
Comment thread lib/openai/internal/transport/base_client.rb Outdated
Comment thread lib/openai/internal/logging.rb Outdated
@jbeckwith-oai

Copy link
Copy Markdown
Contributor Author

Closing this draft because the response metadata, logging, and timeout work is being rebuilt together as one clean PR from current main. This avoids retaining the temporary stacked base and fragmented transport design.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

generator Touches generated SDK files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants