Skip to content

feat: endpoint type log - #2038

Merged
seefs001 merged 4 commits into
QuantumNous:mainfrom
seefs001:feature/endpoint_type_log
Oct 14, 2025
Merged

feat: endpoint type log#2038
seefs001 merged 4 commits into
QuantumNous:mainfrom
seefs001:feature/endpoint_type_log

Conversation

@seefs001

@seefs001 seefs001 commented Oct 13, 2025

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features

    • Usage logs now display the request path for applicable entries, improving traceability.
    • Added multilingual support for the “Request path” label in the UI.
  • Documentation

    • Updated translations for the new “Request path” label in English, French, Russian, and Chinese.

@coderabbitai

coderabbitai Bot commented Oct 13, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

Adds request_path logging to error and quota logs; refactors RelayInfo generation with centralized construction and stricter type checks; changes GenerateMjOtherInfo to accept RelayInfo and updates callers; updates frontend logs to display request_path with new i18n entries.

Changes

Cohort / File(s) Summary
Error/Quota log augmentation
controller/relay.go, relay/relay_task.go
Append request_path to logged metadata when available from HTTP request.
RelayInfo construction refactor
relay/common/relay_info.go
Centralizes GenRelayInfo return path via local variable; adds explicit type-assertion errors for Rerank and OpenAIResponses; sets RelayFormat consistently.
MJ other-info generation API change
service/log_info_generate.go, relay/mjproxy_handler.go
GenerateMjOtherInfo now takes *RelayInfo plus price data; callers updated to pass RelayInfo; new helper adds request_path from context or RelayInfo.
Frontend logs + i18n
web/src/hooks/usage-logs/useUsageLogsData.jsx, web/src/i18n/locales/en.json, .../fr.json, .../ru.json, .../zh.json
UI shows request_path in type 2 logs when available; adds translations for “请求路径”.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Client
  participant Controller as Controller (relay)
  participant RelayInfo as RelayInfo Builder
  participant Service as Service.LogInfo
  participant MJ as MJ Proxy Handler
  participant UI as Web UI

  Client->>Controller: Incoming request
  Controller->>RelayInfo: GenRelayInfo(request)
  RelayInfo-->>Controller: RelayInfo (with RequestURLPath)

  Controller->>Service: appendRequestPath(ctx, RelayInfo) [internal]
  note right of Service: Augments metadata with request_path

  Controller->>MJ: GenerateMjOtherInfo(RelayInfo, priceData)
  MJ-->>Controller: Other info (includes request_path)

  Controller-->>Client: Response
  UI->>UI: Render usage log
  UI->>UI: If other.request_path, display “Request path”
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • creamlike1024
  • Calcium-Ion

Poem

A nibble of logs, a hop through the path,
I trace each request, avoiding all wrath.
With RelayInfo snug in my fluffy pack,
I tag the route—no detail I lack.
MJ hums, the UI sings—
Request path found, my carrot zings! 🥕🐇

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Title Check ⚠️ Warning The title “feat: endpoint type log” does not clearly describe the main change of this pull request, which is to add the request_path to log metadata across multiple handlers and to update related functions and UI components; it uses vague terminology that does not match the implemented feature. Please update the title to explicitly summarize the primary change, for example “feat: include request_path in log metadata” so that it accurately conveys the addition of request path logging.
Docstring Coverage ⚠️ Warning Docstring coverage is 10.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 384cba9 and 7d480d5.

