Skip to content

Conversation

@PascalSenn
Copy link
Contributor

@PascalSenn PascalSenn commented Oct 23, 2025

This PR adds semantic conventions for GraphQL errors following OpenTelemetry patterns and the GraphQL specification.

Summary

Adds support for reporting GraphQL errors as both span events and log records, following the same pattern as the existing exception semantic conventions in OpenTelemetry.

Changes

  1. Registry (spec/registry.yaml)

    • Added new attribute group registry.graphql.error with four attributes:
      • graphql.error.message (required): Error message for developers
      • graphql.error.locations (conditional): Line/column locations in the GraphQL document
      • graphql.error.path (conditional): Path to the response field that experienced the error
      • graphql.error.extensions.code (optional): Error categorization code
  2. Events (spec/events.yaml)

    • Added event.graphql.error for recording GraphQL errors as span events
  3. Logs (spec/logs.yaml)

    • Added log-graphql.error for recording GraphQL errors as log records

Design Decisions (Based on WG Meeting Feedback)

Based on the working group discussion, the following decisions were made:

  • Record on root span: Errors should be recorded on the root span for simplicity and scalability, rather than correlating them with specific resolver spans
  • Extension code for categorization: The error.extensions.code field is opt_in for categorizing errors (e.g., GRAPHQL_VALIDATION_FAILED, UNAUTHENTICATED, FORBIDDEN)
  • Coexistence with exceptions: GraphQL errors and exceptions can coexist for the same issue - errors are visible to users while exceptions represent unhandled issues with stack traces
  • GraphQL spec compliance: All attributes follow the GraphQL specification for error structure

requirement_level: required

- id: graphql.error.path
type: string[]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int or stirng

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or jsonpath

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just found out that an attribute can be either a string[] or a number[], but not a mix of both (string | number)[]. So we should either use jsonpath or a stringified representation of the path.

stability: development
brief: >
The locations in the GraphQL document associated with the error.
examples: ['[{"line":3,"column":7}]']
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a string

Copy link
Contributor

@EmrysMyrddin EmrysMyrddin Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Proposition from last working group:

Suggested change
examples: ['[{"line":3,"column":7}]']
examples: [['3:7', '5:4']]

so a simple string[]

integers. If the error happens in an aliased field, the path to the error should use the
aliased name, since it represents a path in the response, not in the request.
- id: graphql.error.extensions.code
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- id: graphql.error.extensions.code
- id: graphql.error.code

brief: >
This document defines the shared attributes used to
report GraphQL errors associated with a span or event.
attributes:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion from the last meeting, the schema coordinate of the field that experienced the error. This allows to easily group errors by field and identify resolver with hight fault rate.

Suggested change
attributes:
attributes:
- id: graphql.error.schema-coordinate
type: string
stability: development
brief: >
The coordinate of the field in the schema which experienced the error.
examples: ['User.friends', 'Query.me']
note: >
If an error can be associated to a particular field in the GraphQL schema, it must a schema coordinate in the form of `typeName.fieldName` identifying the field which experienced the error.

requirement_level:
conditionally_required: Must be included when the error can be associated with a particular field in the GraphQL result.
- ref: graphql.error.extensions.code
requirement_level: opt_in
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion from last meeting.
See coment in registry.yml for more details.

Suggested change
requirement_level: opt_in
requirement_level: opt_in
- ref: graphql.error.schema-coordinate
requirement_level: opt_in

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.

3 participants