UNPKG

dd-trace

Version:

Datadog APM tracing client for JavaScript

34 lines (28 loc) 986 B
'use strict' const shimmer = require('../../datadog-shimmer') const { channel, addHook } = require('./helpers/instrument') const cryptoHashCh = channel('datadog:crypto:hashing:start') const cryptoCipherCh = channel('datadog:crypto:cipher:start') const hashMethods = ['createHash', 'createHmac', 'createSign', 'createVerify', 'sign', 'verify'] const cipherMethods = ['createCipheriv', 'createDecipheriv'] const names = ['crypto', 'node:crypto'] addHook({ name: names }, crypto => { shimmer.massWrap(crypto, hashMethods, wrapCryptoMethod(cryptoHashCh)) shimmer.massWrap(crypto, cipherMethods, wrapCryptoMethod(cryptoCipherCh)) return crypto }) function wrapCryptoMethod (channel) { function wrapMethod (cryptoMethod) { return function () { if (channel.hasSubscribers && arguments.length > 0) { const algorithm = arguments[0] channel.publish({ algorithm }) } return cryptoMethod.apply(this, arguments) } } return wrapMethod }