elastic-apm-node
Advanced tools
Comparing version 3.6.1 to 3.7.0
@@ -43,2 +43,7 @@ /// <reference types="node" /> | ||
currentTraceparent: string | null; | ||
currentTraceIds: { | ||
'trace.id'?: string; | ||
'transaction.id'?: string; | ||
'span.id'?: string; | ||
} | ||
@@ -45,0 +50,0 @@ // Transactions |
@@ -182,6 +182,7 @@ 'use strict' | ||
if (type === 'response') onresponse(res) | ||
if (type === 'abort') onAbort(type) | ||
return emit.apply(req, arguments) | ||
} | ||
let url | ||
let url, statusCode | ||
httpRequestToUrl(req).then(_url => { | ||
@@ -195,2 +196,33 @@ url = _url | ||
// In case the request is ended prematurely | ||
function onAbort (type) { | ||
if (span.ended) return | ||
agent.logger.debug('intercepted http.ClientRequest abort event %o', { id: id }) | ||
onEnd() | ||
} | ||
function onEnd () { | ||
span.setHttpContext({ | ||
method: req.method, | ||
status_code: statusCode, | ||
url | ||
}) | ||
// Add destination info only when socket conn is established | ||
if (url) { | ||
// The `getHTTPDestination` function might throw in case an | ||
// invalid URL is given to the `URL()` function. Until we can | ||
// be 100% sure this doesn't happen, we better catch it here. | ||
// For details, see: | ||
// https://github.com/elastic/apm-agent-nodejs/issues/1769 | ||
try { | ||
span.setDestinationContext(getHTTPDestination(url, span.type)) | ||
} catch (e) { | ||
agent.logger.error('Could not set destination context:', e.message) | ||
} | ||
} | ||
span.end() | ||
} | ||
function onresponse (res) { | ||
@@ -203,17 +235,9 @@ // Work around async_hooks bug in Node.js 12.0 - 12.2 (https://github.com/nodejs/node/pull/27477) | ||
res.prependListener('end', onEnd) | ||
statusCode = res.statusCode | ||
function onEnd () { | ||
res.prependListener('end', function () { | ||
agent.logger.debug('intercepted http.IncomingMessage end event %o', { id: id }) | ||
span.setHttpContext({ | ||
method: req.method, | ||
status_code: this.statusCode, | ||
url | ||
}) | ||
span.setDestinationContext(getHTTPDestination(url, span.type)) | ||
span.end() | ||
} | ||
onEnd() | ||
}) | ||
} | ||
@@ -220,0 +244,0 @@ } |
@@ -5,2 +5,3 @@ 'use strict' | ||
const shimmer = require('../shimmer') | ||
const clone = require('shallow-clone-shim') | ||
@@ -15,11 +16,27 @@ module.exports = function (apolloServerCore, agent, { version, enabled }) { | ||
shimmer.wrap(apolloServerCore, 'runHttpQuery', function (runHttpQuery) { | ||
function wrapRunHttpQuery (orig) { | ||
return function wrappedRunHttpQuery () { | ||
var trans = agent._instrumentation.currentTransaction | ||
if (trans) trans._graphqlRoute = true | ||
return runHttpQuery.apply(this, arguments) | ||
return orig.apply(this, arguments) | ||
} | ||
} | ||
if (semver.satisfies(version, '<2.14')) { | ||
shimmer.wrap(apolloServerCore, 'runHttpQuery', wrapRunHttpQuery) | ||
return apolloServerCore | ||
} | ||
// apollo-server-core >= 2.14 does not allow overriding the exports object | ||
return clone({}, apolloServerCore, { | ||
runHttpQuery (descriptor) { | ||
const getter = descriptor.get | ||
if (getter) { | ||
descriptor.get = function get () { | ||
return wrapRunHttpQuery(getter()) | ||
} | ||
} | ||
return descriptor | ||
} | ||
}) | ||
return apolloServerCore | ||
} |
@@ -58,6 +58,11 @@ 'use strict' | ||
} else { | ||
return original.apply(this, arguments) | ||
.then(function (originalP) { | ||
const originalPromise = original.apply(this, arguments) | ||
const descriptors = Object.getOwnPropertyDescriptors(originalPromise) | ||
delete descriptors.domain | ||
const inspectedPromise = originalPromise | ||
.then(function (value) { | ||
span.end() | ||
return originalP | ||
return value | ||
}, function (err) { | ||
@@ -67,2 +72,17 @@ span.end() | ||
}) | ||
Object.defineProperties(inspectedPromise, descriptors) | ||
// we have to properly end the span when user aborts the request | ||
shimmer.wrap(inspectedPromise, 'abort', function wrapAbort (originalAbort) { | ||
return function wrappedAbort () { | ||
if (span.ended) return | ||
agent.logger.debug('intercepted call to elasticsearch.Transport.request.abort %o', { id: id, method: method, path: path }) | ||
const originalReturn = originalAbort.apply(this, args) | ||
span.end() | ||
return originalReturn | ||
} | ||
}) | ||
return inspectedPromise | ||
} | ||
@@ -69,0 +89,0 @@ } else { |
@@ -10,3 +10,3 @@ 'use strict' | ||
if (!enabled) return graphql | ||
if (!semver.satisfies(version, '>=0.7.0 <15.0.0 || ^14.0.0-rc') || | ||
if (!semver.satisfies(version, '>=0.7.0 <16.0.0 || ^14.0.0-rc') || | ||
!graphql.Kind || | ||
@@ -13,0 +13,0 @@ typeof graphql.Source !== 'function' || |
@@ -182,3 +182,12 @@ 'use strict' | ||
span.setDestinationContext(getHTTPDestination(url, span.type)) | ||
// The `getHTTPDestination` function might throw in case an | ||
// invalid URL is given to the `URL()` function. Until we can | ||
// be 100% sure this doesn't happen, we better catch it here. | ||
// For details, see: | ||
// https://github.com/elastic/apm-agent-nodejs/issues/1769 | ||
try { | ||
span.setDestinationContext(getHTTPDestination(url, span.type)) | ||
} catch (e) { | ||
agent.logger.error('Could not set destination context:', e.message) | ||
} | ||
@@ -185,0 +194,0 @@ span.end() |
@@ -10,3 +10,3 @@ 'use strict' | ||
if (!enabled) return Knex | ||
if (semver.gte(version, '0.21.0')) { | ||
if (semver.gte(version, '0.22.0')) { | ||
agent.logger.debug('knex version %s not supported - aborting...', version) | ||
@@ -13,0 +13,0 @@ return Knex |
@@ -9,3 +9,3 @@ 'use strict' | ||
if (!enabled) return Router | ||
if (!semver.satisfies(version, '>=5.2.0 <9')) { | ||
if (!semver.satisfies(version, '>=5.2.0 <10')) { | ||
agent.logger.debug('koa-router version %s not supported - aborting...', version) | ||
@@ -12,0 +12,0 @@ return Router |
@@ -9,3 +9,3 @@ 'use strict' | ||
module.exports = function (redis, agent, { version, enabled }) { | ||
if (!semver.satisfies(version, '^2.0.0')) { | ||
if (!semver.satisfies(version, '^3.0.0')) { | ||
agent.logger.debug('redis version %s not supported - aborting...', version) | ||
@@ -12,0 +12,0 @@ return redis |
{ | ||
"name": "elastic-apm-node", | ||
"version": "3.6.1", | ||
"version": "3.7.0", | ||
"description": "The official Elastic APM agent for Node.js", | ||
@@ -111,3 +111,3 @@ "main": "index.js", | ||
"devDependencies": { | ||
"@apidevtools/json-schema-ref-parser": "^8.0.0", | ||
"@apidevtools/json-schema-ref-parser": "^9.0.1", | ||
"@babel/cli": "^7.8.4", | ||
@@ -120,3 +120,3 @@ "@babel/core": "^7.8.4", | ||
"@hapi/hapi": "^18.4.1", | ||
"@koa/router": "^8.0.8", | ||
"@koa/router": "^9.0.1", | ||
"@types/node": "^13.7.4", | ||
@@ -143,3 +143,3 @@ "apollo-server-express": "^2.10.1", | ||
"got": "^9.6.0", | ||
"graphql": "^14.6.0", | ||
"graphql": "^15.3.0", | ||
"handlebars": "^4.7.3", | ||
@@ -152,5 +152,5 @@ "hapi": "^18.1.0", | ||
"jade": "^1.11.0", | ||
"knex": "^0.20.10", | ||
"knex": "^0.21.2", | ||
"koa": "^2.11.0", | ||
"koa-router": "^8.0.8", | ||
"koa-router": "^9.0.1", | ||
"lambda-local": "^1.7.1", | ||
@@ -171,3 +171,3 @@ "memcached": "^2.2.2", | ||
"pug": "^2.0.4", | ||
"redis": "^2.8.0", | ||
"redis": "^3.0.2", | ||
"request": "^2.88.2", | ||
@@ -179,3 +179,3 @@ "restify": "^8.5.1", | ||
"standard": "^14.3.3", | ||
"tape": "^4.13.0", | ||
"tape": "^5.0.0", | ||
"tedious": "^8.0.1", | ||
@@ -206,5 +206,5 @@ "test-all-versions": "^4.1.1", | ||
"coordinates": [ | ||
56.038606, | ||
12.619913 | ||
56.038184, | ||
12.61979 | ||
] | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
265778
6312