dd-trace 5.0.0-pre-e4b9a26 → 5.0.0-pre-0fb796c

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 (45) hide show
  1. package/index.d.ts +14 -0
  2. package/package.json +2 -2
  3. package/packages/datadog-instrumentations/src/helpers/hooks.js +1 -0
  4. package/packages/datadog-instrumentations/src/openai.js +50 -0
  5. package/packages/datadog-plugin-cassandra-driver/src/index.js +2 -2
  6. package/packages/datadog-plugin-dns/src/lookup.js +1 -1
  7. package/packages/datadog-plugin-elasticsearch/src/index.js +2 -2
  8. package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +1 -1
  9. package/packages/datadog-plugin-graphql/src/execute.js +1 -1
  10. package/packages/datadog-plugin-graphql/src/parse.js +1 -1
  11. package/packages/datadog-plugin-graphql/src/resolve.js +0 -5
  12. package/packages/datadog-plugin-graphql/src/validate.js +1 -1
  13. package/packages/datadog-plugin-grpc/src/client.js +1 -1
  14. package/packages/datadog-plugin-grpc/src/server.js +1 -1
  15. package/packages/datadog-plugin-http/src/client.js +1 -1
  16. package/packages/datadog-plugin-http/src/server.js +38 -34
  17. package/packages/datadog-plugin-http2/src/client.js +0 -5
  18. package/packages/datadog-plugin-http2/src/server.js +23 -23
  19. package/packages/datadog-plugin-moleculer/src/client.js +1 -1
  20. package/packages/datadog-plugin-mongodb-core/src/index.js +2 -2
  21. package/packages/datadog-plugin-openai/src/index.js +678 -0
  22. package/packages/datadog-plugin-openai/src/services.js +43 -0
  23. package/packages/datadog-plugin-oracledb/src/index.js +2 -10
  24. package/packages/datadog-plugin-pg/src/index.js +2 -10
  25. package/packages/datadog-plugin-sharedb/src/index.js +1 -1
  26. package/packages/dd-trace/src/ci-visibility/exporters/git/git_metadata.js +12 -0
  27. package/packages/dd-trace/src/config.js +11 -0
  28. package/packages/dd-trace/src/constants.js +2 -0
  29. package/packages/dd-trace/src/dogstatsd.js +12 -4
  30. package/packages/dd-trace/src/external-logger/src/index.js +4 -0
  31. package/packages/dd-trace/src/lambda/handler.js +3 -15
  32. package/packages/dd-trace/src/opentelemetry/span.js +1 -0
  33. package/packages/dd-trace/src/opentracing/span.js +32 -0
  34. package/packages/dd-trace/src/opentracing/tracer.js +3 -1
  35. package/packages/dd-trace/src/plugins/index.js +1 -0
  36. package/packages/dd-trace/src/plugins/outbound.js +58 -1
  37. package/packages/dd-trace/src/plugins/tracing.js +2 -1
  38. package/packages/dd-trace/src/plugins/util/exec.js +2 -0
  39. package/packages/dd-trace/src/plugins/util/git.js +4 -8
  40. package/packages/dd-trace/src/profiling/config.js +2 -0
  41. package/packages/dd-trace/src/profiling/profiler.js +8 -6
  42. package/packages/dd-trace/src/service-naming/schemas/v0/storage.js +34 -1
  43. package/packages/dd-trace/src/service-naming/schemas/v1/storage.js +31 -0
  44. package/packages/dd-trace/src/telemetry/index.js +3 -0
  45. package/packages/dd-trace/src/telemetry/metrics.js +225 -0
package/index.d.ts CHANGED
@@ -1450,6 +1450,20 @@ declare namespace plugins {
1450
1450
  };
1451
1451
  }
1452
1452
 
