cosmo icon indicating copy to clipboard operation
cosmo copied to clipboard

feat: improve error access logs

Open StarpTech opened this issue 7 months ago • 1 comments

Motivation and Context

This PR enhances our GraphQL router’s logging and error pipelines, giving you fine-grained control over access-log verbosity, richer diagnostics in both router and subgraph logs, and tidier error propagation.

🎯 What’s Changed

  1. Configurable Access-Log Level

    • Now you can set "level" to control which requests get logged ("info" vs "error").
  2. Optional Stack Traces

    • The new "add_stacktrace" flag lets you include full stack traces in your access logs when errors occur.
  3. New response_error context field

    • This field will log the response errors as JSON array and includes verbose information including stacktraces about all errors.
  4. Cleaner Error Composition

    • Resolver errors now propagate intact into the final GraphQL error payload, and we’ve removed an accidental “double join” that was duplicating messages.

⚙️ JSON Config Example

access_logs:
  enabled: true
  add_stacktrace: true
  level: error
  router:
    fields:
      - key: "response_error"
        value_from:
          context_field: response_error
  subgraphs:
    enabled: true
    fields:
      - key: "response_error"
        value_from:
          context_field: response_error

In this snippet:

  • "level": "error" ensures only failed operations are emitted.
  • "add_stacktrace": true" appends the stack trace for any error.
  • Field response_error will log the response errors in JSON format including stacktrace information.

Related https://github.com/wundergraph/graphql-go-tools/pull/1132

Checklist

  • [ ] I have discussed my proposed changes in an issue and have received approval to proceed.
  • [ ] I have followed the coding standards of the project.
  • [ ] Tests or benchmarks have been added or updated.
  • [ ] Documentation has been updated on https://github.com/wundergraph/cosmo-docs.
  • [ ] I have read the Contributors Guide.

StarpTech avatar Apr 24 '25 19:04 StarpTech