apollographql / router

A configurable, high-performance routing runtime for Apollo Federation 🚀
https://www.apollographql.com/docs/router/
Other
774 stars 251 forks source link

Configurability of log attributes #5540

Open BrynCooke opened 1 week ago

BrynCooke commented 1 week ago

Currently when configuring the attributes that are output onto log events we have the following:

telemetry:
  exporters:
    logging: 
      stdout:
        format: 
          json:
            display_span_list: true # Output all attributes from all spans to the root
            display_current_span: true # Output attributes from the current span

When following the otel conventions there can be a large number of span attributes, and users need the ability to specify which attributes should be output rather than the all or nothing settings we have already.

Users needs to be able to opt in to attributes so that they can be sure that only the attributes they want are output.

Suggested config:

telemetry:
  exporters:
    logging:
      stdout:
        format:
          json:
            attributes:
              - my.custom.attribute1
              - my.custom.attribute2
  instrumentation:
    spans:
      router:
        attributes:
          my.custom.attribute1: "hello"
      subgraph: 
        attributes:
          my.custom.attribute2: "world"

This will search for the first attribute in the list of span attributes from the root span to the current and attach it to the outmost json object for the log event.

First attribute from root wins, so if anything is found at router then an identical attribute from child spans will be ignored.

Samjin commented 1 week ago

The PRs that closed items 3 and 4 are linked in the description, but is also here: #5447

So to confirm, this ticket can sample a custom trace id. 3 & 4 from last ticket would help to append to custom request logs. Does 3/4 allow custom trace id format like UUID? Based on the router schema definition 3 and 4 requires hexadecimal/ decimal, open_telemetry/datadog format, or are these format specific for experimental_response_trace_id feature only?

Samjin commented 4 days ago

a1e81c42-5558-4b62-a363-a6dbcc1014dc as example trace id

BrynCooke commented 1 day ago

Added suggested config. We are going to tackle the uuid formatting thing separately.