Skip to content

Commit

Permalink
Merge branch 'master' into v2-api
Browse files Browse the repository at this point in the history
  • Loading branch information
watson committed Jul 31, 2018
2 parents 061c48e + 69448f5 commit 8423307
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 6 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# 1.10.1 - 2018/7/31
* fix(graphql): handle execute args object (#484)

# 1.10.0 - 2018/7/30
* feat(cassandra): instrument Cassandra queries (#437)
* feat(mssql): instrument SQL Server queries (#444)

# 1.9.0 - 2018/7/25
* fix(parsers): use basic-auth rather than req.auth (#475)
* feat(agent): add currentTransaction getter (#462)
Expand Down
22 changes: 21 additions & 1 deletion lib/instrumentation/modules/graphql.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ module.exports = function (graphql, agent, version, enabled) {
}

function wrapExecute (orig) {
return function wrappedExecute (schema, document, rootValue, contextValue, variableValues, operationName) {
function wrappedExecuteImpl (schema, document, rootValue, contextValue, variableValues, operationName) {
var trans = agent._instrumentation.currentTransaction
var span = agent.buildSpan()
var id = span && span.transaction.id
Expand Down Expand Up @@ -135,6 +135,26 @@ module.exports = function (graphql, agent, version, enabled) {
}
return p
}

return function wrappedExecute (argsOrSchema, document, rootValue, contextValue, variableValues, operationName) {
return arguments.length === 1
? wrappedExecuteImpl(
argsOrSchema.schema,
argsOrSchema.document,
argsOrSchema.rootValue,
argsOrSchema.contextValue,
argsOrSchema.variableValues,
argsOrSchema.operationName
)
: wrappedExecuteImpl(
argsOrSchema,
document,
rootValue,
contextValue,
variableValues,
operationName
)
}
}

function extractDetails (document, operationName) {
Expand Down
3 changes: 2 additions & 1 deletion lib/instrumentation/modules/tedious.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ module.exports = function (tedious, agent, version, enabled) {
return originalMakeRequest.apply(this, arguments)
}

const preparing = request.sqlTextOrProcedure === 'sp_prepare'
const params = request.parametersByName
const sql = (params.statement || params.stmt || {}).value
const name = sqlSummary(sql) + (request.preparing ? ' (prepare)' : '')
const name = sqlSummary(sql) + (preparing ? ' (prepare)' : '')
span.setDbContext({ statement: sql, type: 'sql' })
span.start(name, 'db.mssql.query')

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "elastic-apm-node",
"version": "1.9.0",
"version": "1.10.1",
"description": "The official Elastic APM agent for Node.js",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -152,7 +152,7 @@
]
},
"coordinates": [
55.777395,
12.592147
55.777008,
12.592123
]
}
2 changes: 1 addition & 1 deletion test/.jenkins_tav.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
TAV:
- generic-pool+mysql+mysql2+redis+koa-router+handlebars+mongodb-core
- ioredis+pg+cassandra-driver
- ioredis+pg+cassandra-driver+tedious
- mimic-response+got+bluebird
- knex+ws+graphql+express-graphql+elasticsearch+hapi+express+express-queue
25 changes: 25 additions & 0 deletions test/instrumentation/modules/graphql.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,31 @@ test('graphql.execute', function (t) {
})
})

test('graphql.execute args object', function (t) {
resetAgent(done(t))

var schema = graphql.buildSchema('type Query { hello: String }')
var root = {hello () {
return Promise.resolve('Hello world!')
}}
var query = '{ hello }'
var source = new graphql.Source(query)
var documentAST = graphql.parse(source)
var args = {
schema: schema,
document: documentAST,
rootValue: root
}

agent.startTransaction('foo')

graphql.execute(args).then(function (response) {
agent.endTransaction()
t.deepEqual(response, {data: {hello: 'Hello world!'}})
agent.flush()
})
})

if (semver.satisfies(pkg.version, '>=0.12')) {
test('graphql.execute sync', function (t) {
resetAgent(done(t))
Expand Down

0 comments on commit 8423307

Please sign in to comment.