apollographql / apollo-tracing

A GraphQL extension for performance tracing
478 stars 35 forks source link

[feature] Tracing Errors #23

Closed can-kayacan closed 5 years ago

can-kayacan commented 5 years ago

Errors from the resolvers are not traced.

const books = [
...
];

const resolvers = {
  Query: {
    books: () => books,
    reservedBooks: () => {
      throw new Error("Reserved books could not be found!")
    }
  }
};

Here the reservedBooks resolver is throwing an error which is not anyhow detected by the apollo-tracing.

{  
   "version":1,
   "startTime":"2019-03-21T15:12:52.808Z",
   "endTime":"2019-03-21T15:12:52.809Z",
   "duration":972315,
   "execution":{  
      "resolvers":[  
         {  
            "path":[  
               "books"
            ],
            "parentType":"Query",
            "fieldName":"books",
            "returnType":"[Book]",
            "startOffset":573807,
            "duration":9734
         },
         ...
         {  
            "path":[  
               "reservedBooks"
            ],
            "parentType":"Query",
            "fieldName":"reservedBooks",
            "returnType":"[Book]",
            "startOffset":651279,
            "duration":16398
         }
      ]
   }
}
can-kayacan commented 5 years ago
  graphqlHTTP(
    (request: any) =>
      <any>{
        schema: instrumentSchemaForTracing(schema),
        context: {
          _traceCollector: request._traceCollector
        },
        graphiql: true,
        extensions: (info: any) => {
          // **access errors here**
          info.result.errors
        }
      }
  )
martijnwalraven commented 5 years ago

I may be missing something, but any thrown errors should be present in a top-level errors field, so there's no need to make this part of the tracing extension.