dd-trace 2.3.1 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/index.d.ts +51 -0
  2. package/package.json +2 -2
  3. package/packages/datadog-instrumentations/index.js +8 -0
  4. package/packages/datadog-instrumentations/src/amqp10.js +70 -0
  5. package/packages/datadog-instrumentations/src/amqplib.js +58 -0
  6. package/packages/datadog-instrumentations/src/cassandra-driver.js +191 -0
  7. package/packages/datadog-instrumentations/src/cucumber.js +2 -0
  8. package/packages/datadog-instrumentations/src/helpers/instrument.js +3 -3
  9. package/packages/datadog-instrumentations/src/mocha.js +122 -0
  10. package/packages/datadog-instrumentations/src/mongodb-core.js +179 -0
  11. package/packages/datadog-instrumentations/src/pg.js +75 -0
  12. package/packages/datadog-instrumentations/src/rhea.js +224 -0
  13. package/packages/datadog-instrumentations/src/tedious.js +66 -0
  14. package/packages/datadog-plugin-amqp10/src/index.js +79 -122
  15. package/packages/datadog-plugin-amqplib/src/index.js +77 -142
  16. package/packages/datadog-plugin-cassandra-driver/src/index.js +52 -224
  17. package/packages/datadog-plugin-cucumber/src/index.js +3 -1
  18. package/packages/datadog-plugin-jest/src/jest-jasmine2.js +5 -3
  19. package/packages/datadog-plugin-mocha/src/index.js +96 -207
  20. package/packages/datadog-plugin-mongodb-core/src/index.js +119 -3
  21. package/packages/datadog-plugin-pg/src/index.js +32 -69
  22. package/packages/datadog-plugin-rhea/src/index.js +59 -225
  23. package/packages/datadog-plugin-tedious/src/index.js +38 -86
  24. package/packages/dd-trace/lib/version.js +1 -1
  25. package/packages/dd-trace/src/appsec/recommended.json +137 -116
  26. package/packages/dd-trace/src/config.js +6 -0
  27. package/packages/dd-trace/src/noop/tracer.js +4 -0
  28. package/packages/dd-trace/src/opentracing/propagation/text_map.js +34 -1
  29. package/packages/dd-trace/src/proxy.js +4 -0
  30. package/packages/dd-trace/src/tracer.js +16 -0
  31. package/packages/datadog-plugin-mongodb-core/src/legacy.js +0 -59
  32. package/packages/datadog-plugin-mongodb-core/src/unified.js +0 -138
  33. package/packages/datadog-plugin-mongodb-core/src/util.js +0 -143
@@ -1,143 +0,0 @@
1
- 'use strict'
2
-
3
- const analyticsSampler = require('../../dd-trace/src/analytics_sampler')
4
-
5
- function instrument (command, ctx, args, server, ns, ops, tracer, config, options = {}) {
6
- const name = options.name || (ops && Object.keys(ops)[0])
7
- const index = args.length - 1
8
- const callback = args[index]
9
-
10
- if (typeof callback !== 'function') return command.apply(ctx, args)
11
-
12
- const span = startSpan(tracer, config, ns, ops, server, name)
13
-
14
- if (name !== 'getMore' && name !== 'killCursors') {
15
- analyticsSampler.sample(span, config.measured)
16
- }
17
-
18
- args[index] = wrapCallback(tracer, span, callback)
19
-
20
- return tracer.scope().bind(command, span).apply(ctx, args)
21
- }
22
-
23
- function startSpan (tracer, config, ns, ops, server, name) {
24
- const scope = tracer.scope()
25
- const childOf = scope.active()
26
- const span = tracer.startSpan('mongodb.query', { childOf })
27
-
28
- addTags(span, tracer, config, ns, ops, server, name)
29
-
30
- return span
31
- }
32
-
33
- function wrapCallback (tracer, span, done) {
34
- return tracer.scope().bind((err, res) => {
35
- if (err) {
36
- span.addTags({
37
- 'error.type': err.name,
38
- 'error.msg': err.message,
39
- 'error.stack': err.stack
40
- })
41
- }
42
-
43
- span.finish()
44
-
45
- if (done) {
46
- done(err, res)
47
- }
48
- })
49
- }
50
-
51
- function addTags (span, tracer, config, ns, cmd, topology, operationName) {
52
- const query = getQuery(cmd)
53
- const resource = getResource(ns, query, operationName)
54
-
55
- span.addTags({
56
- 'service.name': config.service || `${tracer._service}-mongodb`,
57
- 'resource.name': resource,
58
- 'span.type': 'mongodb',
59
- 'span.kind': 'client',
60
- 'db.name': ns
61
- })
62
-
63
- if (query) {
64
- span.setTag('mongodb.query', query)
65
- }
66
-
67
- addHost(span, topology)
68
- }
69
-
70
- function addHost (span, topology) {
71
- const options = topology && topology.s && topology.s.options
72
-
73
- if (options && options.host && options.port) {
74
- span.addTags({
75
- 'out.host': topology.s.options.host,
76
- 'out.port': topology.s.options.port
77
- })
78
- }
79
- }
80
-
81
- function getQuery (cmd) {
82
- if (!cmd || typeof cmd !== 'object' || Array.isArray(cmd)) return
83
- if (cmd.query) return JSON.stringify(sanitize(cmd.query))
84
- if (cmd.filter) return JSON.stringify(sanitize(cmd.filter))
85
- }
86
-
87
- function getResource (ns, query, operationName) {
88
- const parts = [operationName, ns]
89
-
90
- if (query) {
91
- parts.push(query)
92
- }
93
-
94
- return parts.join(' ')
95
- }
96
-
97
- function shouldHide (input) {
98
- return !isObject(input) || Buffer.isBuffer(input) || isBSON(input)
99
- }
100
-
101
- function sanitize (input) {
102
- if (shouldHide(input)) return '?'
103
-
104
- const output = {}
105
- const queue = [{
106
- input,
107
- output,
108
- depth: 0
109
- }]
110
-
111
- while (queue.length) {
112
- const {
113
- input, output, depth
114
- } = queue.pop()
115
- const nextDepth = depth + 1
116
- for (const key in input) {
117
- if (typeof input[key] === 'function') continue
118
-
119
- const child = input[key]
120
- if (depth >= 20 || shouldHide(child)) {
121
- output[key] = '?'
122
- } else {
123
- queue.push({
124
- input: child,
125
- output: output[key] = {},
126
- depth: nextDepth
127
- })
128
- }
129
- }
130
- }
131
-
132
- return output
133
- }
134
-
135
- function isObject (val) {
136
- return typeof val === 'object' && val !== null && !(val instanceof Array)
137
- }
138
-
139
- function isBSON (val) {
140
- return val && val._bsontype
141
- }
142
-
143
- module.exports = { instrument }