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,171 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { VERSION: packageVersion } = require('../../../../../version')
|
|
4
|
+
const log = require('../../log')
|
|
5
|
+
const {
|
|
6
|
+
Counter, UpDownCounter, Histogram, Gauge, ObservableGauge, ObservableCounter, ObservableUpDownCounter
|
|
7
|
+
} = require('./instruments')
|
|
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
|