cosmo icon indicating copy to clipboard operation
cosmo copied to clipboard

feat: add specific request tracing hooks

Open SkArchon opened this issue 6 months ago • 1 comments
trafficstars

Motivation and Context

Sometimes subgraph requests can fail for users, and it might not be obvious why, by providing a way to log and add more span details, this can help users to figure out what is actually happening at the request level.

In order to do this we allow adding more detailed values to the expression context for subgraphs. For this we introduce a Subgraph expression context based on the expr spec (https://github.com/wundergraph/cosmo/pull/1481).

The PR also makes expression attributes available to the subgraph access logger (previously it was only the router access logger that could process expressions).

We use httptrace.ClientTrace for getting more detailed values. We wrap the current roundtripper transport in a wrapper transport which includes the httptrace.ClientTrace hooks. We ONLY enable (TODO) the ClientTrace when any user has used subgraph.trace in any expression, to reduce unwanted latency.

Example Configuration (still in flux)

access_logs:
  subgraphs:
    enabled: true
    fields:
      - key: "there"
        value_from:
          expression: "subgraph.error ?? subgraph.trace.attributes[\"getconn.hostport\"]"

telemetry:
  tracing:
    enabled: true
    exporters:
      - endpoint: "http://localhost:4319"
        exporter: http
    subgraph:
      attributes:
        - key: "wg.tracing.testthere"
          expression: "subgraph.error ?? subgraph.trace.attributes[\"getconn.hostport\"]"

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.

SkArchon avatar Apr 28 '25 09:04 SkArchon

Router image scan passed

:white_check_mark: No security vulnerabilities found in image:

ghcr.io/wundergraph/cosmo/router:sha-713fdd616f3cab545f985cf9301c687e5df04c5e

github-actions[bot] avatar Apr 28 '25 09:04 github-actions[bot]

Because we also introduce custom telemetry attributes, we don't have a way right now to allow custom attributes in studio. We will need to (initial thoughts at least) add a UI in studio which can allow users to specify what custom telemetry attributes they want to view in studio traces. (cc: @StarpTech)

SkArchon avatar May 05 '25 10:05 SkArchon