dd-trace 5.80.0 → 5.81.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.
- package/LICENSE-3rdparty.csv +79 -88
- package/ext/tags.d.ts +1 -0
- package/ext/tags.js +1 -0
- package/index.d.ts +35 -35
- package/loader-hook.mjs +10 -3
- package/package.json +22 -40
- package/packages/datadog-esbuild/index.js +36 -19
- package/packages/datadog-instrumentations/index.js +1 -0
- package/packages/datadog-instrumentations/src/anthropic.js +12 -0
- package/packages/datadog-instrumentations/src/aws-sdk.js +5 -1
- package/packages/datadog-instrumentations/src/cucumber.js +2 -2
- package/packages/datadog-instrumentations/src/find-my-way.js +6 -5
- package/packages/datadog-instrumentations/src/google-genai.js +120 -0
- package/packages/datadog-instrumentations/src/graphql.js +20 -0
- package/packages/datadog-instrumentations/src/helpers/hooks.js +1 -0
- package/packages/datadog-instrumentations/src/helpers/instrument.js +10 -0
- package/packages/datadog-instrumentations/src/helpers/register.js +6 -1
- package/packages/datadog-instrumentations/src/helpers/rewriter/compiler.js +27 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/index.js +152 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/index.js +5 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/langchain.js +237 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/loader.js +9 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/loader.mjs +11 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/transforms.js +139 -0
- package/packages/datadog-instrumentations/src/langchain.js +3 -109
- package/packages/datadog-instrumentations/src/mocha/main.js +1 -1
- package/packages/datadog-instrumentations/src/mysql2.js +1 -1
- package/packages/datadog-instrumentations/src/playwright.js +45 -16
- package/packages/datadog-instrumentations/src/router.js +1 -1
- package/packages/datadog-instrumentations/src/selenium.js +3 -1
- package/packages/datadog-instrumentations/src/ws.js +35 -17
- package/packages/datadog-plugin-child_process/src/scrub-cmd-params.js +1 -1
- package/packages/datadog-plugin-cypress/src/cypress-plugin.js +23 -2
- package/packages/datadog-plugin-cypress/src/plugin.js +1 -1
- package/packages/datadog-plugin-cypress/src/support.js +73 -31
- package/packages/datadog-plugin-google-genai/src/index.js +17 -0
- package/packages/datadog-plugin-google-genai/src/tracing.js +41 -0
- package/packages/datadog-plugin-graphql/src/tools/transforms.js +5 -4
- package/packages/datadog-plugin-jest/src/util.js +1 -1
- package/packages/datadog-plugin-langchain/src/tracing.js +7 -3
- package/packages/datadog-plugin-next/src/index.js +11 -3
- package/packages/dd-trace/src/aiguard/sdk.js +18 -10
- package/packages/dd-trace/src/appsec/api_security_sampler.js +1 -1
- package/packages/dd-trace/src/appsec/iast/overhead-controller.js +1 -1
- package/packages/dd-trace/src/appsec/iast/taint-tracking/rewriter-esm.mjs +1 -1
- package/packages/dd-trace/src/appsec/iast/taint-tracking/rewriter.js +1 -2
- package/packages/dd-trace/src/appsec/iast/vulnerability-reporter.js +1 -1
- package/packages/dd-trace/src/appsec/reporter.js +0 -4
- package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/worker/index.js +4 -8
- package/packages/dd-trace/src/ci-visibility/test-management/get-test-management-tests.js +4 -2
- package/packages/dd-trace/src/config.js +81 -7
- package/packages/dd-trace/src/config_defaults.js +14 -2
- package/packages/dd-trace/src/datastreams/encoding.js +23 -6
- package/packages/dd-trace/src/datastreams/pathway.js +40 -1
- package/packages/dd-trace/src/datastreams/processor.js +1 -1
- package/packages/dd-trace/src/datastreams/schemas/schema_builder.js +1 -1
- package/packages/dd-trace/src/debugger/devtools_client/breakpoints.js +15 -5
- package/packages/dd-trace/src/debugger/devtools_client/condition.js +1 -1
- package/packages/dd-trace/src/debugger/devtools_client/config.js +2 -0
- package/packages/dd-trace/src/debugger/devtools_client/index.js +30 -15
- package/packages/dd-trace/src/debugger/devtools_client/inspector_promises_polyfill.js +2 -0
- package/packages/dd-trace/src/debugger/devtools_client/json-buffer.js +24 -18
- package/packages/dd-trace/src/debugger/devtools_client/send.js +18 -8
- package/packages/dd-trace/src/debugger/devtools_client/snapshot/collector.js +103 -15
- package/packages/dd-trace/src/debugger/devtools_client/snapshot/constants.js +25 -0
- package/packages/dd-trace/src/debugger/devtools_client/snapshot/index.js +56 -25
- package/packages/dd-trace/src/debugger/devtools_client/snapshot/processor.js +64 -23
- package/packages/dd-trace/src/debugger/devtools_client/snapshot/symbols.js +3 -1
- package/packages/dd-trace/src/debugger/devtools_client/snapshot-pruner.js +404 -0
- package/packages/dd-trace/src/debugger/devtools_client/source-maps.js +1 -1
- package/packages/dd-trace/src/debugger/devtools_client/state.js +7 -2
- package/packages/dd-trace/src/debugger/devtools_client/status.js +1 -1
- package/packages/dd-trace/src/debugger/index.js +1 -1
- package/packages/dd-trace/src/encode/span-stats.js +7 -1
- package/packages/dd-trace/src/histogram.js +1 -1
- package/packages/dd-trace/src/id.js +60 -0
- package/packages/dd-trace/src/lambda/runtime/ritm.js +1 -1
- package/packages/dd-trace/src/llmobs/constants/tags.js +1 -0
- package/packages/dd-trace/src/llmobs/plugins/genai/index.js +104 -0
- package/packages/dd-trace/src/llmobs/plugins/genai/util.js +486 -0
- package/packages/dd-trace/src/llmobs/plugins/langchain/index.js +2 -2
- package/packages/dd-trace/src/llmobs/plugins/{openai.js → openai/index.js} +48 -6
- package/packages/dd-trace/src/llmobs/plugins/openai/utils.js +114 -0
- package/packages/dd-trace/src/llmobs/sdk.js +5 -0
- package/packages/dd-trace/src/llmobs/span_processor.js +6 -1
- package/packages/dd-trace/src/llmobs/tagger.js +4 -0
- package/packages/dd-trace/src/opentelemetry/logs/index.js +2 -2
- package/packages/dd-trace/src/opentelemetry/logs/logger.js +3 -2
- package/packages/dd-trace/src/opentelemetry/logs/otlp_http_log_exporter.js +5 -3
- package/packages/dd-trace/src/opentelemetry/logs/otlp_transformer.js +8 -8
- package/packages/dd-trace/src/opentelemetry/metrics/constants.js +34 -0
- package/packages/dd-trace/src/opentelemetry/metrics/index.js +81 -0
- package/packages/dd-trace/src/opentelemetry/metrics/instruments.js +225 -0
- package/packages/dd-trace/src/opentelemetry/metrics/meter.js +171 -0
- package/packages/dd-trace/src/opentelemetry/metrics/meter_provider.js +54 -0
- package/packages/dd-trace/src/opentelemetry/metrics/otlp_http_metric_exporter.js +62 -0
- package/packages/dd-trace/src/opentelemetry/metrics/otlp_transformer.js +251 -0
- package/packages/dd-trace/src/opentelemetry/metrics/periodic_metric_reader.js +532 -0
- package/packages/dd-trace/src/opentelemetry/otlp/otlp_http_exporter_base.js +10 -18
- package/packages/dd-trace/src/opentelemetry/otlp/otlp_transformer_base.js +36 -22
- package/packages/dd-trace/src/opentelemetry/otlp/protobuf_loader.js +1 -1
- package/packages/dd-trace/src/opentelemetry/span.js +1 -1
- package/packages/dd-trace/src/opentelemetry/tracer.js +1 -1
- package/packages/dd-trace/src/opentelemetry/tracer_provider.js +1 -1
- package/packages/dd-trace/src/payload-tagging/index.js +2 -2
- package/packages/dd-trace/src/plugin_manager.js +4 -2
- package/packages/dd-trace/src/plugins/index.js +1 -0
- package/packages/dd-trace/src/plugins/util/test.js +3 -3
- package/packages/dd-trace/src/plugins/util/url.js +119 -1
- package/packages/dd-trace/src/plugins/util/web.js +10 -41
- package/packages/dd-trace/src/process-tags/index.js +81 -0
- package/packages/dd-trace/src/profiling/config.js +1 -1
- package/packages/dd-trace/src/profiling/exporters/agent.js +1 -1
- package/packages/dd-trace/src/profiling/profilers/events.js +10 -1
- package/packages/dd-trace/src/proxy.js +5 -0
- package/packages/dd-trace/src/rate_limiter.js +1 -1
- package/packages/dd-trace/src/remote_config/manager.js +1 -1
- package/packages/dd-trace/src/ritm.js +1 -1
- package/packages/dd-trace/src/service-naming/schemas/v0/web.js +4 -0
- package/packages/dd-trace/src/service-naming/schemas/v1/web.js +4 -0
- package/packages/dd-trace/src/span_format.js +9 -4
- package/packages/dd-trace/src/span_processor.js +8 -3
- package/packages/dd-trace/src/span_stats.js +15 -4
- package/packages/dd-trace/src/spanleak.js +1 -1
- package/packages/dd-trace/src/supported-configurations.json +13 -0
- package/packages/dd-trace/src/telemetry/dependencies.js +1 -1
- package/packages/dd-trace/src/telemetry/telemetry.js +11 -2
- package/vendor/dist/@datadog/sketches-js/LICENSE +39 -0
- package/vendor/dist/@datadog/sketches-js/index.js +1 -0
- package/vendor/dist/@datadog/source-map/LICENSE +28 -0
- package/vendor/dist/@datadog/source-map/index.js +1 -0
- package/vendor/dist/@isaacs/ttlcache/LICENSE +55 -0
- package/vendor/dist/@isaacs/ttlcache/index.js +1 -0
- package/vendor/dist/@opentelemetry/core/LICENSE +201 -0
- package/vendor/dist/@opentelemetry/core/index.js +1 -0
- package/vendor/dist/@opentelemetry/resources/LICENSE +201 -0
- package/vendor/dist/@opentelemetry/resources/index.js +1 -0
- package/vendor/dist/astring/LICENSE +19 -0
- package/vendor/dist/astring/index.js +1 -0
- package/vendor/dist/crypto-randomuuid/index.js +1 -0
- package/vendor/dist/escape-string-regexp/LICENSE +9 -0
- package/vendor/dist/escape-string-regexp/index.js +1 -0
- package/vendor/dist/esquery/LICENSE +24 -0
- package/vendor/dist/esquery/index.js +1 -0
- package/vendor/dist/ignore/LICENSE +21 -0
- package/vendor/dist/ignore/index.js +1 -0
- package/vendor/dist/istanbul-lib-coverage/LICENSE +24 -0
- package/vendor/dist/istanbul-lib-coverage/index.js +1 -0
- package/vendor/dist/jest-docblock/LICENSE +21 -0
- package/vendor/dist/jest-docblock/index.js +1 -0
- package/vendor/dist/jsonpath-plus/LICENSE +22 -0
- package/vendor/dist/jsonpath-plus/index.js +1 -0
- package/vendor/dist/limiter/LICENSE +19 -0
- package/vendor/dist/limiter/index.js +1 -0
- package/vendor/dist/lodash.sortby/LICENSE +47 -0
- package/vendor/dist/lodash.sortby/index.js +1 -0
- package/vendor/dist/lru-cache/LICENSE +15 -0
- package/vendor/dist/lru-cache/index.js +1 -0
- package/vendor/dist/meriyah/LICENSE +7 -0
- package/vendor/dist/meriyah/index.js +1 -0
- package/vendor/dist/module-details-from-path/LICENSE +21 -0
- package/vendor/dist/module-details-from-path/index.js +1 -0
- package/vendor/dist/mutexify/promise/LICENSE +21 -0
- package/vendor/dist/mutexify/promise/index.js +1 -0
- package/vendor/dist/opentracing/LICENSE +201 -0
- package/vendor/dist/opentracing/binary_carrier.d.ts +11 -0
- package/vendor/dist/opentracing/constants.d.ts +61 -0
- package/vendor/dist/opentracing/examples/demo/demo.d.ts +2 -0
- package/vendor/dist/opentracing/ext/tags.d.ts +90 -0
- package/vendor/dist/opentracing/functions.d.ts +20 -0
- package/vendor/dist/opentracing/global_tracer.d.ts +14 -0
- package/vendor/dist/opentracing/index.d.ts +12 -0
- package/vendor/dist/opentracing/index.js +1 -0
- package/vendor/dist/opentracing/mock_tracer/index.d.ts +5 -0
- package/vendor/dist/opentracing/mock_tracer/mock_context.d.ts +13 -0
- package/vendor/dist/opentracing/mock_tracer/mock_report.d.ts +16 -0
- package/vendor/dist/opentracing/mock_tracer/mock_span.d.ts +50 -0
- package/vendor/dist/opentracing/mock_tracer/mock_tracer.d.ts +26 -0
- package/vendor/dist/opentracing/noop.d.ts +8 -0
- package/vendor/dist/opentracing/reference.d.ts +33 -0
- package/vendor/dist/opentracing/span.d.ts +147 -0
- package/vendor/dist/opentracing/span_context.d.ts +26 -0
- package/vendor/dist/opentracing/test/api_compatibility.d.ts +16 -0
- package/vendor/dist/opentracing/test/mocktracer_implemenation.d.ts +3 -0
- package/vendor/dist/opentracing/test/noop_implementation.d.ts +4 -0
- package/vendor/dist/opentracing/test/opentracing_api.d.ts +3 -0
- package/vendor/dist/opentracing/test/unittest.d.ts +2 -0
- package/vendor/dist/opentracing/tracer.d.ts +127 -0
- package/vendor/dist/path-to-regexp/LICENSE +21 -0
- package/vendor/dist/path-to-regexp/index.js +1 -0
- package/vendor/dist/pprof-format/LICENSE +8 -0
- package/vendor/dist/pprof-format/index.js +1 -0
- package/vendor/dist/protobufjs/LICENSE +39 -0
- package/vendor/dist/protobufjs/index.js +1 -0
- package/vendor/dist/protobufjs/minimal/LICENSE +39 -0
- package/vendor/dist/protobufjs/minimal/index.js +1 -0
- package/vendor/dist/retry/LICENSE +21 -0
- package/vendor/dist/retry/index.js +1 -0
- package/vendor/dist/rfdc/LICENSE +15 -0
- package/vendor/dist/rfdc/index.js +1 -0
- package/vendor/dist/semifies/LICENSE +201 -0
- package/vendor/dist/semifies/index.js +1 -0
- package/vendor/dist/shell-quote/LICENSE +24 -0
- package/vendor/dist/shell-quote/index.js +1 -0
- package/vendor/dist/source-map/LICENSE +28 -0
- package/vendor/dist/source-map/index.js +1 -0
- package/vendor/dist/source-map/lib/util/LICENSE +28 -0
- package/vendor/dist/source-map/lib/util/index.js +1 -0
- package/vendor/dist/source-map/mappings.wasm +0 -0
- package/vendor/dist/tlhunter-sorted-set/LICENSE +21 -0
- package/vendor/dist/tlhunter-sorted-set/index.js +1 -0
- package/vendor/dist/ttl-set/LICENSE +21 -0
- package/vendor/dist/ttl-set/index.js +1 -0
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { VERSION: packageVersion } = require('../../../../../version')
|
|
4
|
+
const {
|
|
5
|
+
Counter, UpDownCounter, Histogram, Gauge, ObservableGauge, ObservableCounter, ObservableUpDownCounter
|
|
6
|
+
} = require('./instruments')
|
|
7
|
+
const log = require('../../log')
|
|
8
|
+
const { METRIC_TYPES } = require('./constants')
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @typedef {import('@opentelemetry/api').MetricOptions} MetricOptions
|
|
12
|
+
* @typedef {import('@opentelemetry/core').InstrumentationScope} InstrumentationScope
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Meter provides methods to create metric instruments.
|
|
17
|
+
*
|
|
18
|
+
* This implementation follows the OpenTelemetry JavaScript API Meter:
|
|
19
|
+
* https://open-telemetry.github.io/opentelemetry-js/interfaces/_opentelemetry_api._opentelemetry_api.Meter.html
|
|
20
|
+
*
|
|
21
|
+
* @class Meter
|
|
22
|
+
*/
|
|
23
|
+
class Meter {
|
|
24
|
+
#instrumentationScope
|
|
25
|
+
#instruments = new Map()
|
|
26
|
+
/**
|
|
27
|
+
* Creates a new Meter instance.
|
|
28
|
+
*
|
|
29
|
+
* @param {MeterProvider} meterProvider - Parent meter provider
|
|
30
|
+
* @param {InstrumentationScope} instrumentationScope - Instrumentation scope information
|
|
31
|
+
* @param {string} [instrumentationScope.name] - Meter name (defaults to 'dd-trace-js')
|
|
32
|
+
* @param {string} [instrumentationScope.version] - Meter version (defaults to tracer version)
|
|
33
|
+
* @param {string} [instrumentationScope.schemaUrl] - Schema URL
|
|
34
|
+
* @param {Object} [instrumentationScope.attributes] - Attributes for the instrumentation scope
|
|
35
|
+
*/
|
|
36
|
+
constructor (
|
|
37
|
+
meterProvider,
|
|
38
|
+
{ name = 'dd-trace-js', version = packageVersion, schemaUrl = '', attributes = {} } = {}
|
|
39
|
+
) {
|
|
40
|
+
this.meterProvider = meterProvider
|
|
41
|
+
this.#instrumentationScope = {
|
|
42
|
+
name,
|
|
43
|
+
version,
|
|
44
|
+
schemaUrl,
|
|
45
|
+
attributes,
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Gets an existing instrument or creates a new one if it doesn't exist.
|
|
51
|
+
* Instruments are cached by type and normalized (lowercase) name.
|
|
52
|
+
*
|
|
53
|
+
*
|
|
54
|
+
* @param {string} name - Instrument name (will be normalized to lowercase)
|
|
55
|
+
* @param {string} type - Instrument type (e.g., 'counter', 'histogram', 'gauge')
|
|
56
|
+
* @param {Function} InstrumentClass - Constructor for the instrument type
|
|
57
|
+
* @param {MetricOptions} [options] - Instrument options (description, unit, etc.)
|
|
58
|
+
* @returns {Instrument} The instrument instance (new or cached)
|
|
59
|
+
*/
|
|
60
|
+
#getOrCreateInstrument (name, type, InstrumentClass, options) {
|
|
61
|
+
const normalizedName = name.toLowerCase()
|
|
62
|
+
const key = `${type}:${normalizedName}`
|
|
63
|
+
let instrument = this.#instruments.get(key)
|
|
64
|
+
if (!instrument) {
|
|
65
|
+
instrument = new InstrumentClass(
|
|
66
|
+
normalizedName, options, this.#instrumentationScope, this.meterProvider.reader
|
|
67
|
+
)
|
|
68
|
+
this.#instruments.set(key, instrument)
|
|
69
|
+
}
|
|
70
|
+
return instrument
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Creates a Counter instrument.
|
|
75
|
+
*
|
|
76
|
+
* @param {string} name - Instrument name (case-insensitive)
|
|
77
|
+
* @param {MetricOptions} [options] - Instrument options
|
|
78
|
+
* @returns {Counter} Counter instrument
|
|
79
|
+
*/
|
|
80
|
+
createCounter (name, options = {}) {
|
|
81
|
+
return this.#getOrCreateInstrument(name, METRIC_TYPES.COUNTER, Counter, options)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Creates an UpDownCounter instrument.
|
|
86
|
+
*
|
|
87
|
+
* @param {string} name - Instrument name
|
|
88
|
+
* @param {MetricOptions} [options] - Instrument options
|
|
89
|
+
* @returns {UpDownCounter} UpDownCounter instrument
|
|
90
|
+
*/
|
|
91
|
+
createUpDownCounter (name, options = {}) {
|
|
92
|
+
return this.#getOrCreateInstrument(name, METRIC_TYPES.UPDOWNCOUNTER, UpDownCounter, options)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Creates a Histogram instrument.
|
|
97
|
+
*
|
|
98
|
+
* @param {string} name - Instrument name (case-insensitive)
|
|
99
|
+
* @param {MetricOptions} [options] - Instrument options
|
|
100
|
+
* @returns {Histogram} Histogram instrument
|
|
101
|
+
*/
|
|
102
|
+
createHistogram (name, options = {}) {
|
|
103
|
+
return this.#getOrCreateInstrument(name, METRIC_TYPES.HISTOGRAM, Histogram, options)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Creates a Gauge instrument.
|
|
108
|
+
*
|
|
109
|
+
* @param {string} name - Instrument name (case-insensitive)
|
|
110
|
+
* @param {MetricOptions} [options] - Instrument options
|
|
111
|
+
* @returns {Gauge} Gauge instrument
|
|
112
|
+
*/
|
|
113
|
+
createGauge (name, options = {}) {
|
|
114
|
+
return this.#getOrCreateInstrument(name, METRIC_TYPES.GAUGE, Gauge, options)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Creates an ObservableGauge instrument.
|
|
119
|
+
*
|
|
120
|
+
* @param {string} name - Instrument name (case-insensitive)
|
|
121
|
+
* @param {MetricOptions} [options] - Instrument options
|
|
122
|
+
* @returns {ObservableGauge} ObservableGauge instrument
|
|
123
|
+
*/
|
|
124
|
+
createObservableGauge (name, options = {}) {
|
|
125
|
+
return this.#getOrCreateInstrument(name, METRIC_TYPES.OBSERVABLEGAUGE, ObservableGauge, options)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Creates an ObservableCounter instrument.
|
|
130
|
+
*
|
|
131
|
+
* @param {string} name - Instrument name (case-insensitive)
|
|
132
|
+
* @param {MetricOptions} [options] - Instrument options
|
|
133
|
+
* @returns {ObservableCounter} ObservableCounter instrument
|
|
134
|
+
*/
|
|
135
|
+
createObservableCounter (name, options = {}) {
|
|
136
|
+
return this.#getOrCreateInstrument(name, METRIC_TYPES.OBSERVABLECOUNTER, ObservableCounter, options)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Creates an ObservableUpDownCounter instrument.
|
|
141
|
+
*
|
|
142
|
+
* @param {string} name - Instrument name (case-insensitive)
|
|
143
|
+
* @param {MetricOptions} [options] - Instrument options
|
|
144
|
+
* @returns {ObservableUpDownCounter} ObservableUpDownCounter instrument
|
|
145
|
+
*/
|
|
146
|
+
createObservableUpDownCounter (name, options = {}) {
|
|
147
|
+
return this.#getOrCreateInstrument(name, METRIC_TYPES.OBSERVABLEUPDOWNCOUNTER, ObservableUpDownCounter, options)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Adds a batch observable callback (not implemented).
|
|
152
|
+
*
|
|
153
|
+
* @param {Function} callback - Batch observable callback
|
|
154
|
+
* @param {Array} observables - Array of observable instruments
|
|
155
|
+
*/
|
|
156
|
+
addBatchObservableCallback (callback, observables) {
|
|
157
|
+
log.warn('addBatchObservableCallback is not implemented')
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Removes a batch observable callback (not implemented).
|
|
162
|
+
*
|
|
163
|
+
* @param {Function} callback - Batch observable callback
|
|
164
|
+
* @param {Array} observables - Array of observable instruments
|
|
165
|
+
*/
|
|
166
|
+
removeBatchObservableCallback (callback, observables) {
|
|
167
|
+
log.warn('removeBatchObservableCallback is not implemented')
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
module.exports = Meter
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const Meter = require('./meter')
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {import('@opentelemetry/api').Meter} Meter
|
|
7
|
+
* @typedef {import('@opentelemetry/api').MeterOptions} MeterOptions
|
|
8
|
+
* @typedef {import('./periodic_metric_reader')} PeriodicMetricReader
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* MeterProvider is the main entry point for creating meters with a single reader for Datadog Agent export.
|
|
13
|
+
*
|
|
14
|
+
* This implementation follows the OpenTelemetry JavaScript API MeterProvider interface:
|
|
15
|
+
* https://open-telemetry.github.io/opentelemetry-js/interfaces/_opentelemetry_api._opentelemetry_api.MeterProvider.html
|
|
16
|
+
*
|
|
17
|
+
* @class MeterProvider
|
|
18
|
+
* @implements {import('@opentelemetry/api').MeterProvider}
|
|
19
|
+
*/
|
|
20
|
+
class MeterProvider {
|
|
21
|
+
#meters = new Map()
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Creates a new MeterProvider instance with a single reader for Datadog Agent export.
|
|
25
|
+
*
|
|
26
|
+
* @param {MeterOptions} [options] - MeterProvider options
|
|
27
|
+
* @param {PeriodicMetricReader} [options.reader] - Single MetricReader instance for
|
|
28
|
+
* exporting metrics to Datadog Agent
|
|
29
|
+
*/
|
|
30
|
+
constructor (options = {}) {
|
|
31
|
+
this.reader = options.reader
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Gets or creates a meter instance.
|
|
36
|
+
*
|
|
37
|
+
* @param {string} name - Meter name (case-insensitive)
|
|
38
|
+
* @param {string} [version] - Meter version
|
|
39
|
+
* @param {MeterOptions} [options] - Additional options
|
|
40
|
+
* @returns {Meter} Meter instance
|
|
41
|
+
*/
|
|
42
|
+
getMeter (name, version = '', { schemaUrl = '', attributes = {} } = {}) {
|
|
43
|
+
const normalizedName = name.toLowerCase()
|
|
44
|
+
const key = `${normalizedName}@${version}@${schemaUrl}`
|
|
45
|
+
let meter = this.#meters.get(key)
|
|
46
|
+
if (!meter) {
|
|
47
|
+
meter = new Meter(this, { name: normalizedName, version, schemaUrl, attributes })
|
|
48
|
+
this.#meters.set(key, meter)
|
|
49
|
+
}
|
|
50
|
+
return meter
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
module.exports = MeterProvider
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const OtlpHttpExporterBase = require('../otlp/otlp_http_exporter_base')
|
|
4
|
+
const OtlpTransformer = require('./otlp_transformer')
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @typedef {import('@opentelemetry/resources').Resource} Resource
|
|
8
|
+
* @typedef {import('./periodic_metric_reader').AggregatedMetric} AggregatedMetric
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* OtlpHttpMetricExporter exports metrics via OTLP over HTTP.
|
|
13
|
+
*
|
|
14
|
+
* @class OtlpHttpMetricExporter
|
|
15
|
+
*/
|
|
16
|
+
class OtlpHttpMetricExporter extends OtlpHttpExporterBase {
|
|
17
|
+
/**
|
|
18
|
+
* Creates a new OtlpHttpMetricExporter instance.
|
|
19
|
+
*
|
|
20
|
+
* @param {string} url - OTLP endpoint URL
|
|
21
|
+
* @param {string} headers - Additional HTTP headers as comma-separated key=value string
|
|
22
|
+
* @param {number} timeout - Request timeout in milliseconds
|
|
23
|
+
* @param {string} protocol - OTLP protocol (http/protobuf or http/json)
|
|
24
|
+
* @param {Resource} resource - Resource attributes
|
|
25
|
+
*/
|
|
26
|
+
constructor (url, headers, timeout, protocol, resource) {
|
|
27
|
+
super(url, headers, timeout, protocol, '/v1/metrics', 'metrics')
|
|
28
|
+
this.transformer = new OtlpTransformer(resource, protocol)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Exports metrics via OTLP over HTTP.
|
|
33
|
+
*
|
|
34
|
+
* @param {Map<string, AggregatedMetric>} metrics - Map of metric data to export
|
|
35
|
+
*
|
|
36
|
+
* @returns {void}
|
|
37
|
+
*/
|
|
38
|
+
export (metrics) {
|
|
39
|
+
if (metrics.size === 0) {
|
|
40
|
+
return
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
let dataPointCount = 0
|
|
44
|
+
for (const metric of metrics.values()) {
|
|
45
|
+
if (metric.dataPointMap) {
|
|
46
|
+
dataPointCount += metric.dataPointMap.size
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const additionalTags = [`points:${dataPointCount}`]
|
|
51
|
+
this.recordTelemetry('otel.metrics_export_attempts', 1, additionalTags)
|
|
52
|
+
|
|
53
|
+
const payload = this.transformer.transformMetrics(metrics.values())
|
|
54
|
+
this.sendPayload(payload, (result) => {
|
|
55
|
+
if (result.code === 0) {
|
|
56
|
+
this.recordTelemetry('otel.metrics_export_successes', 1, additionalTags)
|
|
57
|
+
}
|
|
58
|
+
})
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
module.exports = OtlpHttpMetricExporter
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const OtlpTransformerBase = require('../otlp/otlp_transformer_base')
|
|
4
|
+
const { getProtobufTypes } = require('../otlp/protobuf_loader')
|
|
5
|
+
const { METRIC_TYPES, TEMPORALITY } = require('./constants')
|
|
6
|
+
|
|
7
|
+
const { protoAggregationTemporality } = getProtobufTypes()
|
|
8
|
+
const AGGREGATION_TEMPORALITY_DELTA = protoAggregationTemporality.values.AGGREGATION_TEMPORALITY_DELTA
|
|
9
|
+
const AGGREGATION_TEMPORALITY_CUMULATIVE = protoAggregationTemporality.values.AGGREGATION_TEMPORALITY_CUMULATIVE
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @typedef {import('./periodic_metric_reader').AggregatedMetric} AggregatedMetric
|
|
13
|
+
* @typedef {import('./periodic_metric_reader').NumberDataPoint} NumberDataPoint
|
|
14
|
+
* @typedef {import('./periodic_metric_reader').HistogramDataPoint} HistogramDataPoint
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* OtlpTransformer transforms metrics to OTLP format.
|
|
19
|
+
*
|
|
20
|
+
* This implementation follows the OTLP Metrics v1.7.0 Data Model specification:
|
|
21
|
+
* https://opentelemetry.io/docs/specs/otlp/#metrics-data-model
|
|
22
|
+
*
|
|
23
|
+
* @class OtlpTransformer
|
|
24
|
+
* @augments OtlpTransformerBase
|
|
25
|
+
*/
|
|
26
|
+
class OtlpTransformer extends OtlpTransformerBase {
|
|
27
|
+
/**
|
|
28
|
+
* Creates a new OtlpTransformer instance.
|
|
29
|
+
*
|
|
30
|
+
* @param {import('@opentelemetry/api').Attributes} resourceAttributes - Resource attributes
|
|
31
|
+
* @param {string} protocol - OTLP protocol (http/protobuf or http/json)
|
|
32
|
+
*/
|
|
33
|
+
constructor (resourceAttributes, protocol) {
|
|
34
|
+
super(resourceAttributes, protocol, 'metrics')
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Transforms metrics to OTLP format based on the configured protocol.
|
|
39
|
+
* @param {Iterable<AggregatedMetric>} metrics - Iterable of metric data to transform
|
|
40
|
+
* @returns {Buffer} Transformed metrics in the appropriate format
|
|
41
|
+
*/
|
|
42
|
+
transformMetrics (metrics) {
|
|
43
|
+
if (this.protocol === 'http/json') {
|
|
44
|
+
return this.#transformToJson(metrics)
|
|
45
|
+
}
|
|
46
|
+
return this.#transformToProtobuf(metrics)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Transforms metrics to protobuf format.
|
|
51
|
+
* @param {Iterable<AggregatedMetric>} metrics - Iterable of metrics to transform
|
|
52
|
+
* @returns {Buffer} Protobuf-encoded metrics
|
|
53
|
+
*
|
|
54
|
+
*/
|
|
55
|
+
#transformToProtobuf (metrics) {
|
|
56
|
+
const { protoMetricsService } = getProtobufTypes()
|
|
57
|
+
|
|
58
|
+
const metricsData = {
|
|
59
|
+
resourceMetrics: [{
|
|
60
|
+
resource: this.transformResource(),
|
|
61
|
+
scopeMetrics: this.#transformScope(metrics),
|
|
62
|
+
}]
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return this.serializeToProtobuf(protoMetricsService, metricsData)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Transforms metrics to JSON format.
|
|
70
|
+
* @param {Array} metrics - Array of metrics to transform
|
|
71
|
+
* @returns {Buffer} JSON-encoded metrics
|
|
72
|
+
*
|
|
73
|
+
*/
|
|
74
|
+
#transformToJson (metrics) {
|
|
75
|
+
const metricsData = {
|
|
76
|
+
resourceMetrics: [{
|
|
77
|
+
resource: this.transformResource(),
|
|
78
|
+
scopeMetrics: this.#transformScope(metrics, true)
|
|
79
|
+
}]
|
|
80
|
+
}
|
|
81
|
+
return this.serializeToJson(metricsData)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Creates scope metrics grouped by instrumentation scope.
|
|
86
|
+
* @param {Iterable<AggregatedMetric>} metrics - Iterable of metrics to transform
|
|
87
|
+
* @param {boolean} isJson - Whether to format for JSON output
|
|
88
|
+
* @returns {Array<Object>} Array of scope metric objects
|
|
89
|
+
*
|
|
90
|
+
*/
|
|
91
|
+
#transformScope (metrics, isJson = false) {
|
|
92
|
+
const groupedMetrics = this.groupByInstrumentationScope(metrics)
|
|
93
|
+
const scopeMetrics = []
|
|
94
|
+
|
|
95
|
+
for (const metricsInScope of groupedMetrics.values()) {
|
|
96
|
+
const firstMetric = metricsInScope[0]
|
|
97
|
+
const instrumentationScope = firstMetric.instrumentationScope || {}
|
|
98
|
+
const { name = '', version = '', schemaUrl = '', attributes = {} } = instrumentationScope
|
|
99
|
+
|
|
100
|
+
const scope = {
|
|
101
|
+
name,
|
|
102
|
+
version,
|
|
103
|
+
droppedAttributesCount: 0
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (attributes) {
|
|
107
|
+
const transformed = isJson ? this.attributesToJson(attributes) : this.transformAttributes(attributes)
|
|
108
|
+
if (transformed.length) {
|
|
109
|
+
scope.attributes = transformed
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
scopeMetrics.push({
|
|
114
|
+
scope,
|
|
115
|
+
schemaUrl,
|
|
116
|
+
metrics: metricsInScope.map(metric => this.#transformMetric(metric, isJson))
|
|
117
|
+
})
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return scopeMetrics
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Transforms a single metric to protobuf or JSON format.
|
|
125
|
+
*
|
|
126
|
+
* @param {AggregatedMetric} metric - The metric to transform
|
|
127
|
+
* @param {boolean} isJson - Whether to output JSON format (vs protobuf)
|
|
128
|
+
* @returns {Object} - The metric transformed to OTLP protobuf or JSON format
|
|
129
|
+
*/
|
|
130
|
+
#transformMetric (metric, isJson = false) {
|
|
131
|
+
const result = {
|
|
132
|
+
name: metric.name,
|
|
133
|
+
description: metric.description || '',
|
|
134
|
+
unit: metric.unit || ''
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const isCumulative = metric.temporality === TEMPORALITY.CUMULATIVE
|
|
138
|
+
let temporality
|
|
139
|
+
if (isJson) {
|
|
140
|
+
temporality = isCumulative ? 'AGGREGATION_TEMPORALITY_CUMULATIVE' : 'AGGREGATION_TEMPORALITY_DELTA'
|
|
141
|
+
} else {
|
|
142
|
+
temporality = isCumulative ? AGGREGATION_TEMPORALITY_CUMULATIVE : AGGREGATION_TEMPORALITY_DELTA
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
switch (metric.type) {
|
|
146
|
+
case METRIC_TYPES.HISTOGRAM:
|
|
147
|
+
result.histogram = {
|
|
148
|
+
dataPoints: Array.from(metric.dataPointMap.values(), dp => this.#transformHistogramDataPoint(dp, isJson)),
|
|
149
|
+
aggregationTemporality: temporality
|
|
150
|
+
}
|
|
151
|
+
break
|
|
152
|
+
|
|
153
|
+
case METRIC_TYPES.COUNTER:
|
|
154
|
+
case METRIC_TYPES.OBSERVABLECOUNTER:
|
|
155
|
+
case METRIC_TYPES.UPDOWNCOUNTER:
|
|
156
|
+
case METRIC_TYPES.OBSERVABLEUPDOWNCOUNTER:
|
|
157
|
+
result.sum = {
|
|
158
|
+
dataPoints: Array.from(metric.dataPointMap.values(), dp => this.#transformNumberDataPoint(dp, isJson)),
|
|
159
|
+
aggregationTemporality: temporality,
|
|
160
|
+
isMonotonic: metric.type === METRIC_TYPES.COUNTER || metric.type === METRIC_TYPES.OBSERVABLECOUNTER
|
|
161
|
+
}
|
|
162
|
+
break
|
|
163
|
+
|
|
164
|
+
case METRIC_TYPES.GAUGE:
|
|
165
|
+
result.gauge = {
|
|
166
|
+
dataPoints: Array.from(metric.dataPointMap.values(), dp => this.#transformNumberDataPoint(dp, isJson))
|
|
167
|
+
}
|
|
168
|
+
break
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return result
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Transforms a histogram data point.
|
|
176
|
+
*
|
|
177
|
+
* @param {HistogramDataPoint} dp - The histogram data point to transform
|
|
178
|
+
* @param {boolean} isJson - Whether to output JSON format (vs protobuf)
|
|
179
|
+
* @returns {Object} The histogram data point transformed to OTLP protobuf format
|
|
180
|
+
*/
|
|
181
|
+
#transformHistogramDataPoint (dp, isJson) {
|
|
182
|
+
const attributes = isJson
|
|
183
|
+
? this.attributesToJson(dp.attributes)
|
|
184
|
+
: this.transformAttributes(dp.attributes)
|
|
185
|
+
|
|
186
|
+
const dataPoint = {
|
|
187
|
+
attributes,
|
|
188
|
+
startTimeUnixNano: dp.startTimeUnixNano,
|
|
189
|
+
timeUnixNano: dp.timeUnixNano,
|
|
190
|
+
count: dp.count,
|
|
191
|
+
sum: dp.sum,
|
|
192
|
+
bucketCounts: dp.bucketCounts || [],
|
|
193
|
+
explicitBounds: dp.explicitBounds || [],
|
|
194
|
+
min: dp.min,
|
|
195
|
+
max: dp.max
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (isJson) {
|
|
199
|
+
dataPoint.startTimeUnixNano = String(dataPoint.startTimeUnixNano)
|
|
200
|
+
dataPoint.timeUnixNano = String(dataPoint.timeUnixNano)
|
|
201
|
+
dataPoint.count = dataPoint.count || 0
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
return dataPoint
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Transforms a number data point to protobuf or JSON format.
|
|
209
|
+
*
|
|
210
|
+
* @param {NumberDataPoint} dataPoint - The number data point to transform
|
|
211
|
+
* @param {boolean} isJson - Whether to output JSON format (vs protobuf)
|
|
212
|
+
* @returns {Object} The number data point transformed to OTLP protobuf format
|
|
213
|
+
*/
|
|
214
|
+
#transformNumberDataPoint (dataPoint, isJson) {
|
|
215
|
+
const attributes = isJson
|
|
216
|
+
? this.attributesToJson(dataPoint.attributes)
|
|
217
|
+
: this.transformAttributes(dataPoint.attributes)
|
|
218
|
+
const timeUnixNano = isJson
|
|
219
|
+
? String(dataPoint.timeUnixNano)
|
|
220
|
+
: dataPoint.timeUnixNano
|
|
221
|
+
|
|
222
|
+
const result = {
|
|
223
|
+
attributes,
|
|
224
|
+
timeUnixNano
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
if (dataPoint.startTimeUnixNano) {
|
|
228
|
+
result.startTimeUnixNano = isJson ? String(dataPoint.startTimeUnixNano) : dataPoint.startTimeUnixNano
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
this.#assignNumberValue(result, dataPoint.value)
|
|
232
|
+
return result
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Assigns the appropriate value field (asInt or asDouble) based on the value type.
|
|
237
|
+
*
|
|
238
|
+
* @param {NumberDataPoint} dataPoint - The number data point to assign a value to
|
|
239
|
+
* @param {number} value - The value to assign
|
|
240
|
+
* @returns {void}
|
|
241
|
+
*/
|
|
242
|
+
#assignNumberValue (dataPoint, value) {
|
|
243
|
+
if (Number.isInteger(value)) {
|
|
244
|
+
dataPoint.asInt = value
|
|
245
|
+
} else {
|
|
246
|
+
dataPoint.asDouble = value
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
module.exports = OtlpTransformer
|