dd-trace 5.80.0 → 5.82.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 +42 -35
- package/loader-hook.mjs +16 -4
- package/package.json +33 -56
- package/packages/datadog-core/src/utils/src/parse-tags.js +1 -1
- package/packages/datadog-esbuild/index.js +44 -26
- package/packages/datadog-esbuild/src/utils.js +14 -2
- package/packages/datadog-instrumentations/index.js +1 -0
- package/packages/datadog-instrumentations/src/aerospike.js +3 -2
- package/packages/datadog-instrumentations/src/ai.js +2 -2
- package/packages/datadog-instrumentations/src/amqp10.js +1 -1
- package/packages/datadog-instrumentations/src/amqplib.js +4 -4
- package/packages/datadog-instrumentations/src/anthropic.js +14 -2
- package/packages/datadog-instrumentations/src/apollo-server-core.js +2 -2
- package/packages/datadog-instrumentations/src/apollo-server.js +1 -1
- package/packages/datadog-instrumentations/src/apollo.js +3 -2
- package/packages/datadog-instrumentations/src/avsc.js +1 -1
- package/packages/datadog-instrumentations/src/aws-sdk.js +6 -2
- package/packages/datadog-instrumentations/src/azure-event-hubs.js +4 -3
- package/packages/datadog-instrumentations/src/azure-functions.js +2 -2
- package/packages/datadog-instrumentations/src/azure-service-bus.js +3 -4
- package/packages/datadog-instrumentations/src/bluebird.js +1 -1
- package/packages/datadog-instrumentations/src/bullmq.js +11 -0
- package/packages/datadog-instrumentations/src/bunyan.js +1 -1
- package/packages/datadog-instrumentations/src/cassandra-driver.js +1 -1
- package/packages/datadog-instrumentations/src/child_process.js +2 -2
- package/packages/datadog-instrumentations/src/confluentinc-kafka-javascript.js +3 -3
- package/packages/datadog-instrumentations/src/couchbase.js +1 -1
- package/packages/datadog-instrumentations/src/crypto.js +1 -1
- package/packages/datadog-instrumentations/src/cucumber.js +12 -13
- package/packages/datadog-instrumentations/src/cypress.js +1 -1
- package/packages/datadog-instrumentations/src/dns.js +1 -1
- package/packages/datadog-instrumentations/src/elasticsearch.js +1 -1
- package/packages/datadog-instrumentations/src/express-mongo-sanitize.js +1 -1
- package/packages/datadog-instrumentations/src/express.js +1 -1
- package/packages/datadog-instrumentations/src/find-my-way.js +6 -5
- package/packages/datadog-instrumentations/src/fs.js +1 -1
- package/packages/datadog-instrumentations/src/generic-pool.js +1 -1
- package/packages/datadog-instrumentations/src/google-cloud-pubsub.js +137 -15
- package/packages/datadog-instrumentations/src/google-cloud-vertexai.js +2 -3
- package/packages/datadog-instrumentations/src/google-genai.js +120 -0
- package/packages/datadog-instrumentations/src/graphql.js +21 -1
- package/packages/datadog-instrumentations/src/grpc/client.js +1 -1
- package/packages/datadog-instrumentations/src/grpc/server.js +1 -1
- package/packages/datadog-instrumentations/src/helpers/bundler-register.js +1 -1
- package/packages/datadog-instrumentations/src/helpers/hook.js +1 -1
- package/packages/datadog-instrumentations/src/helpers/hooks.js +5 -1
- package/packages/datadog-instrumentations/src/helpers/instrument.js +11 -1
- package/packages/datadog-instrumentations/src/helpers/register.js +12 -5
- 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/bullmq.json +106 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/index.js +6 -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/helpers/router-helper.js +1 -1
- package/packages/datadog-instrumentations/src/helpers/shared-utils.js +9 -0
- package/packages/datadog-instrumentations/src/hono.js +55 -10
- package/packages/datadog-instrumentations/src/ioredis.js +1 -1
- package/packages/datadog-instrumentations/src/iovalkey.js +1 -1
- package/packages/datadog-instrumentations/src/jest.js +2 -2
- package/packages/datadog-instrumentations/src/kafkajs.js +3 -3
- package/packages/datadog-instrumentations/src/knex.js +1 -1
- package/packages/datadog-instrumentations/src/langchain.js +3 -109
- package/packages/datadog-instrumentations/src/ldapjs.js +1 -1
- package/packages/datadog-instrumentations/src/light-my-request.js +93 -0
- package/packages/datadog-instrumentations/src/limitd-client.js +1 -1
- package/packages/datadog-instrumentations/src/lodash.js +1 -2
- package/packages/datadog-instrumentations/src/mariadb.js +1 -2
- package/packages/datadog-instrumentations/src/memcached.js +1 -1
- package/packages/datadog-instrumentations/src/mocha/main.js +1 -1
- package/packages/datadog-instrumentations/src/mongodb-core.js +1 -1
- package/packages/datadog-instrumentations/src/mongodb.js +1 -1
- package/packages/datadog-instrumentations/src/mongoose.js +1 -1
- package/packages/datadog-instrumentations/src/mquery.js +1 -1
- package/packages/datadog-instrumentations/src/mysql.js +1 -1
- package/packages/datadog-instrumentations/src/mysql2.js +2 -2
- package/packages/datadog-instrumentations/src/net.js +1 -1
- package/packages/datadog-instrumentations/src/next.js +1 -1
- package/packages/datadog-instrumentations/src/nyc.js +1 -1
- package/packages/datadog-instrumentations/src/openai.js +2 -2
- package/packages/datadog-instrumentations/src/opensearch.js +1 -1
- package/packages/datadog-instrumentations/src/oracledb.js +1 -1
- package/packages/datadog-instrumentations/src/otel-sdk-trace.js +1 -1
- package/packages/datadog-instrumentations/src/pg.js +3 -3
- package/packages/datadog-instrumentations/src/pino.js +1 -1
- package/packages/datadog-instrumentations/src/playwright.js +46 -17
- package/packages/datadog-instrumentations/src/prisma.js +52 -37
- package/packages/datadog-instrumentations/src/process.js +1 -1
- package/packages/datadog-instrumentations/src/promise-js.js +1 -1
- package/packages/datadog-instrumentations/src/promise.js +1 -1
- package/packages/datadog-instrumentations/src/protobufjs.js +1 -1
- package/packages/datadog-instrumentations/src/q.js +1 -1
- package/packages/datadog-instrumentations/src/redis.js +1 -1
- package/packages/datadog-instrumentations/src/rhea.js +1 -1
- package/packages/datadog-instrumentations/src/router.js +1 -1
- package/packages/datadog-instrumentations/src/selenium.js +4 -2
- package/packages/datadog-instrumentations/src/sequelize.js +1 -2
- package/packages/datadog-instrumentations/src/sharedb.js +1 -1
- package/packages/datadog-instrumentations/src/tedious.js +1 -1
- package/packages/datadog-instrumentations/src/undici.js +4 -4
- package/packages/datadog-instrumentations/src/url.js +1 -1
- package/packages/datadog-instrumentations/src/vitest.js +1 -1
- package/packages/datadog-instrumentations/src/vm.js +1 -1
- package/packages/datadog-instrumentations/src/when.js +1 -1
- package/packages/datadog-instrumentations/src/winston.js +1 -1
- package/packages/datadog-instrumentations/src/ws.js +38 -19
- package/packages/datadog-plugin-amqp10/src/index.js +1 -1
- package/packages/datadog-plugin-amqplib/src/index.js +1 -1
- package/packages/datadog-plugin-anthropic/src/index.js +1 -1
- package/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/index.js +1 -1
- package/packages/datadog-plugin-aws-sdk/src/services/dynamodb.js +4 -4
- package/packages/datadog-plugin-aws-sdk/src/services/eventbridge.js +2 -2
- package/packages/datadog-plugin-aws-sdk/src/util.js +3 -3
- package/packages/datadog-plugin-azure-event-hubs/src/index.js +1 -1
- package/packages/datadog-plugin-azure-event-hubs/src/producer.js +19 -5
- package/packages/datadog-plugin-azure-service-bus/src/index.js +1 -1
- package/packages/datadog-plugin-azure-service-bus/src/producer.js +4 -0
- package/packages/datadog-plugin-bullmq/src/consumer.js +60 -0
- package/packages/datadog-plugin-bullmq/src/index.js +18 -0
- package/packages/datadog-plugin-bullmq/src/producer.js +178 -0
- package/packages/datadog-plugin-child_process/src/scrub-cmd-params.js +1 -1
- package/packages/datadog-plugin-confluentinc-kafka-javascript/src/index.js +1 -1
- package/packages/datadog-plugin-cypress/src/cypress-plugin.js +23 -2
- package/packages/datadog-plugin-cypress/src/plugin.js +2 -2
- package/packages/datadog-plugin-cypress/src/support.js +73 -31
- package/packages/datadog-plugin-express/src/index.js +1 -1
- package/packages/datadog-plugin-fastify/src/index.js +1 -1
- package/packages/datadog-plugin-google-cloud-pubsub/src/client.js +13 -3
- package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +171 -12
- package/packages/datadog-plugin-google-cloud-pubsub/src/index.js +1 -2
- package/packages/datadog-plugin-google-cloud-pubsub/src/producer.js +160 -13
- package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-push-subscription.js +217 -0
- package/packages/datadog-plugin-google-cloud-vertexai/src/index.js +1 -1
- 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/resolve.js +1 -1
- package/packages/datadog-plugin-graphql/src/tools/transforms.js +5 -4
- package/packages/datadog-plugin-grpc/src/index.js +1 -1
- package/packages/datadog-plugin-http/src/client.js +2 -1
- package/packages/datadog-plugin-http/src/index.js +25 -5
- package/packages/datadog-plugin-http2/src/client.js +2 -2
- package/packages/datadog-plugin-http2/src/index.js +1 -1
- package/packages/datadog-plugin-jest/src/util.js +1 -1
- package/packages/datadog-plugin-kafkajs/src/index.js +1 -1
- package/packages/datadog-plugin-langchain/src/index.js +1 -1
- package/packages/datadog-plugin-langchain/src/tracing.js +7 -3
- package/packages/datadog-plugin-moleculer/src/index.js +1 -1
- package/packages/datadog-plugin-mongodb-core/src/index.js +6 -2
- package/packages/datadog-plugin-next/src/index.js +11 -3
- package/packages/datadog-plugin-openai/src/index.js +1 -1
- package/packages/datadog-plugin-openai/src/stream-helpers.js +30 -10
- package/packages/datadog-plugin-openai/src/tracing.js +2 -2
- package/packages/datadog-plugin-rhea/src/index.js +1 -1
- package/packages/datadog-plugin-ws/src/close.js +56 -3
- package/packages/datadog-plugin-ws/src/index.js +4 -0
- package/packages/datadog-plugin-ws/src/producer.js +39 -4
- package/packages/datadog-plugin-ws/src/receiver.js +39 -3
- package/packages/datadog-plugin-ws/src/server.js +13 -1
- package/packages/datadog-plugin-ws/src/util.js +107 -0
- package/packages/datadog-shimmer/src/shimmer.js +2 -2
- package/packages/dd-trace/src/aiguard/sdk.js +21 -13
- package/packages/dd-trace/src/appsec/api_security_sampler.js +1 -1
- package/packages/dd-trace/src/appsec/graphql.js +2 -2
- package/packages/dd-trace/src/appsec/iast/analyzers/code-injection-analyzer.js +1 -1
- package/packages/dd-trace/src/appsec/iast/analyzers/command-injection-analyzer.js +1 -1
- package/packages/dd-trace/src/appsec/iast/analyzers/cookie-analyzer.js +1 -1
- package/packages/dd-trace/src/appsec/iast/analyzers/hardcoded-base-analyzer.js +1 -1
- package/packages/dd-trace/src/appsec/iast/analyzers/injection-analyzer.js +1 -1
- package/packages/dd-trace/src/appsec/iast/analyzers/ldap-injection-analyzer.js +1 -1
- package/packages/dd-trace/src/appsec/iast/analyzers/nosql-injection-mongodb-analyzer.js +3 -3
- package/packages/dd-trace/src/appsec/iast/analyzers/path-traversal-analyzer.js +1 -1
- package/packages/dd-trace/src/appsec/iast/analyzers/ssrf-analyzer.js +1 -1
- package/packages/dd-trace/src/appsec/iast/analyzers/untrusted-deserialization-analyzer.js +1 -1
- package/packages/dd-trace/src/appsec/iast/analyzers/unvalidated-redirect-analyzer.js +1 -1
- package/packages/dd-trace/src/appsec/iast/analyzers/weak-cipher-analyzer.js +1 -1
- package/packages/dd-trace/src/appsec/iast/analyzers/weak-hash-analyzer.js +3 -2
- package/packages/dd-trace/src/appsec/iast/analyzers/weak-randomness-analyzer.js +1 -1
- package/packages/dd-trace/src/appsec/iast/iast-plugin.js +3 -3
- package/packages/dd-trace/src/appsec/iast/index.js +5 -5
- package/packages/dd-trace/src/appsec/iast/overhead-controller.js +1 -1
- package/packages/dd-trace/src/appsec/iast/security-controls/index.js +1 -1
- package/packages/dd-trace/src/appsec/iast/taint-tracking/index.js +1 -2
- package/packages/dd-trace/src/appsec/iast/taint-tracking/operations-taint-object.js +1 -1
- package/packages/dd-trace/src/appsec/iast/taint-tracking/plugin.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 +11 -16
- package/packages/dd-trace/src/appsec/iast/taint-tracking/taint-tracking-impl.js +1 -1
- package/packages/dd-trace/src/appsec/iast/telemetry/namespaces.js +1 -1
- package/packages/dd-trace/src/appsec/iast/vulnerability-reporter.js +4 -4
- package/packages/dd-trace/src/appsec/index.js +8 -8
- package/packages/dd-trace/src/appsec/rasp/command_injection.js +1 -1
- package/packages/dd-trace/src/appsec/rasp/index.js +1 -1
- package/packages/dd-trace/src/appsec/rasp/lfi.js +1 -1
- package/packages/dd-trace/src/appsec/rc-products.js +10 -0
- package/packages/dd-trace/src/appsec/recommended.json +230 -3
- package/packages/dd-trace/src/appsec/remote_config.js +177 -0
- package/packages/dd-trace/src/appsec/reporter.js +3 -7
- package/packages/dd-trace/src/appsec/rule_manager.js +37 -20
- package/packages/dd-trace/src/appsec/sdk/index.js +1 -1
- package/packages/dd-trace/src/appsec/sdk/set_user.js +1 -1
- package/packages/dd-trace/src/appsec/sdk/track_event.js +2 -2
- package/packages/dd-trace/src/appsec/sdk/user_blocking.js +2 -2
- package/packages/dd-trace/src/appsec/user_tracking.js +2 -2
- package/packages/dd-trace/src/appsec/waf/index.js +17 -3
- package/packages/dd-trace/src/appsec/waf/waf_manager.js +11 -0
- package/packages/dd-trace/src/azure_metadata.js +8 -2
- package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/worker/index.js +8 -6
- package/packages/dd-trace/src/ci-visibility/exporters/agentless/index.js +2 -2
- package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +1 -1
- package/packages/dd-trace/src/ci-visibility/exporters/test-worker/index.js +1 -1
- package/packages/dd-trace/src/ci-visibility/test-management/get-test-management-tests.js +4 -2
- package/packages/dd-trace/src/config/remote_config.js +34 -0
- package/packages/dd-trace/src/config.js +109 -34
- package/packages/dd-trace/src/config_defaults.js +16 -3
- package/packages/dd-trace/src/constants.js +5 -0
- package/packages/dd-trace/src/crashtracking/crashtracker.js +10 -1
- package/packages/dd-trace/src/datastreams/checkpointer.js +2 -2
- package/packages/dd-trace/src/datastreams/encoding.js +23 -6
- package/packages/dd-trace/src/datastreams/index.js +1 -1
- package/packages/dd-trace/src/datastreams/pathway.js +41 -2
- package/packages/dd-trace/src/datastreams/processor.js +3 -3
- package/packages/dd-trace/src/datastreams/schemas/schema_builder.js +1 -1
- package/packages/dd-trace/src/datastreams/writer.js +2 -2
- package/packages/dd-trace/src/debugger/config.js +1 -0
- 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 +3 -1
- package/packages/dd-trace/src/debugger/devtools_client/index.js +37 -17
- 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 +21 -11
- package/packages/dd-trace/src/debugger/devtools_client/session.js +1 -1
- 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 +8 -3
- package/packages/dd-trace/src/debugger/devtools_client/status.js +3 -3
- package/packages/dd-trace/src/debugger/index.js +2 -2
- package/packages/dd-trace/src/dogstatsd.js +3 -2
- package/packages/dd-trace/src/encode/0.4.js +1 -1
- package/packages/dd-trace/src/encode/agentless-ci-visibility.js +2 -2
- package/packages/dd-trace/src/encode/coverage-ci-visibility.js +1 -1
- package/packages/dd-trace/src/encode/span-stats.js +13 -2
- package/packages/dd-trace/src/exporter.js +2 -2
- package/packages/dd-trace/src/exporters/agent/index.js +1 -1
- package/packages/dd-trace/src/exporters/common/agent-info-exporter.js +1 -1
- package/packages/dd-trace/src/exporters/common/request.js +2 -2
- package/packages/dd-trace/src/exporters/common/writer.js +1 -1
- package/packages/dd-trace/src/exporters/span-stats/index.js +1 -1
- package/packages/dd-trace/src/external-logger/src/index.js +1 -2
- package/packages/dd-trace/src/flare/index.js +1 -1
- package/packages/dd-trace/src/guardrails/index.js +6 -3
- package/packages/dd-trace/src/histogram.js +1 -1
- package/packages/dd-trace/src/id.js +60 -0
- package/packages/dd-trace/src/index.js +1 -1
- package/packages/dd-trace/src/lambda/handler.js +4 -4
- package/packages/dd-trace/src/lambda/index.js +1 -1
- package/packages/dd-trace/src/lambda/runtime/patch.js +4 -4
- package/packages/dd-trace/src/lambda/runtime/ritm.js +2 -2
- package/packages/dd-trace/src/llmobs/constants/tags.js +8 -1
- package/packages/dd-trace/src/llmobs/index.js +8 -9
- package/packages/dd-trace/src/llmobs/plugins/ai/index.js +38 -7
- package/packages/dd-trace/src/llmobs/plugins/ai/util.js +30 -9
- package/packages/dd-trace/src/llmobs/plugins/bedrockruntime.js +3 -3
- 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/handlers/chain.js +1 -1
- package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/chat_model.js +1 -1
- package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/embedding.js +1 -1
- package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/llm.js +1 -1
- package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/vectorstore.js +1 -1
- package/packages/dd-trace/src/llmobs/plugins/langchain/index.js +2 -2
- package/packages/dd-trace/src/llmobs/plugins/openai/constants.js +16 -0
- package/packages/dd-trace/src/llmobs/plugins/{openai.js → openai/index.js} +63 -6
- package/packages/dd-trace/src/llmobs/plugins/openai/utils.js +126 -0
- package/packages/dd-trace/src/llmobs/plugins/vertexai.js +1 -1
- package/packages/dd-trace/src/llmobs/sdk.js +20 -22
- package/packages/dd-trace/src/llmobs/span_processor.js +15 -14
- package/packages/dd-trace/src/llmobs/tagger.js +4 -0
- package/packages/dd-trace/src/llmobs/telemetry.js +3 -4
- package/packages/dd-trace/src/llmobs/writers/base.js +2 -2
- package/packages/dd-trace/src/llmobs/writers/spans.js +1 -2
- package/packages/dd-trace/src/log/index.js +1 -1
- package/packages/dd-trace/src/noop/proxy.js +2 -2
- package/packages/dd-trace/src/noop/span.js +1 -1
- package/packages/dd-trace/src/openfeature/index.js +2 -2
- package/packages/dd-trace/src/openfeature/noop.js +14 -14
- package/packages/dd-trace/src/openfeature/remote_config.js +31 -0
- package/packages/dd-trace/src/openfeature/writers/base.js +5 -5
- package/packages/dd-trace/src/openfeature/writers/exposures.js +9 -9
- package/packages/dd-trace/src/opentelemetry/context_manager.js +2 -2
- 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/logger_provider.js +4 -4
- package/packages/dd-trace/src/opentelemetry/logs/otlp_http_log_exporter.js +5 -3
- package/packages/dd-trace/src/opentelemetry/logs/otlp_transformer.js +17 -16
- 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 +557 -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 +47 -32
- package/packages/dd-trace/src/opentelemetry/otlp/protobuf_loader.js +1 -1
- package/packages/dd-trace/src/opentelemetry/span.js +3 -3
- package/packages/dd-trace/src/opentelemetry/tracer.js +4 -4
- package/packages/dd-trace/src/opentelemetry/tracer_provider.js +1 -1
- package/packages/dd-trace/src/opentracing/propagation/text_map.js +24 -8
- package/packages/dd-trace/src/opentracing/span.js +3 -3
- package/packages/dd-trace/src/opentracing/tracer.js +5 -5
- package/packages/dd-trace/src/payload-tagging/index.js +8 -4
- package/packages/dd-trace/src/plugin_manager.js +5 -3
- package/packages/dd-trace/src/plugins/apollo.js +1 -1
- package/packages/dd-trace/src/plugins/ci_plugin.js +27 -27
- package/packages/dd-trace/src/plugins/database.js +1 -1
- package/packages/dd-trace/src/plugins/index.js +6 -1
- package/packages/dd-trace/src/plugins/log_plugin.js +1 -1
- package/packages/dd-trace/src/plugins/outbound.js +1 -1
- package/packages/dd-trace/src/plugins/tracing.js +1 -1
- package/packages/dd-trace/src/plugins/util/ci.js +1 -1
- package/packages/dd-trace/src/plugins/util/git.js +8 -8
- package/packages/dd-trace/src/plugins/util/stacktrace.js +1 -1
- package/packages/dd-trace/src/plugins/util/test.js +27 -27
- package/packages/dd-trace/src/plugins/util/url.js +119 -1
- package/packages/dd-trace/src/plugins/util/user-provided-git.js +1 -1
- package/packages/dd-trace/src/plugins/util/web.js +18 -46
- package/packages/dd-trace/src/priority_sampler.js +15 -16
- package/packages/dd-trace/src/process-tags/index.js +83 -0
- package/packages/dd-trace/src/profiling/config.js +33 -22
- package/packages/dd-trace/src/profiling/exporter_cli.js +4 -4
- package/packages/dd-trace/src/profiling/exporters/agent.js +5 -5
- package/packages/dd-trace/src/profiling/index.js +1 -1
- package/packages/dd-trace/src/profiling/libuv-size.js +1 -1
- package/packages/dd-trace/src/profiling/profiler.js +4 -5
- package/packages/dd-trace/src/profiling/profilers/event_plugins/event.js +1 -1
- package/packages/dd-trace/src/profiling/profilers/events.js +11 -2
- package/packages/dd-trace/src/profiling/profilers/wall.js +4 -4
- package/packages/dd-trace/src/proxy.js +17 -18
- package/packages/dd-trace/src/rate_limiter.js +1 -1
- package/packages/dd-trace/src/remote_config/index.js +541 -137
- package/packages/dd-trace/src/require-package-json.js +1 -1
- package/packages/dd-trace/src/ritm.js +50 -27
- package/packages/dd-trace/src/runtime_metrics/runtime_metrics.js +1 -1
- package/packages/dd-trace/src/serverless.js +16 -0
- package/packages/dd-trace/src/service-naming/schemas/v0/messaging.js +8 -0
- package/packages/dd-trace/src/service-naming/schemas/v0/web.js +4 -0
- package/packages/dd-trace/src/service-naming/schemas/v1/messaging.js +8 -0
- package/packages/dd-trace/src/service-naming/schemas/v1/web.js +4 -0
- package/packages/dd-trace/src/span_format.js +10 -5
- package/packages/dd-trace/src/span_processor.js +8 -3
- package/packages/dd-trace/src/span_stats.js +21 -8
- package/packages/dd-trace/src/spanleak.js +1 -1
- package/packages/dd-trace/src/standalone/index.js +1 -1
- package/packages/dd-trace/src/startup-log.js +3 -3
- package/packages/dd-trace/src/supported-configurations.json +16 -0
- package/packages/dd-trace/src/telemetry/dependencies.js +4 -4
- package/packages/dd-trace/src/telemetry/endpoints.js +8 -8
- package/packages/dd-trace/src/telemetry/logs/index.js +1 -1
- package/packages/dd-trace/src/telemetry/telemetry.js +22 -8
- package/packages/dd-trace/src/tracer.js +3 -3
- package/packages/dd-trace/src/tracer_metadata.js +19 -15
- 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
- package/packages/dd-trace/src/remote_config/manager.js +0 -368
|
@@ -0,0 +1,557 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const log = require('../../log')
|
|
4
|
+
const { stableStringify } = require('../otlp/otlp_transformer_base')
|
|
5
|
+
const {
|
|
6
|
+
METRIC_TYPES, TEMPORALITY, DEFAULT_HISTOGRAM_BUCKETS, DEFAULT_MAX_MEASUREMENT_QUEUE_SIZE
|
|
7
|
+
} = require('./constants')
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @typedef {import('@opentelemetry/api').Attributes} Attributes
|
|
11
|
+
* @typedef {import('@opentelemetry/core').InstrumentationScope} InstrumentationScope
|
|
12
|
+
* @typedef {import('./instruments').Measurement} Measurement
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @typedef {{ value: number, startTime: number }} SumCumulativeState
|
|
17
|
+
*
|
|
18
|
+
* @typedef {{
|
|
19
|
+
* count: number,
|
|
20
|
+
* sum: number,
|
|
21
|
+
* min: number,
|
|
22
|
+
* max: number,
|
|
23
|
+
* bucketCounts: number[],
|
|
24
|
+
* startTime: number
|
|
25
|
+
* }} HistogramCumulativeState
|
|
26
|
+
*
|
|
27
|
+
* @typedef {SumCumulativeState | HistogramCumulativeState} CumulativeStateValue
|
|
28
|
+
*
|
|
29
|
+
* @typedef {{
|
|
30
|
+
* count: number,
|
|
31
|
+
* sum: number,
|
|
32
|
+
* min?: number,
|
|
33
|
+
* max?: number,
|
|
34
|
+
* bucketCounts: number[]
|
|
35
|
+
* }} HistogramLastExportedState
|
|
36
|
+
*
|
|
37
|
+
* @typedef {number | HistogramLastExportedState} LastExportedStateValue
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @typedef {object} NumberDataPoint
|
|
42
|
+
* @property {Attributes} attributes - Number data point metric attributes
|
|
43
|
+
* @property {string} attrKey - Stable stringified key for attributes
|
|
44
|
+
* @property {number} timeUnixNano - Timestamp in nanoseconds
|
|
45
|
+
* @property {number} startTimeUnixNano - Start timestamp for cumulative metrics
|
|
46
|
+
* @property {number} value - Metric value
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @typedef {object} HistogramDataPoint
|
|
51
|
+
* @property {Attributes} attributes - Histogram data point metric attributes
|
|
52
|
+
* @property {string} attrKey - Stable stringified key for attributes
|
|
53
|
+
* @property {number} timeUnixNano - Timestamp in nanoseconds
|
|
54
|
+
* @property {number} startTimeUnixNano - Start timestamp
|
|
55
|
+
* @property {number} count - Number of observations
|
|
56
|
+
* @property {number} sum - Sum of all observations
|
|
57
|
+
* @property {number} min - Minimum value observed
|
|
58
|
+
* @property {number} max - Maximum value observed
|
|
59
|
+
* @property {number[]} bucketCounts - Count per histogram bucket
|
|
60
|
+
* @property {number[]} explicitBounds - Histogram bucket boundaries
|
|
61
|
+
*/
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @typedef {object} AggregatedMetricDataPoint
|
|
65
|
+
* @property {Attributes} attributes - Aggregated metric data point metric attributes
|
|
66
|
+
* @property {string} attrKey - Stable stringified key for attributes
|
|
67
|
+
* @property {number} timeUnixNano - Timestamp in nanoseconds
|
|
68
|
+
* @property {number} startTimeUnixNano - Start timestamp
|
|
69
|
+
* @property {number} count - Number of observations
|
|
70
|
+
* @property {number} sum - Sum of all observations
|
|
71
|
+
* @property {number} min - Minimum value observed
|
|
72
|
+
* @property {number} max - Maximum value observed
|
|
73
|
+
* @property {number[]} bucketCounts - Count per histogram bucket
|
|
74
|
+
* @property {number[]} explicitBounds - Histogram bucket boundaries
|
|
75
|
+
*/
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* @typedef {object} AggregatedMetric
|
|
79
|
+
* @property {string} name - Metric name
|
|
80
|
+
* @property {string} description - Metric description
|
|
81
|
+
* @property {string} unit - Metric unit
|
|
82
|
+
* @property {string} type - Metric type from METRIC_TYPES
|
|
83
|
+
* @property {InstrumentationScope} instrumentationScope - Instrumentation scope
|
|
84
|
+
* @property {string} temporality - Temporality from TEMPORALITY constants
|
|
85
|
+
* @property {Map<string, AggregatedMetricDataPoint>} dataPointMap - Map of attribute keys to data points
|
|
86
|
+
*/
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* PeriodicMetricReader collects and exports metrics at a regular interval.
|
|
90
|
+
*
|
|
91
|
+
* This implementation follows the OpenTelemetry JavaScript SDK MetricReader pattern:
|
|
92
|
+
* https://open-telemetry.github.io/opentelemetry-js/classes/_opentelemetry_sdk-metrics.PeriodicExportingMetricReader.html
|
|
93
|
+
*
|
|
94
|
+
* @class PeriodicMetricReader
|
|
95
|
+
*/
|
|
96
|
+
class PeriodicMetricReader {
|
|
97
|
+
#measurements = []
|
|
98
|
+
#cumulativeState = new Map()
|
|
99
|
+
#lastExportedState = new Map()
|
|
100
|
+
#droppedCount = 0
|
|
101
|
+
#timer = null
|
|
102
|
+
#isShutdown = false
|
|
103
|
+
#exportInterval
|
|
104
|
+
#aggregator
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Creates a new PeriodicMetricReader instance.
|
|
108
|
+
*
|
|
109
|
+
* @param {OtlpHttpMetricExporter} exporter - Metric exporter for sending to Datadog Agent
|
|
110
|
+
* @param {number} exportInterval - Export interval in milliseconds
|
|
111
|
+
* @param {string} temporalityPreference - Temporality preference: DELTA, CUMULATIVE, or LOWMEMORY
|
|
112
|
+
* @param {number} maxBatchedQueueSize - Maximum number of measurements to queue before dropping
|
|
113
|
+
*/
|
|
114
|
+
constructor (exporter, exportInterval, temporalityPreference, maxBatchedQueueSize) {
|
|
115
|
+
this.exporter = exporter
|
|
116
|
+
this.observableInstruments = new Set()
|
|
117
|
+
this.#exportInterval = exportInterval
|
|
118
|
+
this.#aggregator = new MetricAggregator(temporalityPreference, maxBatchedQueueSize)
|
|
119
|
+
this.#startTimer()
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Records a measurement from a synchronous instrument.
|
|
124
|
+
*
|
|
125
|
+
* @param {Measurement} measurement - The measurement data
|
|
126
|
+
*/
|
|
127
|
+
record (measurement) {
|
|
128
|
+
if (this.#measurements.length >= DEFAULT_MAX_MEASUREMENT_QUEUE_SIZE || this.#isShutdown) {
|
|
129
|
+
this.#droppedCount++
|
|
130
|
+
return
|
|
131
|
+
}
|
|
132
|
+
this.#measurements.push(measurement)
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Forces an immediate collection and export of all metrics.
|
|
137
|
+
* @returns {void}
|
|
138
|
+
*/
|
|
139
|
+
forceFlush () {
|
|
140
|
+
if (this.#isShutdown) {
|
|
141
|
+
log.warn(`PeriodicMetricReader is shutdown. ${this.#droppedCount} measurement(s) were dropped`)
|
|
142
|
+
return
|
|
143
|
+
}
|
|
144
|
+
this.#collectAndExport()
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Shuts down the reader and stops periodic collection.
|
|
149
|
+
* @returns {void}
|
|
150
|
+
*/
|
|
151
|
+
shutdown () {
|
|
152
|
+
if (this.#isShutdown) {
|
|
153
|
+
log.warn('PeriodicMetricReader is already shutdown')
|
|
154
|
+
return
|
|
155
|
+
}
|
|
156
|
+
this.#isShutdown = true
|
|
157
|
+
this.#clearTimer()
|
|
158
|
+
this.forceFlush()
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Starts the periodic export timer.
|
|
163
|
+
*
|
|
164
|
+
*/
|
|
165
|
+
#startTimer () {
|
|
166
|
+
if (this.#timer) return
|
|
167
|
+
|
|
168
|
+
this.#timer = setInterval(() => {
|
|
169
|
+
this.#collectAndExport()
|
|
170
|
+
}, this.#exportInterval).unref()
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Clears the periodic export timer.
|
|
175
|
+
*
|
|
176
|
+
*/
|
|
177
|
+
#clearTimer () {
|
|
178
|
+
if (this.#timer) {
|
|
179
|
+
clearInterval(this.#timer)
|
|
180
|
+
this.#timer = null
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Collects measurements and exports metrics.
|
|
186
|
+
*
|
|
187
|
+
* @param {Function} [callback] - Called after export completes
|
|
188
|
+
*/
|
|
189
|
+
#collectAndExport (callback = () => {}) {
|
|
190
|
+
// Atomically drain measurements for export. New measurements can be recorded
|
|
191
|
+
// during export without interfering with this batch.
|
|
192
|
+
const allMeasurements = this.#measurements.splice(0)
|
|
193
|
+
|
|
194
|
+
for (const instrument of this.observableInstruments) {
|
|
195
|
+
const observableMeasurements = instrument.collect()
|
|
196
|
+
|
|
197
|
+
if (allMeasurements.length >= DEFAULT_MAX_MEASUREMENT_QUEUE_SIZE) {
|
|
198
|
+
this.#droppedCount += observableMeasurements.length
|
|
199
|
+
continue
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const remainingCapacity = DEFAULT_MAX_MEASUREMENT_QUEUE_SIZE - allMeasurements.length
|
|
203
|
+
|
|
204
|
+
if (observableMeasurements.length <= remainingCapacity) {
|
|
205
|
+
allMeasurements.push(...observableMeasurements)
|
|
206
|
+
} else {
|
|
207
|
+
allMeasurements.push(...observableMeasurements.slice(0, remainingCapacity))
|
|
208
|
+
this.#droppedCount += observableMeasurements.length - remainingCapacity
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if (this.#droppedCount > 0) {
|
|
213
|
+
log.warn(
|
|
214
|
+
`Metric queue exceeded limit (max: ${DEFAULT_MAX_MEASUREMENT_QUEUE_SIZE}). ` +
|
|
215
|
+
`Dropping ${this.#droppedCount} measurements. `
|
|
216
|
+
)
|
|
217
|
+
this.#droppedCount = 0
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
if (allMeasurements.length === 0) {
|
|
221
|
+
callback()
|
|
222
|
+
return
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const metrics = this.#aggregator.aggregate(
|
|
226
|
+
allMeasurements,
|
|
227
|
+
this.#cumulativeState,
|
|
228
|
+
this.#lastExportedState
|
|
229
|
+
)
|
|
230
|
+
|
|
231
|
+
this.exporter.export(metrics, callback)
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* MetricAggregator aggregates individual measurements into metric data points.
|
|
237
|
+
*
|
|
238
|
+
*/
|
|
239
|
+
class MetricAggregator {
|
|
240
|
+
#startTime = Number(process.hrtime.bigint())
|
|
241
|
+
#temporalityPreference
|
|
242
|
+
#maxBatchedQueueSize
|
|
243
|
+
|
|
244
|
+
constructor (temporalityPreference, maxBatchedQueueSize) {
|
|
245
|
+
this.#temporalityPreference = temporalityPreference
|
|
246
|
+
this.#maxBatchedQueueSize = maxBatchedQueueSize
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Gets the temporality for a given metric type.
|
|
251
|
+
*
|
|
252
|
+
* @param {string} type - Metric type from METRIC_TYPES
|
|
253
|
+
* @returns {string} Temporality from TEMPORALITY
|
|
254
|
+
*/
|
|
255
|
+
#getTemporality (type) {
|
|
256
|
+
// UpDownCounter and Observable UpDownCounter always use CUMULATIVE
|
|
257
|
+
if (type === METRIC_TYPES.UPDOWNCOUNTER || type === METRIC_TYPES.OBSERVABLEUPDOWNCOUNTER) {
|
|
258
|
+
return TEMPORALITY.CUMULATIVE
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// Gauge always uses last-value aggregation
|
|
262
|
+
if (type === METRIC_TYPES.GAUGE) {
|
|
263
|
+
return TEMPORALITY.GAUGE
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
switch (this.#temporalityPreference) {
|
|
267
|
+
case TEMPORALITY.CUMULATIVE:
|
|
268
|
+
return TEMPORALITY.CUMULATIVE
|
|
269
|
+
case TEMPORALITY.LOWMEMORY:
|
|
270
|
+
// LOWMEMORY: only synchronous Counter and Histogram use DELTA, Observable Counter uses CUMULATIVE
|
|
271
|
+
return (type === METRIC_TYPES.COUNTER || type === METRIC_TYPES.HISTOGRAM)
|
|
272
|
+
? TEMPORALITY.DELTA
|
|
273
|
+
: TEMPORALITY.CUMULATIVE
|
|
274
|
+
default:
|
|
275
|
+
return TEMPORALITY.DELTA
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Aggregates measurements into metrics.
|
|
281
|
+
*
|
|
282
|
+
* @param {Measurement[]} measurements - The measurements to aggregate
|
|
283
|
+
* @param {Map<string, CumulativeStateValue>} cumulativeState - The cumulative state of the metrics
|
|
284
|
+
* @param {Map<string, LastExportedStateValue>} lastExportedState - The last exported state of the metrics
|
|
285
|
+
* @returns {Iterable<AggregatedMetric>} The aggregated metrics
|
|
286
|
+
*/
|
|
287
|
+
aggregate (measurements, cumulativeState, lastExportedState) {
|
|
288
|
+
const metricsMap = new Map()
|
|
289
|
+
|
|
290
|
+
for (const measurement of measurements) {
|
|
291
|
+
const {
|
|
292
|
+
name,
|
|
293
|
+
description,
|
|
294
|
+
unit,
|
|
295
|
+
type,
|
|
296
|
+
instrumentationScope,
|
|
297
|
+
value,
|
|
298
|
+
attributes,
|
|
299
|
+
timestamp
|
|
300
|
+
} = measurement
|
|
301
|
+
|
|
302
|
+
const scopeKey = this.#getScopeKey(instrumentationScope)
|
|
303
|
+
const metricKey = `${scopeKey}:${name}:${type}`
|
|
304
|
+
const attrKey = stableStringify(attributes)
|
|
305
|
+
const stateKey = this.#getStateKey(scopeKey, name, type, attrKey)
|
|
306
|
+
|
|
307
|
+
let metric = metricsMap.get(metricKey)
|
|
308
|
+
if (!metric) {
|
|
309
|
+
if (metricsMap.size >= this.#maxBatchedQueueSize) {
|
|
310
|
+
log.warn(
|
|
311
|
+
`Metric queue exceeded limit (max: ${this.#maxBatchedQueueSize}). ` +
|
|
312
|
+
`Dropping metric: ${metricKey}, value: ${value}. ` +
|
|
313
|
+
'Consider increasing OTEL_BSP_MAX_QUEUE_SIZE or decreasing OTEL_METRIC_EXPORT_INTERVAL.'
|
|
314
|
+
)
|
|
315
|
+
continue
|
|
316
|
+
}
|
|
317
|
+
metric = {
|
|
318
|
+
name,
|
|
319
|
+
description,
|
|
320
|
+
unit,
|
|
321
|
+
type,
|
|
322
|
+
instrumentationScope,
|
|
323
|
+
temporality: this.#getTemporality(type),
|
|
324
|
+
dataPointMap: new Map()
|
|
325
|
+
}
|
|
326
|
+
metricsMap.set(metricKey, metric)
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
if (type === METRIC_TYPES.COUNTER || type === METRIC_TYPES.UPDOWNCOUNTER) {
|
|
330
|
+
this.#aggregateSum(metric, value, attributes, attrKey, timestamp, stateKey, cumulativeState)
|
|
331
|
+
} else if (type === METRIC_TYPES.HISTOGRAM) {
|
|
332
|
+
this.#aggregateHistogram(metric, value, attributes, attrKey, timestamp, stateKey, cumulativeState)
|
|
333
|
+
} else {
|
|
334
|
+
this.#aggregateLastValue(metric, value, attributes, attrKey, timestamp)
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
this.#applyDeltaTemporality(metricsMap, lastExportedState)
|
|
339
|
+
return metricsMap
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Gets unique identifier for a given instrumentation scope.
|
|
344
|
+
*
|
|
345
|
+
* @param {InstrumentationScope} instrumentationScope - The instrumentation scope
|
|
346
|
+
* @returns {string} - The scope identifier
|
|
347
|
+
*/
|
|
348
|
+
#getScopeKey (instrumentationScope) {
|
|
349
|
+
return `${instrumentationScope.name}@${instrumentationScope.version}@${instrumentationScope.schemaUrl}`
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* Gets unique identifier for a given metric.
|
|
354
|
+
*
|
|
355
|
+
* @param {string} scopeKey - The scope identifier
|
|
356
|
+
* @param {string} name - The metric name
|
|
357
|
+
* @param {string} type - The metric type from METRIC_TYPES
|
|
358
|
+
* @param {string} attrKey - The attribute key
|
|
359
|
+
* @returns {string} - The metric identifier
|
|
360
|
+
*/
|
|
361
|
+
#getStateKey (scopeKey, name, type, attrKey) {
|
|
362
|
+
return `${scopeKey}:${name}:${type}:${attrKey}`
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Checks if a given metric type is a delta type.
|
|
367
|
+
*
|
|
368
|
+
* @param {string} type - The metric type from METRIC_TYPES
|
|
369
|
+
* @returns {boolean} - True if the metric type is a delta type
|
|
370
|
+
*/
|
|
371
|
+
#isDeltaType (type) {
|
|
372
|
+
return type === METRIC_TYPES.COUNTER ||
|
|
373
|
+
type === METRIC_TYPES.OBSERVABLECOUNTER ||
|
|
374
|
+
type === METRIC_TYPES.HISTOGRAM
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* Applies delta temporality to the metrics.
|
|
379
|
+
*
|
|
380
|
+
* @param {Iterable<AggregatedMetric>} metrics - The metrics to apply delta temporality to
|
|
381
|
+
* @param {Map<string, LastExportedStateValue>} lastExportedState - The last exported state of the metrics
|
|
382
|
+
* @returns {void}
|
|
383
|
+
*/
|
|
384
|
+
#applyDeltaTemporality (metrics, lastExportedState) {
|
|
385
|
+
for (const metric of metrics) {
|
|
386
|
+
if (metric.temporality === TEMPORALITY.DELTA && this.#isDeltaType(metric.type)) {
|
|
387
|
+
const scopeKey = this.#getScopeKey(metric.instrumentationScope)
|
|
388
|
+
|
|
389
|
+
for (const dataPoint of metric.dataPointMap.values()) {
|
|
390
|
+
const stateKey = this.#getStateKey(scopeKey, metric.name, metric.type, dataPoint.attrKey)
|
|
391
|
+
|
|
392
|
+
if (metric.type === METRIC_TYPES.COUNTER || metric.type === METRIC_TYPES.OBSERVABLECOUNTER) {
|
|
393
|
+
const lastValue = lastExportedState.get(stateKey) || 0
|
|
394
|
+
const currentValue = dataPoint.value
|
|
395
|
+
dataPoint.value = currentValue - lastValue
|
|
396
|
+
lastExportedState.set(stateKey, currentValue)
|
|
397
|
+
} else if (metric.type === METRIC_TYPES.HISTOGRAM) {
|
|
398
|
+
const lastState = lastExportedState.get(stateKey) || {
|
|
399
|
+
count: 0,
|
|
400
|
+
sum: 0,
|
|
401
|
+
bucketCounts: new Array(dataPoint.bucketCounts.length).fill(0)
|
|
402
|
+
}
|
|
403
|
+
const currentState = {
|
|
404
|
+
count: dataPoint.count,
|
|
405
|
+
sum: dataPoint.sum,
|
|
406
|
+
min: dataPoint.min,
|
|
407
|
+
max: dataPoint.max,
|
|
408
|
+
bucketCounts: [...dataPoint.bucketCounts]
|
|
409
|
+
}
|
|
410
|
+
dataPoint.count = currentState.count - lastState.count
|
|
411
|
+
dataPoint.sum = currentState.sum - lastState.sum
|
|
412
|
+
dataPoint.bucketCounts = currentState.bucketCounts.map(
|
|
413
|
+
(count, idx) => count - (lastState.bucketCounts[idx] || 0)
|
|
414
|
+
)
|
|
415
|
+
lastExportedState.set(stateKey, currentState)
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* Finds or creates a data point for a given metric.
|
|
424
|
+
*
|
|
425
|
+
* @param {AggregatedMetric} metric - The metric to find or create a data point for
|
|
426
|
+
* @param {Attributes} attributes - The attributes of the metric
|
|
427
|
+
* @param {string} attrKey - The attribute key
|
|
428
|
+
* @param {Function} createInitialDataPoint - Function to create an initial data point
|
|
429
|
+
* @returns {NumberDataPoint|HistogramDataPoint} - The data point
|
|
430
|
+
*/
|
|
431
|
+
#findOrCreateDataPoint (metric, attributes, attrKey, createInitialDataPoint) {
|
|
432
|
+
let dataPoint = metric.dataPointMap.get(attrKey)
|
|
433
|
+
|
|
434
|
+
if (!dataPoint) {
|
|
435
|
+
dataPoint = { attributes, attrKey, ...createInitialDataPoint() }
|
|
436
|
+
metric.dataPointMap.set(attrKey, dataPoint)
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
return dataPoint
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* Records the sum of all values for a given metric.
|
|
444
|
+
* Creates a new data point if it doesn't exist.
|
|
445
|
+
*
|
|
446
|
+
* @param {AggregatedMetric} metric - The metric to aggregate a sum for
|
|
447
|
+
* @param {number} value - The value to aggregate
|
|
448
|
+
* @param {Attributes} attributes - The attributes of the metric
|
|
449
|
+
* @param {string} attrKey - The attribute key
|
|
450
|
+
* @param {number} timestamp - The timestamp of the measurement
|
|
451
|
+
* @param {string} stateKey - The state key
|
|
452
|
+
* @param {Map<string, CumulativeStateValue>} cumulativeState - The cumulative state of the metrics
|
|
453
|
+
*/
|
|
454
|
+
#aggregateSum (metric, value, attributes, attrKey, timestamp, stateKey, cumulativeState) {
|
|
455
|
+
if (!cumulativeState.has(stateKey)) {
|
|
456
|
+
cumulativeState.set(stateKey, {
|
|
457
|
+
value: 0,
|
|
458
|
+
startTime: metric.temporality === TEMPORALITY.CUMULATIVE ? this.#startTime : timestamp
|
|
459
|
+
})
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
const state = cumulativeState.get(stateKey)
|
|
463
|
+
state.value += value
|
|
464
|
+
|
|
465
|
+
const dataPoint = this.#findOrCreateDataPoint(metric, attributes, attrKey, () => ({
|
|
466
|
+
startTimeUnixNano: state.startTime,
|
|
467
|
+
timeUnixNano: timestamp,
|
|
468
|
+
value: 0
|
|
469
|
+
}))
|
|
470
|
+
|
|
471
|
+
dataPoint.value = state.value
|
|
472
|
+
dataPoint.timeUnixNano = timestamp
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* Overwrites the last recorded value for a given metric or
|
|
477
|
+
* creates a new data point if it doesn't exist.
|
|
478
|
+
*
|
|
479
|
+
* @param {AggregatedMetric} metric - The metric to aggregate a last value for
|
|
480
|
+
* @param {number} value - The value to aggregate
|
|
481
|
+
* @param {Attributes} attributes - The attributes of the metric
|
|
482
|
+
* @param {string} attrKey - The attribute key
|
|
483
|
+
* @param {number} timestamp - The timestamp of the measurement
|
|
484
|
+
*/
|
|
485
|
+
#aggregateLastValue (metric, value, attributes, attrKey, timestamp) {
|
|
486
|
+
const dataPoint = this.#findOrCreateDataPoint(metric, attributes, attrKey, () => ({
|
|
487
|
+
timeUnixNano: timestamp,
|
|
488
|
+
value: 0
|
|
489
|
+
}))
|
|
490
|
+
|
|
491
|
+
dataPoint.value = value
|
|
492
|
+
dataPoint.timeUnixNano = timestamp
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
/**
|
|
496
|
+
* Aggregates histogram values by distributing them into buckets.
|
|
497
|
+
* Tracks count, sum, min, max, and per-bucket counts and creates
|
|
498
|
+
* a new data point if it doesn't exist.
|
|
499
|
+
*
|
|
500
|
+
* @param {AggregatedMetric} metric - The metric to aggregate a histogram for
|
|
501
|
+
* @param {number} value - The value to aggregate
|
|
502
|
+
* @param {Attributes} attributes - The attributes of the metric
|
|
503
|
+
* @param {string} attrKey - The attribute key
|
|
504
|
+
* @param {number} timestamp - The timestamp of the measurement
|
|
505
|
+
* @param {string} stateKey - The state key
|
|
506
|
+
* @param {Map<string, CumulativeStateValue>} cumulativeState - The cumulative state of the metrics
|
|
507
|
+
* @returns {void}
|
|
508
|
+
*/
|
|
509
|
+
#aggregateHistogram (metric, value, attributes, attrKey, timestamp, stateKey, cumulativeState) {
|
|
510
|
+
if (!cumulativeState.has(stateKey)) {
|
|
511
|
+
cumulativeState.set(stateKey, {
|
|
512
|
+
count: 0,
|
|
513
|
+
sum: 0,
|
|
514
|
+
min: Infinity,
|
|
515
|
+
max: -Infinity,
|
|
516
|
+
bucketCounts: new Array(DEFAULT_HISTOGRAM_BUCKETS.length + 1).fill(0),
|
|
517
|
+
startTime: metric.temporality === TEMPORALITY.CUMULATIVE ? this.#startTime : timestamp
|
|
518
|
+
})
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
const state = cumulativeState.get(stateKey)
|
|
522
|
+
|
|
523
|
+
let bucketIndex = DEFAULT_HISTOGRAM_BUCKETS.length
|
|
524
|
+
for (let i = 0; i < DEFAULT_HISTOGRAM_BUCKETS.length; i++) {
|
|
525
|
+
if (value <= DEFAULT_HISTOGRAM_BUCKETS[i]) {
|
|
526
|
+
bucketIndex = i
|
|
527
|
+
break
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
state.bucketCounts[bucketIndex]++
|
|
532
|
+
state.count++
|
|
533
|
+
state.sum += value
|
|
534
|
+
state.min = Math.min(state.min, value)
|
|
535
|
+
state.max = Math.max(state.max, value)
|
|
536
|
+
|
|
537
|
+
const dataPoint = this.#findOrCreateDataPoint(metric, attributes, attrKey, () => ({
|
|
538
|
+
startTimeUnixNano: state.startTime,
|
|
539
|
+
timeUnixNano: timestamp,
|
|
540
|
+
count: 0,
|
|
541
|
+
sum: 0,
|
|
542
|
+
min: Infinity,
|
|
543
|
+
max: -Infinity,
|
|
544
|
+
bucketCounts: new Array(DEFAULT_HISTOGRAM_BUCKETS.length + 1).fill(0),
|
|
545
|
+
explicitBounds: DEFAULT_HISTOGRAM_BUCKETS
|
|
546
|
+
}))
|
|
547
|
+
|
|
548
|
+
dataPoint.count = state.count
|
|
549
|
+
dataPoint.sum = state.sum
|
|
550
|
+
dataPoint.min = state.min
|
|
551
|
+
dataPoint.max = state.max
|
|
552
|
+
dataPoint.bucketCounts = [...state.bucketCounts]
|
|
553
|
+
dataPoint.timeUnixNano = timestamp
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
module.exports = PeriodicMetricReader
|
|
@@ -10,14 +10,12 @@ const tracerMetrics = telemetryMetrics.manager.namespace('tracers')
|
|
|
10
10
|
/**
|
|
11
11
|
* Base class for OTLP HTTP exporters.
|
|
12
12
|
*
|
|
13
|
-
* This implementation follows the OTLP HTTP specification:
|
|
13
|
+
* This implementation follows the OTLP HTTP v1.7.0 specification:
|
|
14
14
|
* https://opentelemetry.io/docs/specs/otlp/#otlphttp
|
|
15
15
|
*
|
|
16
16
|
* @class OtlpHttpExporterBase
|
|
17
17
|
*/
|
|
18
18
|
class OtlpHttpExporterBase {
|
|
19
|
-
#telemetryTags
|
|
20
|
-
|
|
21
19
|
/**
|
|
22
20
|
* Creates a new OtlpHttpExporterBase instance.
|
|
23
21
|
*
|
|
@@ -49,31 +47,25 @@ class OtlpHttpExporterBase {
|
|
|
49
47
|
...this.#parseAdditionalHeaders(headers)
|
|
50
48
|
}
|
|
51
49
|
}
|
|
52
|
-
this
|
|
50
|
+
this.telemetryTags = [
|
|
53
51
|
'protocol:http',
|
|
54
52
|
`encoding:${isJson ? 'json' : 'protobuf'}`
|
|
55
53
|
]
|
|
56
54
|
}
|
|
57
55
|
|
|
58
|
-
/**
|
|
59
|
-
* Gets the telemetry tags for this exporter.
|
|
60
|
-
* @returns {Array<string>} Telemetry tags
|
|
61
|
-
* @protected
|
|
62
|
-
*/
|
|
63
|
-
_getTelemetryTags () {
|
|
64
|
-
return this.#telemetryTags
|
|
65
|
-
}
|
|
66
|
-
|
|
67
56
|
/**
|
|
68
57
|
* Records telemetry metrics for exported data.
|
|
69
58
|
* @param {string} metricName - Name of the metric to record
|
|
70
59
|
* @param {number} count - Count to increment
|
|
71
|
-
* @param {Array<string>} [
|
|
60
|
+
* @param {Array<string>} [additionalTags] - Optional custom tags (defaults to this exporter's tags)
|
|
72
61
|
* @protected
|
|
73
62
|
*/
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
63
|
+
recordTelemetry (metricName, count, additionalTags) {
|
|
64
|
+
if (additionalTags?.length > 0) {
|
|
65
|
+
tracerMetrics.count(metricName, [...this.telemetryTags, ...additionalTags || []]).inc(count)
|
|
66
|
+
} else {
|
|
67
|
+
tracerMetrics.count(metricName, this.telemetryTags).inc(count)
|
|
68
|
+
}
|
|
77
69
|
}
|
|
78
70
|
|
|
79
71
|
/**
|
|
@@ -82,7 +74,7 @@ class OtlpHttpExporterBase {
|
|
|
82
74
|
* @param {Function} resultCallback - Callback for the result
|
|
83
75
|
* @protected
|
|
84
76
|
*/
|
|
85
|
-
|
|
77
|
+
sendPayload (payload, resultCallback) {
|
|
86
78
|
const options = {
|
|
87
79
|
...this.options,
|
|
88
80
|
headers: {
|