Socket
Socket
Sign inDemoInstall

dd-trace

Package Overview
Dependencies
Maintainers
3
Versions
579
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dd-trace - npm Package Compare versions

Comparing version 0.7.0-beta.3 to 0.7.0-beta.4

src/plugins/util/redis.js

2

lib/version.js

@@ -1,1 +0,1 @@

module.exports = '0.7.0-beta.3'
module.exports = '0.7.0-beta.4'
{
"name": "dd-trace",
"version": "0.7.0-beta.3",
"version": "0.7.0-beta.4",
"description": "Datadog APM tracing client for JavaScript",

@@ -5,0 +5,0 @@ "main": "index.js",

'use strict'
const tx = require('./util/redis')
function createWrapSendCommand (tracer, config) {
return function wrapSendCommand (sendCommand) {
return function sendCommandWithTrace (command, stream) {
const scope = tracer.scopeManager().active()
const span = tracer.startSpan('redis.command', {
childOf: scope && scope.span(),
tags: {
'span.kind': 'client',
'span.type': 'redis',
'service.name': config.service || `${tracer._service}-redis`,
'resource.name': command.name,
'db.type': 'redis',
'db.name': this.options.db || '0',
'out.host': this.options.host,
'out.port': String(this.options.port)
}
})
const db = this.options.db
const span = tx.instrument(tracer, config, db, command.name, command.args)
command.promise
.then(() => finish(span))
.catch(err => finish(span, err))
tx.setHost(span, this.options.host, this.options.port)
tx.wrap(span, command.promise)

@@ -30,14 +19,2 @@ return sendCommand.apply(this, arguments)

function finish (span, error) {
if (error) {
span.addTags({
'error.type': error.name,
'error.msg': error.message,
'error.stack': error.stack
})
}
span.finish()
}
module.exports = {

@@ -44,0 +21,0 @@ name: 'ioredis',

@@ -30,3 +30,3 @@ 'use strict'

'resource.name': query.type,
'memcached.query': query.command
'memcached.command': query.command
})

@@ -33,0 +33,0 @@

@@ -5,190 +5,5 @@ 'use strict'

// TODO: remove sanitization when implemented by the agent
// Reference https://docs.mongodb.com/v3.6/reference/command/
const DATABASE_COMMANDS = [
// Aggregation Commands
'aggregate',
'count',
'distinct',
'group',
'mapReduce',
// Geospatial Commands
'geoNear',
'geoSearch',
// Query and Write Operation Commands
'delete',
'eval',
'find',
'findAndModify',
'getLastError',
'getMore',
'getPrevError',
'insert',
'parallelCollectionScan',
'resetError',
'update',
// Query Plan Cache Commands
'planCacheClear',
'planCacheClearFilters',
'planCacheListFilters',
'planCacheListPlans',
'planCacheListQueryShapes',
'planCacheSetFilter',
// Authentication Commands
'authenticate',
'authSchemaUpgrade',
'copydbgetnonce',
'getnonce',
'logout',
// User Management Commands
'createUser',
'dropAllUsersFromDatabase',
'dropUser',
'grantRolesToUser',
'revokeRolesFromUser',
'updateUser',
'usersInfo',
// Role Management Commands
'createRole',
'dropRole',
'dropAllRolesFromDatabase',
'grantPrivilegesToRole',
'grantRolesToRole',
'invalidateUserCache',
'revokePrivilegesFromRole',
'revokeRolesFromRole',
'rolesInfo',
'updateRole',
// Replication Commands
'applyOps',
'isMaster',
'replSetAbortPrimaryCatchUp',
'replSetFreeze',
'replSetGetConfig',
'replSetGetStatus',
'replSetInitiate',
'replSetMaintenance',
'replSetReconfig',
'replSetResizeOplog',
'replSetStepDown',
'replSetSyncFrom',
'resync',
// Sharding Commands
'addShard',
'addShardToZone',
'balancerStart',
'balancerStatus',
'balancerStop',
'checkShardingIndex',
'cleanupOrphaned',
'enableSharding',
'flushRouterConfig',
'getShardMap',
'getShardVersion',
'isdbgrid',
'listShards',
'medianKey',
'moveChunk',
'movePrimary',
'mergeChunks',
'removeShard',
'removeShardFromZone',
'setShardVersion',
'shardCollection',
'shardingState',
'split',
'splitChunk',
'splitVector',
'unsetSharding',
'updateZoneKeyRange',
// Session Commands
'endSessions',
'killAllSessions',
'killAllSessionsByPattern',
'killSessions',
'refreshSessions',
'startSession',
// Administration Commands
'clean',
'clone',
'cloneCollection',
'cloneCollectionAsCapped',
'collMod',
'compact',
'connPoolSync',
'convertToCapped',
'copydb',
'create',
'createIndexes',
'currentOp',
'drop',
'dropDatabase',
'dropIndexes',
'filemd5',
'fsync',
'fsyncUnlock',
'getParameter',
'killCursors',
'killOp',
'listCollections',
'listDatabases',
'listIndexes',
'logRotate',
'reIndex',
'renameCollection',
'repairCursor',
'repairDatabase',
'setFeatureCompatibilityVersion',
'setParameter',
'shutdown',
'touch',
// Diagnostic Commands
'availableQueryOptions',
'buildInfo',
'collStats',
'connPoolStats',
'connectionStatus',
'cursorInfo',
'dataSize',
'dbHash',
'dbStats',
'diagLogging',
'driverOIDTest',
'explain',
'features',
'getCmdLineOpts',
'getLog',
'hostInfo',
'isSelf',
'listCommands',
'netstat',
'ping',
'profile',
'serverStatus',
'shardConnPoolStats',
'top',
'validate',
'whatsmyuri',
// System Events Auditing Commands
'logApplicationMessage'
]
function createWrapOperation (tracer, config, operationName) {
return function wrapOperation (operation) {
return function operationWithTrace (ns, ops, options, callback) {
const resource = getResource(ns, ops, operationName)
const parentScope = tracer.scopeManager().active()

@@ -199,3 +14,3 @@ const span = tracer.startSpan('mongodb.query', {

addTags(span, tracer, config, resource, ns, this)
addTags(span, tracer, config, ns, ops, this, operationName)

@@ -214,4 +29,2 @@ if (typeof options === 'function') {

return function nextWithTrace (cb) {
const resource = getResource(this.ns, this.cmd)
const parentScope = tracer.scopeManager().active()

@@ -222,3 +35,3 @@ const span = tracer.startSpan('mongodb.query', {

addTags(span, tracer, config, resource, this.ns, this.topology)
addTags(span, tracer, config, this.ns, this.cmd, this.topology)

@@ -236,3 +49,6 @@ if (this.cursorState) {

function addTags (span, tracer, config, resource, ns, topology) {
function addTags (span, tracer, config, ns, cmd, topology, operationName) {
const query = getQuery(cmd)
const resource = getResource(ns, cmd, query, operationName)
span.addTags({

@@ -245,2 +61,6 @@ 'service.name': config.service || `${tracer._service}-mongodb`,

if (query) {
span.setTag('mongodb.query', query)
}
if (topology.s && topology.s.options) {

@@ -272,5 +92,9 @@ span.addTags({

function getResource (ns, cmd, operationName) {
function getQuery (cmd) {
return cmd.query && JSON.stringify(sanitize(cmd.query))
}
function getResource (ns, cmd, query, operationName) {
if (!operationName) {
operationName = DATABASE_COMMANDS.find(name => cmd[name] !== undefined) || 'unknownCommand'
operationName = Object.keys(cmd)[0]
}

@@ -280,4 +104,4 @@

if (cmd.query) {
parts.push(JSON.stringify(sanitize(cmd.query)))
if (query) {
parts.push(query)
}

@@ -284,0 +108,0 @@

'use strict'
const Tags = require('opentracing').Tags
const tx = require('./util/redis')

@@ -8,5 +8,5 @@ function createWrapInternalSendCommand (tracer, config) {

return function internalSendCommandWithTrace (options) {
const span = startSpan(tracer, config, this, options.command)
const span = startSpan(tracer, config, this, options.command, options.args)
options.callback = wrapCallback(tracer, span, options.callback)
options.callback = tx.wrap(span, options.callback)

@@ -21,10 +21,10 @@ return internalSendCommand.call(this, options)

return function sendCommandWithTrace (command, args, callback) {
const span = startSpan(tracer, config, this, command)
const span = startSpan(tracer, config, this, command, args)
if (callback) {
callback = wrapCallback(tracer, span, callback)
callback = tx.wrap(span, callback)
} else if (args) {
args[(args.length || 1) - 1] = wrapCallback(tracer, span, args[args.length - 1])
args[(args.length || 1) - 1] = tx.wrap(span, args[args.length - 1])
} else {
args = [wrapCallback(tracer, span)]
args = [tx.wrap(span)]
}

@@ -37,49 +37,12 @@

function startSpan (tracer, config, client, command) {
const scope = tracer.scopeManager().active()
const span = tracer.startSpan('redis.command', {
childOf: scope && scope.span(),
tags: {
[Tags.SPAN_KIND]: Tags.SPAN_KIND_RPC_CLIENT,
[Tags.DB_TYPE]: 'redis',
'service.name': config.service || `${tracer._service}-redis`,
'resource.name': command,
'span.type': 'redis',
'db.name': client.selected_db || '0'
}
})
function startSpan (tracer, config, client, command, args) {
const db = client.selected_db
const connectionOptions = client.connection_options || client.connection_option || {}
const span = tx.instrument(tracer, config, db, command, args)
const connectionOptions = client.connection_options || client.connection_option || {
host: client.options.host || '127.0.0.1',
port: client.options.port || 6379
}
tx.setHost(span, connectionOptions.host, connectionOptions.port)
if (connectionOptions) {
span.addTags({
'out.host': String(connectionOptions.host),
'out.port': String(connectionOptions.port)
})
}
return span
}
function wrapCallback (tracer, span, done) {
return (err, res) => {
if (err) {
span.addTags({
'error.type': err.name,
'error.msg': err.message,
'error.stack': err.stack
})
}
span.finish()
if (typeof done === 'function') {
done(err, res)
}
}
}
module.exports = [

@@ -86,0 +49,0 @@ {

@@ -27,6 +27,8 @@ 'use strict'

const validateStatus = getStatusValidator(config)
const hooks = getHooks(config)
return Object.assign({}, config, {
headers,
validateStatus
validateStatus,
hooks
})

@@ -82,2 +84,3 @@ },

paths: [],
hooks: [],
beforeEnd: []

@@ -95,2 +98,4 @@ }

function startSpan (tracer, config, req, res, name) {
req._datadog.hooks.push(config.hooks)
if (req._datadog.span) {

@@ -116,3 +121,3 @@ req._datadog.span.context().name = name

function finish (req) {
function finish (req, res) {
if (req._datadog.finished) return

@@ -122,2 +127,3 @@

req._datadog.hooks.forEach(hooks => hooks.request(req._datadog.span, req, res))
req._datadog.span.finish()

@@ -137,3 +143,3 @@ req._datadog.scope && req._datadog.scope.close()

finish(req)
finish(req, res)

@@ -221,2 +227,9 @@ return returnValue

function getHooks (config) {
const noop = () => {}
const request = (config.hooks && config.hooks.request) || noop
return { request }
}
module.exports = web
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc