Last active
October 22, 2016 15:30
-
-
Save helfer/9e631a59fbba237bb9a90594166cfba5 to your computer and use it in GitHub Desktop.
How to instrument apollo server 0.2 with tracer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import express from 'express'; | |
import { Tracer } from 'graphql-tracer'; | |
import { apolloExpress } from 'apollo-server'; | |
import Schema from './schema'; | |
const app = express(); | |
const tracer = new Tracer({ TRACER_APP_KEY: '...'}); | |
addTracingToResolvers(Schema); | |
const optionsFunc = req => { | |
return { | |
schema: Schema, | |
context: {}, | |
formatParams: params => { | |
const logger = tracer.newLoggerInstance(); | |
logger.log('request.info', { | |
headers: req.headers, | |
baseUrl: req.baseUrl, | |
originalUrl: req.originalUrl, | |
method: req.method, | |
httpVersion: req.httpVersion, | |
remoteAddr: req.connection.remoteAddress, | |
}); | |
params['logFunction'] = logger.log; | |
params['context']['tracer'] = logger; | |
return params; | |
}, | |
formatResponse: (response, { context }) => { | |
context.tracer.submit(); | |
return response; | |
} | |
}; | |
} | |
app.use('/graphql', apolloExpress(optionsFunc)); | |
app.listen(3000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
addTracingToResolvers
should also be imported from graphql-tracer on line 2 right?