1453
+ /**
1454
+ * This plugin automatically instruments the
1455
+ * [openai](https://platform.openai.com/docs/api-reference?lang=node.js) module.
1456
+ *
1457
+ * Note that for logs to work you'll need to set the `DD_API_KEY` environment variable.
1458
+ * You'll also need to adjust any firewall settings to allow the tracer to communicate
1459
+ * with `http-intake.logs.datadoghq.com`.
1460
+ *
1461
+ * Note that for metrics to work you'll need to enable
1462
+ * [DogStatsD](https://docs.datadoghq.com/developers/dogstatsd/?tab=hostagent#setup)
1463
+ * in the agent.
1464
+ */
1465
+ interface openai extends Instrumentation {}
1466
+
1453
1467
  /**
1454
1468
  * This plugin automatically instruments the
1455
1469
  * [opensearch](https://github.com/opensearch-project/opensearch-js) module.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dd-trace",
3
- "version": "5.0.0-pre-e4b9a26",
3
+ "version": "5.0.0-pre-0fb796c",
4
4
  "description": "Datadog APM tracing client for JavaScript",
5
5
  "main": "index.js",
6
6
  "typings": "index.d.ts",
@@ -70,7 +70,7 @@
70
70
  "@datadog/native-iast-rewriter": "2.0.1",
71
71
  "@datadog/native-iast-taint-tracking": "^1.5.0",
72
72
  "@datadog/native-metrics": "^2.0.0",
73
- "@datadog/pprof": "2.2.2",
73
+ "@datadog/pprof": "2.2.3",
74
74
  "@datadog/sketches-js": "^2.1.0",
75
75
  "@opentelemetry/api": "^1.0.0",
76
76
  "@opentelemetry/core": "^1.14.0",
@@ -69,6 +69,7 @@ module.exports = {
69
69
  'net': () => require('../net'),
70
70
  'next': () => require('../next'),
71
71
  'oracledb': () => require('../oracledb'),
72
+ 'openai': () => require('../openai'),
72
73
  'paperplane': () => require('../paperplane'),
73
74
  'pg': () => require('../pg'),
74
75
  'pino': () => require('../pino'),
@@ -0,0 +1,50 @@
1
+ 'use strict'
2
+
3
+ const {
4
+ channel,
5
+ addHook
6
+ } = require('./helpers/instrument')
7
+ const shimmer = require('../../datadog-shimmer')
8
+
9
+ const startCh = channel('apm:openai:request:start')
10
+ const finishCh = channel('apm:openai:request:finish')
11
+ const errorCh = channel('apm:openai:request:error')
12
+
13
+ addHook({ name: 'openai', file: 'dist/api.js', versions: ['>=3.0.0'] }, exports => {
14
+ const methodNames = Object.getOwnPropertyNames(exports.OpenAIApi.prototype)
15
+ methodNames.shift() // remove leading 'constructor' method
16
+
17
+ for (const methodName of methodNames) {
18
+ shimmer.wrap(exports.OpenAIApi.prototype, methodName, fn => function () {
19
+ if (!startCh.hasSubscribers) {
20
+ return fn.apply(this, arguments)
21
+ }
22
+
23
+ startCh.publish({
24
+ methodName,
25
+ args: arguments,
26
+ basePath: this.basePath,
27
+ apiKey: this.configuration.apiKey
28
+ })
29
+
30
+ return fn.apply(this, arguments)
31
+ .then((response) => {
32
+ finishCh.publish({
33
+ headers: response.headers,
34
+ body: response.data,
35
+ path: response.request.path,
36
+ method: response.request.method
37
+ })
38
+
39
+ return response
40
+ })
41
+ .catch((err) => {
42
+ errorCh.publish({ err })
43
+
44
+ throw err
45
+ })
46
+ })
47
+ }
48
+
49
+ return exports
50
+ })
@@ -12,8 +12,8 @@ class CassandraDriverPlugin extends DatabasePlugin {
12
12
  query = combine(query)
13
13
  }
14
14
 
15
- this.startSpan('cassandra.query', {
16
- service: this.config.service,
15
+ this.startSpan(this.operationName(), {
16
+ service: this.serviceName(this.config, this.system),
17
17
  resource: trim(query, 5000),
18
18
  type: 'cassandra',
19
19
  kind: 'client',
@@ -33,7 +33,7 @@ class DNSLookupPlugin extends ClientPlugin {
33
33
  span.setTag('dns.address', result)
34
34
  }
35
35
 
36
- span.finish()
36
+ super.finish()
37
37
  }
38
38
  }
39
39
 
@@ -8,8 +8,8 @@ class ElasticsearchPlugin extends DatabasePlugin {
8
8
  start ({ params }) {
9
9
  const body = getBody(params.body || params.bulkBody)
10
10
 
11
- this.startSpan(`${this.system}.query`, {
12
- service: this.config.service,
11
+ this.startSpan(this.operationName(), {
12
+ service: this.serviceName(this.config),
13
13
  resource: `${params.method} ${quantizePath(params.path)}`,
14
14
  type: 'elasticsearch',
15
15
  kind: 'client',
@@ -32,7 +32,7 @@ class GoogleCloudPubsubConsumerPlugin extends ConsumerPlugin {
32
32
  span.setTag('pubsub.ack', 1)
33
33
  }
34
34
 
35
- span.finish()
35
+ super.finish()
36
36
  }
37
37
  }
38
38
 
@@ -32,7 +32,7 @@ class GraphQLExecutePlugin extends TracingPlugin {
32
32
  finish ({ res, args }) {
33
33
  const span = this.activeSpan
34
34
  this.config.hooks.execute(span, args, res)
35
- span.finish()
35
+ super.finish()
36
36
  }
37
37
  }
38
38
 
@@ -25,7 +25,7 @@ class GraphQLParsePlugin extends TracingPlugin {
25
25
 
26
26
  this.config.hooks.parse(span, source, document)
27
27
 
28
- span.finish()
28
+ super.finish()
29
29
  }
30
30
  }
31
31
 
@@ -56,11 +56,6 @@ class GraphQLResolvePlugin extends TracingPlugin {
56
56
  }
57
57
  }
58
58
 
59
- finish (finishTime) {
60
- const span = this.activeSpan
61
- span.finish(finishTime)
62
- }
63
-
64
59
  constructor (...args) {
65
60
  super(...args)
66
61
 
@@ -21,7 +21,7 @@ class GraphQLValidatePlugin extends TracingPlugin {
21
21
  finish ({ document, errors }) {
22
22
  const span = this.activeSpan
23
23
  this.config.hooks.validate(span, document, errors)
24
- span.finish()
24
+ super.finish()
25
25
  }
26
26
  }
27
27
 
@@ -57,7 +57,7 @@ class GrpcClientPlugin extends ClientPlugin {
57
57
  addMetadataTags(span, metadata, metadataFilter, 'response')
58
58
  }
59
59
 
60
- span.finish()
60
+ super.finish()
61
61
  }
62
62
 
63
63
  configure (config) {
@@ -68,7 +68,7 @@ class GrpcServerPlugin extends ServerPlugin {
68
68
  addMetadataTags(span, trailer, metadataFilter, 'response')
69
69
  }
70
70
 
71
- span.finish()
71
+ super.finish()
72
72
  }
73
73
 
74
74
  configure (config) {
@@ -87,7 +87,7 @@ class HttpClientPlugin extends ClientPlugin {
87
87
  addRequestHeaders(req, span, this.config)
88
88
 
89
89
  this.config.hooks.request(span, req, res)
90
- span.finish()
90
+ super.finish()
91
91
  }
92
92
 
93
93
  error (err) {
@@ -1,63 +1,67 @@
1
1
  'use strict'
2
2
 
3
- const Plugin = require('../../dd-trace/src/plugins/plugin')
3
+ const ServerPlugin = require('../../dd-trace/src/plugins/server')
4
4
  const { storage } = require('../../datadog-core')
5
5
  const web = require('../../dd-trace/src/plugins/util/web')
6
6
  const { incomingHttpRequestStart, incomingHttpRequestEnd } = require('../../dd-trace/src/appsec/channels')
7
7
  const { COMPONENT } = require('../../dd-trace/src/constants')
8
8
 
9
- class HttpServerPlugin extends Plugin {
9
+ class HttpServerPlugin extends ServerPlugin {
10
10
  static get id () {
11
11
  return 'http'
12
12
  }
13
13
 
14
14
  constructor (...args) {
15
15
  super(...args)
16
-
17
16
  this._parentStore = undefined
17
+ this.addTraceSub('exit', message => this.exit(message))
18
+ }
19
+
20
+ addTraceSub (eventName, handler) {
21
+ this.addSub(`apm:${this.constructor.id}:server:${this.operation}:${eventName}`, handler)
22
+ }
18
23
 
19
- this.addSub('apm:http:server:request:start', ({ req, res, abortController }) => {
20
- const store = storage.getStore()
21
- const span = web.startSpan(this.tracer, this.config, req, res, 'web.request')
24
+ start ({ req, res, abortController }) {
25
+ const store = storage.getStore()
26
+ const span = web.startSpan(this.tracer, this.config, req, res, 'web.request')
22
27
 
23
- span.setTag(COMPONENT, this.constructor.id)
28
+ span.setTag(COMPONENT, this.constructor.id)
24
29
 
25
- this._parentStore = store
26
- this.enter(span, { ...store, req, res })
30
+ this._parentStore = store
31
+ this.enter(span, { ...store, req, res })
27
32
 
28
- const context = web.getContext(req)
33
+ const context = web.getContext(req)
29
34
 
30
- if (!context.instrumented) {
31
- context.res.writeHead = web.wrapWriteHead(context)
32
- context.instrumented = true
33
- }
35
+ if (!context.instrumented) {
36
+ context.res.writeHead = web.wrapWriteHead(context)
37
+ context.instrumented = true
38
+ }
34
39
 
35
- if (incomingHttpRequestStart.hasSubscribers) {
36
- incomingHttpRequestStart.publish({ req, res, abortController }) // TODO: no need to make a new object here
37
- }
38
- })
40
+ if (incomingHttpRequestStart.hasSubscribers) {
41
+ incomingHttpRequestStart.publish({ req, res, abortController }) // TODO: no need to make a new object here
42
+ }
43
+ }
39
44
 
40
- this.addSub('apm:http:server:request:error', (error) => {
41
- web.addError(error)
42
- })
45
+ error (error) {
46
+ web.addError(error)
47
+ }
43
48
 
44
- this.addSub('apm:http:server:request:exit', ({ req }) => {
45
- const span = this._parentStore && this._parentStore.span
46
- this.enter(span, this._parentStore)
47
- this._parentStore = undefined
48
- })
49
+ finish ({ req }) {
50
+ const context = web.getContext(req)
49
51
 
50
- this.addSub('apm:http:server:request:finish', ({ req }) => {
51
- const context = web.getContext(req)
52
+ if (!context || !context.res) return // Not created by a http.Server instance.
52
53
 
53
- if (!context || !context.res) return // Not created by a http.Server instance.
54
+ if (incomingHttpRequestEnd.hasSubscribers) {
55
+ incomingHttpRequestEnd.publish({ req, res: context.res })
56
+ }
54
57
 
55
- if (incomingHttpRequestEnd.hasSubscribers) {
56
- incomingHttpRequestEnd.publish({ req, res: context.res })
57
- }
58
+ web.finishAll(context)
59
+ }
58
60
 
59
- web.finishAll(context)
60
- })
61
+ exit ({ req }) {
62
+ const span = this._parentStore && this._parentStore.span
63
+ this.enter(span, this._parentStore)
64
+ this._parentStore = undefined
61
65
  }
62
66
 
63
67
  configure (config) {
@@ -93,11 +93,6 @@ class Http2ClientPlugin extends ClientPlugin {
93
93
  this.enter(span, store)
94
94
  }
95
95
 
96
- finish () {
97
- const span = storage.getStore().span
98
- span.finish()
99
- }
100
-
101
96
  configure (config) {
102
97
  return super.configure(normalizeConfig(config))
103
98
  }
@@ -2,46 +2,46 @@
2
2
 
3
3
  // Plugin temporarily disabled. See https://github.com/DataDog/dd-trace-js/issues/312
4
4
 
5
- const Plugin = require('../../dd-trace/src/plugins/plugin')
5
+ const ServerPlugin = require('../../dd-trace/src/plugins/server')
6
6
  const { storage } = require('../../datadog-core')
7
7
  const web = require('../../dd-trace/src/plugins/util/web')
8
8
  const { COMPONENT } = require('../../dd-trace/src/constants')
9
9
 
10
- class Http2ServerPlugin extends Plugin {
10
+ class Http2ServerPlugin extends ServerPlugin {
11
11
  static get id () {
12
12
  return 'http2'
13
13
  }
14
14
 
15
- constructor (...args) {
16
- super(...args)
15
+ addTraceSub (eventName, handler) {
16
+ this.addSub(`apm:${this.constructor.id}:server:${this.operation}:${eventName}`, handler)
17
+ }
17
18
 
18
- this.addSub('apm:http2:server:request:start', ({ req, res }) => {
19
- const store = storage.getStore()
20
- const span = web.startSpan(this.tracer, this.config, req, res, 'web.request')
19
+ start ({ req, res }) {
20
+ const store = storage.getStore()
21
+ const span = web.startSpan(this.tracer, this.config, req, res, 'web.request')
21
22
 
22
- span.setTag(COMPONENT, this.constructor.id)
23
+ span.setTag(COMPONENT, this.constructor.id)
23
24
 
24
- this.enter(span, { ...store, req, res })
25
+ this.enter(span, { ...store, req, res })
25
26
 
26
- const context = web.getContext(req)
27
+ const context = web.getContext(req)
27
28
 
28
- if (!context.instrumented) {
29
- context.res.writeHead = web.wrapWriteHead(context)
30
- context.instrumented = true
31
- }
32
- })
29
+ if (!context.instrumented) {
30
+ context.res.writeHead = web.wrapWriteHead(context)
31
+ context.instrumented = true
32
+ }
33
+ }
33
34
 
34
- this.addSub('apm:http2:server:request:error', (error) => {
35
- web.addError(error)
36
- })
35
+ finish ({ req }) {
36
+ const context = web.getContext(req)
37
37
 
38
- this.addSub('apm:http2:server:request:finish', ({ req }) => {
39
- const context = web.getContext(req)
38
+ if (!context || !context.res) return // Not created by a http.Server instance.
40
39
 
41
- if (!context || !context.res) return // Not created by a http.Server instance.
40
+ web.finishAll(context)
41
+ }
42
42
 
43
- web.finishAll(context)
44
- })
43
+ error (error) {
44
+ web.addError(error)
45
45
  }
46
46
 
47
47
  configure (config) {
@@ -29,7 +29,7 @@ class MoleculerClientPlugin extends ClientPlugin {
29
29
  span.addTags(moleculerTags(broker, ctx, this.config))
30
30
  }
31
31
 
32
- span.finish()
32
+ super.finish()
33
33
  }
34
34
  }
35
35
 
@@ -10,8 +10,8 @@ class MongodbCorePlugin extends DatabasePlugin {
10
10
  const query = getQuery(ops)
11
11
  const resource = truncate(getResource(this, ns, query, name))
12
12
 
13
- this.startSpan('mongodb.query', {
14
- service: this.config.service,
13
+ this.startSpan(this.operationName(), {
14
+ service: this.serviceName(this.config),
15
15
  resource,
16
16
  type: 'mongodb',
17
17
  kind: 'client',