Skip to content

Add logging to GraphQL

I think it would be good to add some logging to our GraphQL api. There are a couple immediate places it can be added:

In GitlabSchema, for logging query complexity, as mentioned in Prevent complex queries

  log_query_complexity = GraphQL::Analysis::QueryComplexity.new { |query, complexity| Rails.logger.info("[GraphQL Query Complexity] #{complexity}  | admin? #{query.context[:current_user]&.admin?}")}
  query_analyzer(log_query_complexity)

Also logging timeout errors, as mentioned in Timeout

Do we create a new log file, log/graphql_json.log or use the existing log/api_json.log?

MR: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/27885

EE backport: https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/13620

Edited by charlie ablett