📒 Files selected for processing (10)
  • controller/relay.go (1 hunks)
  • relay/common/relay_info.go (1 hunks)
  • relay/mjproxy_handler.go (2 hunks)
  • relay/relay_task.go (1 hunks)
  • service/log_info_generate.go (4 hunks)
  • web/src/hooks/usage-logs/useUsageLogsData.jsx (1 hunks)
  • web/src/i18n/locales/en.json (1 hunks)
  • web/src/i18n/locales/fr.json (2 hunks)
  • web/src/i18n/locales/ru.json (1 hunks)
  • web/src/i18n/locales/zh.json (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (5)
web/src/hooks/usage-logs/useUsageLogsData.jsx (1)
web/src/components/table/usage-logs/UsageLogsColumnDefs.jsx (1)
  • other (176-176)
relay/mjproxy_handler.go (1)
service/log_info_generate.go (1)
  • GenerateMjOtherInfo (103-112)
relay/common/relay_info.go (3)
types/relay_format.go (12)
  • RelayFormatOpenAI (6-6)
  • RelayFormatOpenAIAudio (10-10)
  • RelayFormatOpenAIImage (11-11)
  • RelayFormatOpenAIRealtime (12-12)
  • RelayFormatClaude (7-7)
  • RelayFormatRerank (13-13)
  • RelayFormatGemini (8-8)
  • RelayFormatEmbedding (14-14)
  • RelayFormatOpenAIResponses (9-9)
  • RelayFormatTask (16-16)
  • RelayFormat (3-3)
  • RelayFormatMjProxy (17-17)
dto/rerank.go (1)
  • RerankRequest (11-19)
dto/openai_request.go (1)
  • OpenAIResponsesRequest (787-811)
relay/relay_task.go (1)
dto/request_common.go (1)
  • Request (8-12)
service/log_info_generate.go (2)
relay/common/relay_info.go (1)
  • RelayInfo (75-122)
types/price_data.go (2)
  • PerCallPriceData (27-31)
  • GroupRatioInfo (5-9)
🔇 Additional comments (10)
web/src/i18n/locales/zh.json (1)

1669-1669: LGTM! Translation key added correctly.

The new localization entry "请求路径": "请求路径" is properly placed among other request-related translations and follows the correct format for the Chinese locale file.

web/src/i18n/locales/en.json (1)

1678-1678: LGTM! English translation added correctly.

The translation entry "请求路径": "Request path" is accurate and consistent with the file's pattern of using Chinese keys with English values. Placement aligns with the corresponding zh.json entry.

controller/relay.go (1)

302-304: LGTM! Defensive request path logging added correctly.

The nil checks for c.Request and c.Request.URL before accessing Path are appropriate defensive programming, especially in error handling paths. While c.Request is unlikely to be nil in a normal Gin handler, this safeguard prevents potential panics and aligns with the broader logging enhancements across the PR.

relay/mjproxy_handler.go (1)

221-221: LGTM! Call sites correctly updated.

Both call sites now properly pass the RelayInfo object as the first argument to match the updated GenerateMjOtherInfo signature. This enables the function to access request_path for logging purposes.

Also applies to: 521-521

relay/common/relay_info.go (4)

429-429: LGTM! Centralized construction pattern.

Introducing a local info variable enables unified return flow and makes the function easier to maintain.


443-446: LGTM! Type assertions add necessary safety.

Explicit type checks for RerankRequest and OpenAIResponsesRequest prevent runtime panics and provide clear error messages. The error messages accurately describe the type mismatch.

Also applies to: 453-456


459-463: LGTM! Explicit RelayFormat assignment.

For Task and MjProxy formats, explicitly setting RelayFormat after creating base info ensures consistency with other format handlers.


468-468: LGTM! Single return point improves maintainability.

Centralizing the return statement makes the control flow clearer and reduces the risk of missing cleanup or instrumentation logic in the future.

service/log_info_generate.go (2)

15-32: LGTM! Well-structured helper function.

The appendRequestPath function correctly prioritizes live request context over stored path and handles edge cases:

  • Nil checks prevent panics
  • Query parameters are properly truncated for cleaner logs
  • Fallback logic ensures path is captured when available

103-112: LGTM! Signature change enables request_path logging.

Adding relayInfo as the first parameter allows GenerateMjOtherInfo to access RequestURLPath for logging. The implementation correctly passes nil for ctx since MJ operations don't have an active HTTP context at this point.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@seefs001
seefs001 merged commit ea870a7 into QuantumNous:main Oct 14, 2025
1 check passed
ennnnny pushed a commit to ennnnny/new-api that referenced this pull request Mar 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant