dd-trace 5.132.0 → 5.134.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/ci/diagnose.js +9 -14
- package/ci/init.js +1 -2
- package/ci/test-optimization-validation/ci-discovery.js +9 -4
- package/ci/test-optimization-validation/executable.js +1 -5
- package/ci/test-optimization-validation/framework-adapters/cypress.js +1 -4
- package/ci/test-optimization-validation/framework-adapters/vitest.js +1 -1
- package/ci/test-optimization-validation/generated-files.js +6 -4
- package/ci/test-optimization-validation/generated-test-contract.js +7 -3
- package/ci/test-optimization-validation/manifest-scaffold.js +7 -2
- package/ci/test-optimization-validation/manifest-schema.js +6 -7
- package/ci/test-optimization-validation/report-writer.js +6 -2
- package/ci/test-optimization-validation/runner-command.js +2 -4
- package/ci/test-optimization-validation/runner-contract.js +1 -2
- package/ci/test-optimization-validation/scenarios/auto-test-retries.js +1 -15
- package/ci/vitest-no-worker-init-runner-setup.mjs +27 -0
- package/ci/vitest-no-worker-init-setup.mjs +10 -7
- package/index.d.ts +41 -19
- package/initialize.mjs +1 -3
- package/openfeature/rules-based.d.ts +11 -0
- package/openfeature/rules-based.js +7 -0
- package/package.json +25 -22
- package/packages/datadog-core/src/storage.js +16 -0
- package/packages/datadog-esbuild/index.js +18 -12
- package/packages/datadog-instrumentations/index.js +2 -1
- package/packages/datadog-instrumentations/src/aerospike.js +3 -3
- package/packages/datadog-instrumentations/src/ai.js +3 -3
- package/packages/datadog-instrumentations/src/aws-durable-execution-sdk-js.js +0 -6
- package/packages/datadog-instrumentations/src/aws-sdk.js +21 -13
- package/packages/datadog-instrumentations/src/cassandra-driver.js +25 -20
- package/packages/datadog-instrumentations/src/claude-agent-sdk.js +9 -23
- package/packages/datadog-instrumentations/src/cucumber.js +65 -41
- package/packages/datadog-instrumentations/src/elasticsearch.js +1 -5
- package/packages/datadog-instrumentations/src/electron.js +6 -6
- package/packages/datadog-instrumentations/src/fastify.js +13 -4
- package/packages/datadog-instrumentations/src/fs.js +2 -2
- package/packages/datadog-instrumentations/src/google-cloud-pubsub.js +9 -5
- package/packages/datadog-instrumentations/src/grpc/client.js +2 -0
- package/packages/datadog-instrumentations/src/helpers/bundler-register.js +28 -9
- package/packages/datadog-instrumentations/src/helpers/check-require-cache.js +1 -2
- package/packages/datadog-instrumentations/src/helpers/hooks.js +1 -0
- package/packages/datadog-instrumentations/src/helpers/instrument.js +1 -1
- package/packages/datadog-instrumentations/src/helpers/register.js +45 -1
- package/packages/datadog-instrumentations/src/helpers/rewriter/index.js +2 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentation-registry.js +89 -6
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/graphql-jit.js +5 -6
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/jest.js +12 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/postgres.js +48 -31
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/vitest.js +8 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/webdriverio.js +7 -7
- package/packages/datadog-instrumentations/src/helpers/rewriter/targets.json +5 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/transforms/postgres.js +42 -4
- package/packages/datadog-instrumentations/src/helpers/rewriter/transforms.js +7 -10
- package/packages/datadog-instrumentations/src/ioredis.js +7 -5
- package/packages/datadog-instrumentations/src/iovalkey.js +7 -5
- package/packages/datadog-instrumentations/src/jest.js +72 -67
- package/packages/datadog-instrumentations/src/knex.js +9 -5
- package/packages/datadog-instrumentations/src/mariadb-bundle.js +3 -3
- package/packages/datadog-instrumentations/src/mocha/common.js +20 -8
- package/packages/datadog-instrumentations/src/mocha/main.js +140 -43
- package/packages/datadog-instrumentations/src/mocha/utils.js +38 -4
- package/packages/datadog-instrumentations/src/mocha/worker.js +1 -2
- package/packages/datadog-instrumentations/src/mongodb-core.js +3 -3
- package/packages/datadog-instrumentations/src/mongoose.js +3 -3
- package/packages/datadog-instrumentations/src/nova-sonic/audio.js +173 -0
- package/packages/datadog-instrumentations/src/nova-sonic/index.js +209 -0
- package/packages/datadog-instrumentations/src/nova-sonic/session.js +492 -0
- package/packages/datadog-instrumentations/src/openai-realtime/index.js +18 -6
- package/packages/datadog-instrumentations/src/openai-realtime/session.js +1 -1
- package/packages/datadog-instrumentations/src/openai.js +7 -0
- package/packages/datadog-instrumentations/src/pino.js +5 -6
- package/packages/datadog-instrumentations/src/playwright.js +2 -0
- package/packages/datadog-instrumentations/src/redis.js +27 -13
- package/packages/datadog-instrumentations/src/router.js +30 -0
- package/packages/datadog-instrumentations/src/rum-browser-scripts.js +2 -6
- package/packages/datadog-instrumentations/src/stripe.js +23 -12
- package/packages/datadog-instrumentations/src/vitest-main-no-worker-init.js +8 -5
- package/packages/datadog-instrumentations/src/vitest-main.js +16 -18
- package/packages/datadog-instrumentations/src/vitest-util.js +7 -4
- package/packages/datadog-instrumentations/src/vitest-worker.js +1 -2
- package/packages/datadog-instrumentations/src/vitest.js +9 -1
- package/packages/datadog-instrumentations/src/webdriverio.js +5 -8
- package/packages/datadog-instrumentations/src/ws.js +1 -4
- package/packages/datadog-plugin-amqplib/src/client.js +1 -2
- package/packages/datadog-plugin-avsc/src/schema_iterator.js +1 -5
- package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/handler.js +1 -2
- package/packages/datadog-plugin-aws-sdk/src/base.js +5 -8
- package/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/index.js +18 -0
- package/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/sonic.js +45 -0
- package/packages/datadog-plugin-aws-sdk/src/services/kinesis.js +9 -3
- package/packages/datadog-plugin-aws-sdk/src/services/sqs.js +2 -5
- package/packages/datadog-plugin-azure-durable-functions/src/index.js +5 -4
- package/packages/datadog-plugin-azure-functions/src/index.js +5 -3
- package/packages/datadog-plugin-claude-agent-sdk/src/index.js +0 -2
- package/packages/datadog-plugin-cypress/src/cypress-plugin.js +4 -5
- package/packages/datadog-plugin-cypress/src/index.js +6 -6
- package/packages/datadog-plugin-cypress/src/source-map-utils.js +1 -2
- package/packages/datadog-plugin-cypress/src/support.js +3 -4
- package/packages/datadog-plugin-express/src/code_origin.js +1 -2
- package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +2 -2
- package/packages/datadog-plugin-google-cloud-pubsub/src/producer.js +1 -2
- package/packages/datadog-plugin-graphql/src/execute.js +5 -5
- package/packages/datadog-plugin-grpc/src/util.js +1 -2
- package/packages/datadog-plugin-kafkajs/src/producer.js +1 -2
- package/packages/datadog-plugin-mocha/src/index.js +7 -10
- package/packages/datadog-plugin-mocha/src/webdriverio-video.js +8 -4
- package/packages/datadog-plugin-mongodb-core/src/query.js +8 -5
- package/packages/datadog-plugin-next/src/index.js +1 -2
- package/packages/datadog-plugin-openai/src/tracing.js +5 -2
- package/packages/datadog-plugin-openai-agents/src/integration.js +6 -2
- package/packages/datadog-plugin-openai-agents/src/processor.js +2 -4
- package/packages/datadog-plugin-postgres/src/index.js +24 -0
- package/packages/datadog-plugin-protobufjs/src/schema_iterator.js +1 -5
- package/packages/datadog-plugin-rhea/src/consumer.js +1 -4
- package/packages/datadog-plugin-vitest/src/index.js +5 -2
- package/packages/datadog-shimmer/src/shimmer.js +5 -4
- package/packages/datadog-webpack/index.js +55 -43
- package/packages/datadog-webpack/src/loader.js +56 -8
- package/packages/dd-trace/src/aiguard/evaluation.js +143 -1
- package/packages/dd-trace/src/aiguard/integrations/vercel-ai.js +2 -4
- package/packages/dd-trace/src/aiguard/messages/utils.js +1 -2
- package/packages/dd-trace/src/aiguard/redaction.js +8 -2
- package/packages/dd-trace/src/appsec/api_security/normalized-route.js +3 -2
- package/packages/dd-trace/src/appsec/api_security/sampler.js +2 -6
- package/packages/dd-trace/src/appsec/downstream_requests.js +1 -9
- package/packages/dd-trace/src/appsec/handlers/http-request.js +3 -9
- package/packages/dd-trace/src/appsec/handlers/http-response.js +7 -2
- package/packages/dd-trace/src/appsec/iast/analyzers/path-traversal-analyzer.js +4 -3
- package/packages/dd-trace/src/appsec/iast/analyzers/set-cookies-header-interceptor.js +1 -4
- package/packages/dd-trace/src/appsec/iast/path-line.js +2 -1
- package/packages/dd-trace/src/appsec/iast/taint-tracking/operations-taint-object.js +7 -1
- package/packages/dd-trace/src/appsec/iast/taint-tracking/plugin.js +1 -3
- package/packages/dd-trace/src/appsec/iast/taint-tracking/rewriter-esm.mjs +1 -3
- package/packages/dd-trace/src/appsec/iast/telemetry/iast-metric.js +1 -6
- package/packages/dd-trace/src/appsec/lambda.js +1 -3
- package/packages/dd-trace/src/appsec/rasp/fs-plugin.js +37 -27
- package/packages/dd-trace/src/appsec/rasp/lfi.js +9 -5
- package/packages/dd-trace/src/appsec/reporter.js +21 -1
- package/packages/dd-trace/src/appsec/stack_trace.js +4 -4
- package/packages/dd-trace/src/ci-visibility/dynamic-atr-retries.js +3 -6
- package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/worker/index.js +3 -2
- package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/msgpack-to-json.js +1 -1
- package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +13 -7
- package/packages/dd-trace/src/ci-visibility/exporters/settings-cache-key.js +1 -2
- package/packages/dd-trace/src/ci-visibility/exporters/test-worker/index.js +2 -8
- package/packages/dd-trace/src/ci-visibility/resolve-runfile-path.js +54 -0
- package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache-schema.js +5 -8
- package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache.js +2 -53
- package/packages/dd-trace/src/config/config-types.d.ts +2 -2
- package/packages/dd-trace/src/config/defaults.js +5 -5
- package/packages/dd-trace/src/config/generated-config-types.d.ts +10 -0
- package/packages/dd-trace/src/config/helper.js +34 -3
- package/packages/dd-trace/src/config/index.js +55 -9
- package/packages/dd-trace/src/config/normalize-service.js +1 -1
- package/packages/dd-trace/src/config/parsers.js +2 -2
- package/packages/dd-trace/src/config/supported-configurations.json +44 -0
- package/packages/dd-trace/src/datastreams/processor.js +3 -2
- package/packages/dd-trace/src/datastreams/schemas/schema_builder.js +1 -4
- package/packages/dd-trace/src/debugger/devtools_client/breakpoints.js +6 -5
- package/packages/dd-trace/src/debugger/devtools_client/condition.js +5 -5
- package/packages/dd-trace/src/debugger/devtools_client/send.js +1 -0
- package/packages/dd-trace/src/debugger/devtools_client/snapshot/collector.js +4 -6
- package/packages/dd-trace/src/debugger/devtools_client/status.js +1 -0
- package/packages/dd-trace/src/debugger/guardrail-metrics.js +2 -2
- package/packages/dd-trace/src/debugger/unsupported-runtime.js +16 -0
- package/packages/dd-trace/src/dogstatsd.js +1 -1
- package/packages/dd-trace/src/encode/tags-processors.js +2 -2
- package/packages/dd-trace/src/exporters/common/request.js +1 -5
- package/packages/dd-trace/src/id.js +14 -1
- package/packages/dd-trace/src/lambda/handler.js +179 -19
- package/packages/dd-trace/src/lambda/index.js +15 -1
- package/packages/dd-trace/src/lambda/runtime/patch.js +34 -7
- package/packages/dd-trace/src/llmobs/agent-manifest.js +19 -2
- package/packages/dd-trace/src/llmobs/audio-utils.js +3 -2
- package/packages/dd-trace/src/llmobs/constants/tags.js +15 -0
- package/packages/dd-trace/src/llmobs/experiments/experiment.js +1 -1
- package/packages/dd-trace/src/llmobs/plugins/anthropic/index.js +15 -0
- package/packages/dd-trace/src/llmobs/plugins/genai/util.js +1 -2
- package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/chat_model.js +1 -3
- package/packages/dd-trace/src/llmobs/plugins/langgraph/index.js +1 -1
- package/packages/dd-trace/src/llmobs/plugins/nova-sonic.js +92 -0
- package/packages/dd-trace/src/llmobs/plugins/openai/constants.js +5 -0
- package/packages/dd-trace/src/llmobs/plugins/openai/index.js +64 -2
- package/packages/dd-trace/src/llmobs/plugins/openai/utils.js +38 -0
- package/packages/dd-trace/src/llmobs/prompts/manager.js +5 -7
- package/packages/dd-trace/src/llmobs/prompts/prompt.js +1 -1
- package/packages/dd-trace/src/llmobs/sdk.js +15 -4
- package/packages/dd-trace/src/llmobs/span_processor.js +13 -2
- package/packages/dd-trace/src/llmobs/tagger.js +20 -10
- package/packages/dd-trace/src/llmobs/util.js +11 -6
- package/packages/dd-trace/src/llmobs/writers/base.js +4 -5
- package/packages/dd-trace/src/log/log.js +1 -5
- package/packages/dd-trace/src/openfeature/evaluation-telemetry-opt-out-hook.js +51 -0
- package/packages/dd-trace/src/openfeature/flagging_provider.js +48 -21
- package/packages/dd-trace/src/openfeature/index.js +6 -0
- package/packages/dd-trace/src/openfeature/writers/util.js +4 -4
- package/packages/dd-trace/src/opentelemetry/logs/otlp_transformer.js +1 -1
- package/packages/dd-trace/src/opentelemetry/metrics/otlp_transformer.js +1 -1
- package/packages/dd-trace/src/opentelemetry/metrics/periodic_metric_reader.js +1 -2
- package/packages/dd-trace/src/opentelemetry/otlp/common.proto +1 -1
- package/packages/dd-trace/src/opentelemetry/trace/otlp_transformer.js +24 -24
- package/packages/dd-trace/src/opentracing/propagation/text_map.js +53 -13
- package/packages/dd-trace/src/otel-sampling.js +4 -5
- package/packages/dd-trace/src/otel-thread-ctx.js +79 -13
- package/packages/dd-trace/src/plugin_manager.js +1 -2
- package/packages/dd-trace/src/plugins/database.js +7 -16
- package/packages/dd-trace/src/plugins/tracing.js +0 -1
- package/packages/dd-trace/src/plugins/util/git.js +99 -59
- package/packages/dd-trace/src/plugins/util/inferred_proxy.js +1 -5
- package/packages/dd-trace/src/plugins/util/stacktrace.js +2 -1
- package/packages/dd-trace/src/plugins/util/test.js +50 -4
- package/packages/dd-trace/src/plugins/util/web.js +90 -20
- package/packages/dd-trace/src/priority_sampler.js +1 -2
- package/packages/dd-trace/src/profiling/profiler.js +4 -6
- package/packages/dd-trace/src/proxy.js +1 -2
- package/packages/dd-trace/src/ritm.js +4 -2
- package/packages/dd-trace/src/serverless.js +5 -0
- package/packages/dd-trace/src/span_processor.js +13 -17
- package/packages/dd-trace/src/span_stats.js +4 -1
- package/packages/dd-trace/src/telemetry/endpoints.js +1 -3
- package/packages/dd-trace/src/telemetry/logs/log-collector.js +1 -1
- package/packages/dd-trace/src/util.js +37 -4
- package/packages/dd-trace/src/web-tags-cache.js +6 -2
- package/vendor/dist/@apm-js-collab/code-transformer/index.js +8 -8
- package/vendor/dist/@datadog/openfeature-node-server/index.js +1 -1
- package/vendor/dist/@datadog/openfeature-node-server/rules-based/LICENSE +201 -0
- package/vendor/dist/@datadog/openfeature-node-server/rules-based/index.d.ts +925 -0
- package/vendor/dist/@datadog/openfeature-node-server/rules-based/index.js +1 -0
- package/vendor/dist/@datadog/sketches-js/index.js +1 -1
- package/vendor/dist/protobufjs/index.js +1 -1
- package/vendor/dist/protobufjs/minimal/index.js +1 -1
- package/vendor/dist/shell-quote/index.js +1 -1
|
@@ -5,6 +5,7 @@ const fs = require('fs')
|
|
|
5
5
|
const { URL } = require('url')
|
|
6
6
|
const { stripVTControlCharacters } = require('node:util')
|
|
7
7
|
const { getLageTestSessionName } = require('../../ci-visibility/lage')
|
|
8
|
+
const resolveRunfilePath = require('../../ci-visibility/resolve-runfile-path')
|
|
8
9
|
const log = require('../../log')
|
|
9
10
|
const { getEnvironmentVariable, getValueFromEnvSources } = require('../../config/helper')
|
|
10
11
|
const { getSegment } = require('../../util')
|
|
@@ -250,8 +251,11 @@ const TEST_LEVEL_EVENT_TYPES = [
|
|
|
250
251
|
'test_module_end',
|
|
251
252
|
'test_session_end',
|
|
252
253
|
]
|
|
254
|
+
const TEST_PARALLELIZATION_ENABLED = 'test.parallelization.enabled'
|
|
255
|
+
const TEST_PARALLELIZATION_PLAN_TAG_PREFIX = 'test.parallelization.plan.'
|
|
253
256
|
const TEST_LEVELS_METADATA = 'test_levels'
|
|
254
257
|
const TEST_LEVELS_METADATA_TAGS = [
|
|
258
|
+
TEST_PARALLELIZATION_ENABLED,
|
|
255
259
|
CI_JOB_ID,
|
|
256
260
|
CI_JOB_NAME,
|
|
257
261
|
CI_JOB_URL,
|
|
@@ -795,6 +799,8 @@ function getTestEnvironmentMetadata (testFramework, config, shouldSkipGitMetadat
|
|
|
795
799
|
commitMessage,
|
|
796
800
|
ciWorkspacePath,
|
|
797
801
|
headCommitSha,
|
|
802
|
+
pullRequestBaseBranchSha: userProvidedGitMetadata[GIT_PULL_REQUEST_BASE_BRANCH_SHA] ||
|
|
803
|
+
ciMetadata[GIT_PULL_REQUEST_BASE_BRANCH_SHA],
|
|
798
804
|
})
|
|
799
805
|
}
|
|
800
806
|
|
|
@@ -809,12 +815,49 @@ function getTestEnvironmentMetadata (testFramework, config, shouldSkipGitMetadat
|
|
|
809
815
|
...userProvidedGitMetadata,
|
|
810
816
|
...runtimeAndOSMetadata,
|
|
811
817
|
}
|
|
818
|
+
if (/^(true|1)$/i.test(getEnvironmentVariable('_DD_TEST_PARALLELIZATION_ENABLED'))) {
|
|
819
|
+
metadata[TEST_PARALLELIZATION_ENABLED] = 'true'
|
|
820
|
+
Object.assign(metadata, getTestParallelizationPlanMetadata())
|
|
821
|
+
}
|
|
812
822
|
if (config && config.service) {
|
|
813
823
|
metadata['service.name'] = config.service
|
|
814
824
|
}
|
|
815
825
|
return removeInvalidMetadata(metadata)
|
|
816
826
|
}
|
|
817
827
|
|
|
828
|
+
/** @returns {Record<string, string>} */
|
|
829
|
+
function getTestParallelizationPlanMetadata () {
|
|
830
|
+
try {
|
|
831
|
+
let metadataFile = getEnvironmentVariable('_DD_TEST_PARALLELIZATION_METADATA_FILE')
|
|
832
|
+
if (!metadataFile) {
|
|
833
|
+
// The manifest locator belongs to DDTest's artifact protocol, rather than tracer configuration.
|
|
834
|
+
// eslint-disable-next-line eslint-rules/eslint-process-env
|
|
835
|
+
const env = process.env
|
|
836
|
+
const manifestFile = env.TEST_OPTIMIZATION_MANIFEST_FILE || env.DD_TEST_OPTIMIZATION_MANIFEST_FILE
|
|
837
|
+
const planDirectory = manifestFile
|
|
838
|
+
? path.dirname(resolveRunfilePath(manifestFile, env))
|
|
839
|
+
: path.join(process.cwd(), '.testoptimization')
|
|
840
|
+
metadataFile = path.join(planDirectory, 'plan-metadata.json')
|
|
841
|
+
}
|
|
842
|
+
const { tags } = JSON.parse(fs.readFileSync(metadataFile, 'utf8'))
|
|
843
|
+
if (!tags || typeof tags !== 'object' || Array.isArray(tags) ||
|
|
844
|
+
Object.values(tags).some(value => typeof value !== 'string')) {
|
|
845
|
+
return {}
|
|
846
|
+
}
|
|
847
|
+
const metadata = {}
|
|
848
|
+
for (const [tag, value] of Object.entries(tags)) {
|
|
849
|
+
if (tag.startsWith(TEST_PARALLELIZATION_PLAN_TAG_PREFIX) &&
|
|
850
|
+
tag.length > TEST_PARALLELIZATION_PLAN_TAG_PREFIX.length && value) {
|
|
851
|
+
metadata[tag] = value
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
return metadata
|
|
855
|
+
} catch (err) {
|
|
856
|
+
log.debug('Failed to read DDTest plan metadata: %s', err.message)
|
|
857
|
+
return {}
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
|
|
818
861
|
function getTestParametersString (parametersByTestName, testName) {
|
|
819
862
|
if (!parametersByTestName[testName]) {
|
|
820
863
|
return ''
|
|
@@ -845,6 +888,11 @@ function getTestLevelsMetadataTags (testEnvironmentMetadata) {
|
|
|
845
888
|
testLevelsMetadataTags[key] = value
|
|
846
889
|
}
|
|
847
890
|
}
|
|
891
|
+
for (const [key, value] of Object.entries(testEnvironmentMetadata)) {
|
|
892
|
+
if (key.startsWith(TEST_PARALLELIZATION_PLAN_TAG_PREFIX) && value !== undefined) {
|
|
893
|
+
testLevelsMetadataTags[key] = value
|
|
894
|
+
}
|
|
895
|
+
}
|
|
848
896
|
return testLevelsMetadataTags
|
|
849
897
|
}
|
|
850
898
|
|
|
@@ -1556,8 +1604,7 @@ function applySkippedCoverageToFileCoverage (fileCoverage, skippedBitmap) {
|
|
|
1556
1604
|
let updated = false
|
|
1557
1605
|
for (const [statementId, statementLocation] of Object.entries(fileCoverage.data.statementMap)) {
|
|
1558
1606
|
const startLine = statementLocation?.start?.line
|
|
1559
|
-
if (!isLineCoveredByBitmap(skippedBitmap, startLine)) continue
|
|
1560
|
-
if (fileCoverage.data.s[statementId] > 0) continue
|
|
1607
|
+
if (!isLineCoveredByBitmap(skippedBitmap, startLine) || fileCoverage.data.s[statementId] > 0) continue
|
|
1561
1608
|
|
|
1562
1609
|
fileCoverage.data.s[statementId] = 1
|
|
1563
1610
|
updated = true
|
|
@@ -2256,8 +2303,7 @@ function recordTestManagementExecution (execution, executions = testManagementEx
|
|
|
2256
2303
|
* }} execution
|
|
2257
2304
|
*/
|
|
2258
2305
|
function recordAttemptToFixExecution (attemptToFixExecutions, execution) {
|
|
2259
|
-
if (!execution?.testName) return
|
|
2260
|
-
if (getValueFromEnvSources('DD_TEST_MANAGEMENT_REPORT_ENABLED') === false) return
|
|
2306
|
+
if (!execution?.testName || getValueFromEnvSources('DD_TEST_MANAGEMENT_REPORT_ENABLED') === false) return
|
|
2261
2307
|
|
|
2262
2308
|
const { testSuite, testName, status, isDisabled, isQuarantined } = execution
|
|
2263
2309
|
const identity = getTestOptimizationIdentity(testSuite, testName)
|
|
@@ -321,20 +321,16 @@ const web = {
|
|
|
321
321
|
const writeHead = res.writeHead
|
|
322
322
|
|
|
323
323
|
return function (statusCode, statusMessage, headers) {
|
|
324
|
-
// CORS preflight tagging only matters for OPTIONS requests. Skip the
|
|
325
|
-
// getHeaders() spread + isOriginAllowed work entirely for the common
|
|
326
|
-
// GET / POST / etc. case. Node's http module passes `req.method`
|
|
327
|
-
// through unchanged, so all standard methods are uppercase; the
|
|
328
|
-
// `toLowerCase` fallback covers any non-standard caller.
|
|
329
324
|
if (req.method === 'OPTIONS' || req.method.toLowerCase() === 'options') {
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
325
|
+
const headerIndex = typeof statusMessage === 'string' || headers != null ? 2 : 1
|
|
326
|
+
const updatedHeaders = addAllowHeaders(req, res, arguments[headerIndex])
|
|
327
|
+
if (updatedHeaders) {
|
|
328
|
+
arguments[headerIndex] = updatedHeaders
|
|
329
|
+
const result = writeHead.apply(this, arguments)
|
|
330
|
+
if (context.config.headers.length > 0) context.responseHeaders = updatedHeaders
|
|
331
|
+
return result
|
|
335
332
|
}
|
|
336
333
|
}
|
|
337
|
-
|
|
338
334
|
return writeHead.apply(this, arguments)
|
|
339
335
|
}
|
|
340
336
|
},
|
|
@@ -362,8 +358,28 @@ function normalizeHeadersCarrier (headers) {
|
|
|
362
358
|
return carrier
|
|
363
359
|
}
|
|
364
360
|
|
|
361
|
+
/**
|
|
362
|
+
* @param {import('node:http').IncomingMessage} req
|
|
363
|
+
* @param {import('node:http').ServerResponse | import('node:http2').Http2ServerResponse} res
|
|
364
|
+
* @param {ResponseHeaders} headers
|
|
365
|
+
*/
|
|
365
366
|
function addAllowHeaders (req, res, headers) {
|
|
366
|
-
|
|
367
|
+
if (!req.headers.origin || !req.headers['access-control-request-headers'] ||
|
|
368
|
+
res.headersSent || res.stream?.destroyed || res.stream?.closed) return
|
|
369
|
+
|
|
370
|
+
const originKey = findHeader(headers, 'access-control-allow-origin')
|
|
371
|
+
const allowOrigin = originKey === undefined
|
|
372
|
+
? res.getHeader('access-control-allow-origin')
|
|
373
|
+
: getHeaderValue(headers, originKey)
|
|
374
|
+
if (allowOrigin !== '*' && allowOrigin !== req.headers.origin) return
|
|
375
|
+
|
|
376
|
+
const allowKey = findHeader(headers, 'access-control-allow-headers')
|
|
377
|
+
const existing = allowKey === undefined
|
|
378
|
+
? res.getHeader('access-control-allow-headers')
|
|
379
|
+
: getHeaderValue(headers, allowKey)
|
|
380
|
+
if (allowKey !== undefined && existing == null) return
|
|
381
|
+
|
|
382
|
+
const allowHeaders = splitHeader(existing)
|
|
367
383
|
const requestHeaders = splitHeader(req.headers['access-control-request-headers'])
|
|
368
384
|
const contextHeaders = [
|
|
369
385
|
'baggage',
|
|
@@ -384,19 +400,69 @@ function addAllowHeaders (req, res, headers) {
|
|
|
384
400
|
}
|
|
385
401
|
|
|
386
402
|
if (allowHeaders.length > 0) {
|
|
387
|
-
|
|
403
|
+
const value = uniq(allowHeaders).join(',')
|
|
404
|
+
if (headers) return setAllowHeaders(headers, allowKey, value)
|
|
405
|
+
res.setHeader('access-control-allow-headers', value)
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/** @typedef {import('node:http').OutgoingHttpHeader} HeaderValue */
|
|
410
|
+
/** @typedef {import('node:http').OutgoingHttpHeaders | Array<HeaderValue | [string, HeaderValue]>} ResponseHeaders */
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* @param {ResponseHeaders} headers
|
|
414
|
+
* @param {string} name
|
|
415
|
+
*/
|
|
416
|
+
function findHeader (headers, name) {
|
|
417
|
+
if (!headers) return
|
|
418
|
+
if (Array.isArray(headers)) {
|
|
419
|
+
const tuples = Array.isArray(headers[0])
|
|
420
|
+
for (let i = headers.length - (tuples ? 1 : 2); i >= 0; i -= tuples ? 1 : 2) {
|
|
421
|
+
const key = tuples ? headers[i][0] : headers[i]
|
|
422
|
+
if (typeof key === 'string' && key.toLowerCase() === name) return tuples ? i : i + 1
|
|
423
|
+
}
|
|
424
|
+
} else {
|
|
425
|
+
const keys = Object.keys(headers)
|
|
426
|
+
for (let i = keys.length - 1; i >= 0; i--) {
|
|
427
|
+
if (keys[i].toLowerCase() === name) return keys[i]
|
|
428
|
+
}
|
|
388
429
|
}
|
|
389
430
|
}
|
|
390
431
|
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
432
|
+
/**
|
|
433
|
+
* @param {ResponseHeaders} headers
|
|
434
|
+
* @param {string | number} key
|
|
435
|
+
*/
|
|
436
|
+
function getHeaderValue (headers, key) {
|
|
437
|
+
return Array.isArray(headers) && Array.isArray(headers[0]) ? headers[key][1] : headers[key]
|
|
438
|
+
}
|
|
394
439
|
|
|
395
|
-
|
|
440
|
+
/**
|
|
441
|
+
* @param {ResponseHeaders} headers
|
|
442
|
+
* @param {string | number | undefined} key
|
|
443
|
+
* @param {string} value
|
|
444
|
+
*/
|
|
445
|
+
function setAllowHeaders (headers, key, value) {
|
|
446
|
+
if (Array.isArray(headers)) {
|
|
447
|
+
const result = []
|
|
448
|
+
const tuples = Array.isArray(headers[0])
|
|
449
|
+
// Native writeHead ignores custom array iterators.
|
|
450
|
+
for (let i = 0; i < headers.length; i++) result.push(headers[i])
|
|
451
|
+
if (key !== undefined) {
|
|
452
|
+
result[key] = tuples ? [headers[key][0], value] : value
|
|
453
|
+
} else if (tuples) {
|
|
454
|
+
result.push(['access-control-allow-headers', value])
|
|
455
|
+
} else {
|
|
456
|
+
result.push('access-control-allow-headers', value)
|
|
457
|
+
}
|
|
458
|
+
return result
|
|
459
|
+
}
|
|
460
|
+
return { ...headers, [key ?? 'access-control-allow-headers']: value }
|
|
396
461
|
}
|
|
397
462
|
|
|
398
463
|
function splitHeader (str) {
|
|
399
|
-
|
|
464
|
+
if (Array.isArray(str)) str = str.join(',')
|
|
465
|
+
return str === undefined ? [] : String(str).split(',').map((header) => header.trim())
|
|
400
466
|
}
|
|
401
467
|
|
|
402
468
|
function addRequestTags (context, spanType) {
|
|
@@ -527,10 +593,14 @@ function addRequestHeaders (context) {
|
|
|
527
593
|
}
|
|
528
594
|
|
|
529
595
|
function addResponseHeaders (context) {
|
|
530
|
-
const { res, config, span, inferredProxySpan } = context
|
|
596
|
+
const { res, config, span, inferredProxySpan, responseHeaders } = context
|
|
531
597
|
|
|
532
598
|
for (const [key, tag] of config.headers) {
|
|
533
|
-
|
|
599
|
+
let resHeader = res.getHeader(key)
|
|
600
|
+
if (resHeader === undefined && responseHeaders) {
|
|
601
|
+
const headerKey = findHeader(responseHeaders, key)
|
|
602
|
+
if (headerKey !== undefined) resHeader = getHeaderValue(responseHeaders, headerKey)
|
|
603
|
+
}
|
|
534
604
|
if (resHeader) {
|
|
535
605
|
const tagName = tag || `${HTTP_RESPONSE_HEADERS}.${key}`
|
|
536
606
|
span.setTag(tagName, resHeader)
|
|
@@ -119,8 +119,7 @@ class PrioritySampler {
|
|
|
119
119
|
const root = context._trace.started[0]
|
|
120
120
|
|
|
121
121
|
// TODO: remove the decision maker tag when priority is less than AUTO_KEEP
|
|
122
|
-
if (context._sampling.priority !== undefined) return
|
|
123
|
-
if (!root) return // noop span
|
|
122
|
+
if (context._sampling.priority !== undefined || !root) return // noop span
|
|
124
123
|
|
|
125
124
|
log.trace(span, auto)
|
|
126
125
|
|
|
@@ -352,11 +352,11 @@ class Profiler extends EventEmitter {
|
|
|
352
352
|
_capture (timeout, start) {
|
|
353
353
|
if (!this.enabled) return
|
|
354
354
|
this.#lastStart = start
|
|
355
|
-
if (
|
|
355
|
+
if (this.#timer && timeout === this._timeoutInterval) {
|
|
356
|
+
this.#timer.refresh()
|
|
357
|
+
} else {
|
|
356
358
|
this.#timer = setTimeout(() => this._collect(snapshotKinds.PERIODIC), timeout)
|
|
357
359
|
this.#timer.unref?.()
|
|
358
|
-
} else {
|
|
359
|
-
this.#timer.refresh()
|
|
360
360
|
}
|
|
361
361
|
}
|
|
362
362
|
|
|
@@ -366,10 +366,8 @@ class Profiler extends EventEmitter {
|
|
|
366
366
|
if (!isWebServerSpan(tags)) return
|
|
367
367
|
|
|
368
368
|
const endpointName = endpointNameFromTags(tags)
|
|
369
|
-
if (!endpointName) return
|
|
370
|
-
|
|
371
369
|
// Make sure this is the outermost web span, just in case so we don't overcount
|
|
372
|
-
if (findWebSpan(getStartedSpans(context), context._parentId)) return
|
|
370
|
+
if (!endpointName || findWebSpan(getStartedSpans(context), context._parentId)) return
|
|
373
371
|
|
|
374
372
|
let counter = this.#endpointCounts.get(endpointName)
|
|
375
373
|
if (counter === undefined) {
|
|
@@ -235,8 +235,7 @@ class Tracer extends NoopProxy {
|
|
|
235
235
|
})
|
|
236
236
|
|
|
237
237
|
rc.setProductHandler('AGENT_TASK', (action, conf) => {
|
|
238
|
-
if (action === 'unapply' || !conf) return
|
|
239
|
-
if (conf.task_type !== 'tracer_flare' || !conf.args) return
|
|
238
|
+
if (action === 'unapply' || !conf || conf.task_type !== 'tracer_flare' || !conf.args) return
|
|
240
239
|
|
|
241
240
|
this._flare.enable(config)
|
|
242
241
|
this._flare.module.send(conf.args)
|
|
@@ -92,8 +92,10 @@ function Hook (modules, options, onrequire) {
|
|
|
92
92
|
let name, basedir, hooks
|
|
93
93
|
// return known patched modules immediately
|
|
94
94
|
if (cache[moduleId]) {
|
|
95
|
-
// require.cache
|
|
96
|
-
|
|
95
|
+
// Use Node's cache: bundlers replace require.cache with their own factory cache,
|
|
96
|
+
// whose not-yet-evaluated external modules can still have empty exports.
|
|
97
|
+
// @ts-expect-error - Module._cache is not typed
|
|
98
|
+
const cacheEntry = Module._cache[filename]
|
|
97
99
|
if (cacheEntry && cacheEntry.exports !== cache[moduleId].original) {
|
|
98
100
|
return cacheEntry.exports
|
|
99
101
|
}
|
|
@@ -32,6 +32,10 @@ function enableGCPPubSubPushSubscription () {
|
|
|
32
32
|
getValueFromEnvSources('DD_TRACE_GCP_PUBSUB_PUSH_ENABLED')
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
function getIsAzureContainerApp () {
|
|
36
|
+
return getEnvironmentVariable('CONTAINER_APP_NAME') !== undefined
|
|
37
|
+
}
|
|
38
|
+
|
|
35
39
|
function getIsAzureFunction () {
|
|
36
40
|
return getEnvironmentVariable('FUNCTIONS_EXTENSION_VERSION') !== undefined &&
|
|
37
41
|
getEnvironmentVariable('FUNCTIONS_WORKER_RUNTIME') !== undefined
|
|
@@ -103,6 +107,7 @@ module.exports = {
|
|
|
103
107
|
supportsServerlessTelemetryRetention,
|
|
104
108
|
createServerlessDeliveryTracker,
|
|
105
109
|
getIsGCPFunction,
|
|
110
|
+
getIsAzureContainerApp,
|
|
106
111
|
getIsAzureFunction,
|
|
107
112
|
enableGCPPubSubPushSubscription,
|
|
108
113
|
getIsFlexConsumptionAzureFunction,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const { AUTO_REJECT } = require('../../../ext/priority')
|
|
3
|
+
const { AUTO_KEEP, AUTO_REJECT } = require('../../../ext/priority')
|
|
4
4
|
const log = require('./log')
|
|
5
5
|
const spanFormat = require('./span_format')
|
|
6
6
|
const SpanSampler = require('./span_sampler')
|
|
@@ -15,32 +15,23 @@ const finishedSpans = new WeakSet()
|
|
|
15
15
|
|
|
16
16
|
let otelSampling
|
|
17
17
|
|
|
18
|
-
/**
|
|
19
|
-
|
|
20
|
-
*
|
|
21
|
-
* @param {import('./opentracing/span')} span
|
|
22
|
-
* @param {boolean} isFirstSpanInChunk
|
|
23
|
-
* @param {string | false} processTagsValue
|
|
24
|
-
*/
|
|
25
|
-
function formatOtlpSpan (span, isFirstSpanInChunk, processTagsValue) {
|
|
26
|
-
const formattedSpan = spanFormat(span, isFirstSpanInChunk, processTagsValue)
|
|
27
|
-
const context = span.context()
|
|
18
|
+
/** @param {import('./opentracing/span_context')} context */
|
|
19
|
+
function serializeOtlpTraceState (context) {
|
|
28
20
|
const traceState = context._tracestate?.clone() ?? new TraceState()
|
|
29
21
|
otelSampling ??= require('./otel-sampling')
|
|
30
22
|
otelSampling.updateOtelTraceState(context, traceState)
|
|
31
|
-
|
|
32
|
-
return formattedSpan
|
|
23
|
+
return traceState.toString()
|
|
33
24
|
}
|
|
34
25
|
|
|
35
26
|
class SpanProcessor {
|
|
36
|
-
#
|
|
27
|
+
#exportOtlpTraces
|
|
37
28
|
|
|
38
29
|
constructor (exporter, prioritySampler, config, otlpStatsExporter, exportOtlpTraces) {
|
|
39
30
|
this._exporter = exporter
|
|
40
31
|
this._prioritySampler = prioritySampler
|
|
41
32
|
this._config = config
|
|
42
33
|
this._killAll = false
|
|
43
|
-
this.#
|
|
34
|
+
this.#exportOtlpTraces = exportOtlpTraces
|
|
44
35
|
|
|
45
36
|
if (config.stats?.DD_TRACE_STATS_COMPUTATION_ENABLED &&
|
|
46
37
|
!config.appsec?.DD_EXPERIMENTAL_APPSEC_STANDALONE_ENABLED) {
|
|
@@ -95,13 +86,18 @@ class SpanProcessor {
|
|
|
95
86
|
let isFirstSpanInChunk = true
|
|
96
87
|
const stampApmDisabled = this._config.apmTracingEnabled === false
|
|
97
88
|
const discard = this.#isDiscarded(spanContext)
|
|
98
|
-
const
|
|
89
|
+
const exportOtlpTraces = this.#exportOtlpTraces && !(spanContext._sampling.priority < AUTO_KEEP)
|
|
90
|
+
let traceState
|
|
99
91
|
|
|
100
92
|
for (const span of started) {
|
|
101
93
|
if (span._duration === undefined) {
|
|
102
94
|
active.push(span)
|
|
103
95
|
} else if (!discard) {
|
|
104
|
-
const formattedSpan =
|
|
96
|
+
const formattedSpan = spanFormat(span, isFirstSpanInChunk, this._processTags)
|
|
97
|
+
if (exportOtlpTraces) {
|
|
98
|
+
traceState ??= serializeOtlpTraceState(spanContext)
|
|
99
|
+
formattedSpan.trace_state = traceState
|
|
100
|
+
}
|
|
105
101
|
if (stampApmDisabled) {
|
|
106
102
|
formattedSpan.metrics[APM_TRACING_ENABLED_KEY] = 0
|
|
107
103
|
}
|
|
@@ -208,6 +208,7 @@ class SpanStatsProcessor {
|
|
|
208
208
|
env,
|
|
209
209
|
tags,
|
|
210
210
|
version: appVersion,
|
|
211
|
+
reportHostname,
|
|
211
212
|
_DD_TRACE_METRICS_OTEL_FLUSH_INTERVAL: flushIntervalMs,
|
|
212
213
|
} = config
|
|
213
214
|
if (!otlpExporter) {
|
|
@@ -217,7 +218,9 @@ class SpanStatsProcessor {
|
|
|
217
218
|
this.interval = intervalMs / 1e3
|
|
218
219
|
this.bucketSizeNs = intervalMs * 1e6
|
|
219
220
|
this.buckets = new TimeBuckets(Boolean(otlpExporter))
|
|
220
|
-
|
|
221
|
+
// A non-empty client hostname takes precedence over the agent's own hostname for the resulting
|
|
222
|
+
// metrics, so only send it when explicitly requested.
|
|
223
|
+
this.hostname = reportHostname ? os.hostname() : ''
|
|
221
224
|
this.enabled = enabled
|
|
222
225
|
this.otlpExporter = otlpExporter || null
|
|
223
226
|
this.env = env
|
|
@@ -95,10 +95,8 @@ function onFastifyRoute (routeData) {
|
|
|
95
95
|
* @param {{ method?: string, path?: string }} param0
|
|
96
96
|
*/
|
|
97
97
|
function onExpressRoute ({ method, path }) {
|
|
98
|
-
if (!method || !path) return
|
|
99
|
-
|
|
100
98
|
// If wildcard already recorded for this path, skip specific methods
|
|
101
|
-
if (wildcardEndpoints.has(path)) return
|
|
99
|
+
if (!method || !path || wildcardEndpoints.has(path)) return
|
|
102
100
|
|
|
103
101
|
recordEndpoint(method, path, 'express.request')
|
|
104
102
|
|
|
@@ -48,7 +48,7 @@ function sanitize (logEntry) {
|
|
|
48
48
|
|
|
49
49
|
for (let i = Math.max(firstIndex, 0); i < lines.length; i++) {
|
|
50
50
|
const line = lines[i]
|
|
51
|
-
if (line.includes(ddBasePath)) {
|
|
51
|
+
if (ddBasePath !== undefined && line.includes(ddBasePath)) {
|
|
52
52
|
stackLines.push(line.replace(ddBasePath, ''))
|
|
53
53
|
} else {
|
|
54
54
|
const match = NODE_FRAME_LINE_REGEX.exec(line)
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const path = require('path')
|
|
4
|
+
const { types: { isTypedArray } } = require('node:util')
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @typedef {Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array |
|
|
8
|
+
* Float32Array | Float64Array | BigInt64Array | BigUint64Array | DataView} BinaryView
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const getTypedArrayLength = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(Uint8Array.prototype), 'length').get
|
|
4
12
|
|
|
5
13
|
/**
|
|
6
14
|
* `for-in` with an early return is the only allocation-free shape for
|
|
@@ -12,11 +20,31 @@ const path = require('path')
|
|
|
12
20
|
* @param {object | undefined} obj
|
|
13
21
|
*/
|
|
14
22
|
function isEmpty (obj) {
|
|
23
|
+
if (Array.isArray(obj) || ArrayBuffer.isView(obj)) {
|
|
24
|
+
// `for-in` materializes every index key up front, which exhausts memory on large bodies, so return as soon as
|
|
25
|
+
// there are elements. Empty ones have no index keys to materialize, so check their own keys, which still detects
|
|
26
|
+
// named properties without walking a Buffer's enumerable prototype methods.
|
|
27
|
+
const length = Array.isArray(obj) ? obj.length : typedArrayLength(obj)
|
|
28
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
29
|
+
return length === 0 && Object.keys(obj).length === 0
|
|
30
|
+
}
|
|
31
|
+
// `for-in` over a string also materializes every index key, so large raw string bodies need the same shortcut.
|
|
32
|
+
if (typeof obj === 'string') return obj.length === 0
|
|
15
33
|
// eslint-disable-next-line no-unreachable-loop
|
|
16
34
|
for (const _ in obj) return false
|
|
17
35
|
return true
|
|
18
36
|
}
|
|
19
37
|
|
|
38
|
+
/**
|
|
39
|
+
* Reads the element count through the intrinsic getter, which, unlike `view.length`, an instance or subclass cannot
|
|
40
|
+
* shadow with application code. A `DataView` exposes no indexed elements, so it counts as zero.
|
|
41
|
+
*
|
|
42
|
+
* @param {BinaryView} view
|
|
43
|
+
*/
|
|
44
|
+
function typedArrayLength (view) {
|
|
45
|
+
return isTypedArray(view) ? getTypedArrayLength.call(view) : 0
|
|
46
|
+
}
|
|
47
|
+
|
|
20
48
|
function isTrue (str) {
|
|
21
49
|
str = String(str).toLowerCase()
|
|
22
50
|
return str === 'true' || str === '1'
|
|
@@ -117,9 +145,12 @@ function stripQueryAndFragment (target) {
|
|
|
117
145
|
}
|
|
118
146
|
|
|
119
147
|
function calculateDDBasePath (dirname) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
148
|
+
// Bundled into ESM output, `__dirname` is not defined. Bundled into CJS output, it is the bundle's directory,
|
|
149
|
+
// which may contain an unrelated `packages` segment (e.g. a monorepo). Only this file's own directory identifies
|
|
150
|
+
// where dd-trace lives.
|
|
151
|
+
const suffix = path.sep + path.join('packages', 'dd-trace', 'src')
|
|
152
|
+
if (dirname === undefined || !dirname.endsWith(suffix)) return
|
|
153
|
+
return dirname.slice(0, -suffix.length) + path.sep
|
|
123
154
|
}
|
|
124
155
|
|
|
125
156
|
function normalizePluginEnvName (envPluginName, makeLowercase = false) {
|
|
@@ -163,8 +194,10 @@ module.exports = {
|
|
|
163
194
|
globMatch,
|
|
164
195
|
getSegment,
|
|
165
196
|
stripQueryAndFragment,
|
|
166
|
-
ddBasePath: globalThis.__DD_ESBUILD_BASEPATH ||
|
|
197
|
+
ddBasePath: globalThis.__DD_ESBUILD_BASEPATH ||
|
|
198
|
+
calculateDDBasePath(typeof __dirname === 'string' ? __dirname : undefined),
|
|
167
199
|
normalizePluginEnvName,
|
|
168
200
|
formatKnuthRate,
|
|
169
201
|
truncateString,
|
|
202
|
+
typedArrayLength,
|
|
170
203
|
}
|
|
@@ -120,8 +120,12 @@ function onTagsUpdate (span) {
|
|
|
120
120
|
// the ancestor's own update is what settles the endpoint. Skipped entirely
|
|
121
121
|
// when nobody is listening, keeping this the same early return it used to be
|
|
122
122
|
// for consumers that only care about web-tag discovery.
|
|
123
|
-
if (
|
|
124
|
-
|
|
123
|
+
if (
|
|
124
|
+
!endpointResolvedCh.hasSubscribers || cached.endpointFinal || cached.webTags !== tags ||
|
|
125
|
+
finalEndpoint(tags) === undefined
|
|
126
|
+
) {
|
|
127
|
+
return
|
|
128
|
+
}
|
|
125
129
|
cached.endpointFinal = true
|
|
126
130
|
endpointResolvedCh.publish(span)
|
|
127
131
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(()=>{var i={"./@apm-js-collab/code-transformer/index.js"(i,s,k){"use strict";i.exports=k("./@apm-js-collab/code-transformer/lib/index.js")},"./@apm-js-collab/code-transformer/lib/index.js"(i,s,k){"use strict";let{InstrumentationMatcher:S}=k("./@apm-js-collab/code-transformer/lib/matcher.js");i.exports={create:function(i,s){return new S(i,s)}}},"./@apm-js-collab/code-transformer/lib/matcher.js"(i,s,k){"use strict";let S=k("./semifies/index.js"),{Transformer:E}=k("./@apm-js-collab/code-transformer/lib/transformer.js");let InstrumentationMatcher=class InstrumentationMatcher{#e=[];#t=null;#r={};#n={};constructor(i,s){this.#e=i,this.#t=s||"diagnostics_channel"}free(){this.#r={}}addTransform(i,s){this.#n[i]=s}getTransformer(i,s,k){k=k.replace(/\\/g,"/");let w=`${i}/${k}@${s}`;if(this.#r[w])return this.#r[w];let C=this.#e.filter(({module:E})=>E.name===i&&("string"==typeof E.filePath?E.filePath===k:E.filePath.test(k))&&S(s,E.versionRange));if(0!==C.length)return this.#r[w]=new E(i,s,k,C,this.#t,this.#n),this.#r[w]}};i.exports={InstrumentationMatcher}},"./@apm-js-collab/code-transformer/lib/transformer.js"(i,s,k){"use strict";let S,E,w=k("./esquery/dist/esquery.min.js"),{parse:C}=k("./meriyah/dist/meriyah.cjs"),{generate:T}=k("./astring/dist/astring.js"),_=k("./@apm-js-collab/code-transformer/lib/transforms.js");let Transformer=class Transformer{#a=null;#o=null;#i=null;#e=[];#t=null;#n={};constructor(i,s,k,S,E,w={}){this.#a=i,this.#o=s,this.#i=k,this.#e=S,this.#t=E,this.#n=w}free(){}get moduleName(){return this.#a}get filePath(){return this.#i}transform(i,s,O){let N
|
|
1
|
+
(()=>{var i={"./@apm-js-collab/code-transformer/index.js"(i,s,k){"use strict";i.exports=k("./@apm-js-collab/code-transformer/lib/index.js")},"./@apm-js-collab/code-transformer/lib/index.js"(i,s,k){"use strict";let{InstrumentationMatcher:S}=k("./@apm-js-collab/code-transformer/lib/matcher.js");i.exports={create:function(i,s){return new S(i,s)}}},"./@apm-js-collab/code-transformer/lib/matcher.js"(i,s,k){"use strict";let S=k("./semifies/index.js"),{Transformer:E}=k("./@apm-js-collab/code-transformer/lib/transformer.js");let InstrumentationMatcher=class InstrumentationMatcher{#e=[];#t=null;#r={};#n={};constructor(i,s){this.#e=i,this.#t=s||"diagnostics_channel"}free(){this.#r={}}addTransform(i,s){this.#n[i]=s}getTransformer(i,s,k){k=k.replace(/\\/g,"/");let w=`${i}/${k}@${s}`;if(this.#r[w])return this.#r[w];let C=this.#e.filter(({module:E})=>E.name===i&&("string"==typeof E.filePath?E.filePath===k:E.filePath.test(k))&&S(s,E.versionRange));if(0!==C.length)return this.#r[w]=new E(i,s,k,C,this.#t,this.#n),this.#r[w]}};i.exports={InstrumentationMatcher}},"./@apm-js-collab/code-transformer/lib/transformer.js"(i,s,k){"use strict";let S,E,w=k("./esquery/dist/esquery.min.js"),{parse:C}=k("./meriyah/dist/meriyah.cjs"),{generate:T}=k("./astring/dist/astring.js"),_=k("./@apm-js-collab/code-transformer/lib/transforms.js");let Transformer=class Transformer{#a=null;#o=null;#i=null;#e=[];#t=null;#n={};constructor(i,s,k,S,E,w={}){this.#a=i,this.#o=s,this.#i=k,this.#e=S,this.#t=E,this.#n=w}free(){}get moduleName(){return this.#a}get filePath(){return this.#i}transform(i,s,O,N){let D,q=N?.sourceFile||`${this.#a}/${this.#i}`;if(Buffer.isBuffer(i)&&(i=i.toString()),!i)return{code:i};let j={},R=0,$={..._,...this.#n,defaults:{..._}};for(let k of this.#e){let{astQuery:S,functionQuery:E={}}=k;if(!D){let k={loc:!0,ranges:!0,raw:!0,module:"esm"===s};try{D=C(i,k)}catch{D=C(i,{...k,module:!k.module})}"esm"===s&&(j=this.#s(D))}let T=this.#l(E,j),_=S||this.#c(T),O={...k,dcModule:this.#t,moduleType:s,moduleVersion:this.#o,functionQuery:T,transforms:$};O.operator=this.#u(O),w.traverse(D,w.parse(_),(...i)=>{R++,this.#p(O,...i)})}if(0===R&&this.#e.length>0){let i=this.#e.map(({astQuery:i,functionQuery:s={}})=>{if(i)return i;let k=this.#l(s,j),S=s.methodName||s.privateMethodName||s.functionName||s.expressionName||"constructor",E=s.className||s.functionName||s.expressionName,w=k.className||k.functionName||k.expressionName;return E&&E!==w?`${E} (local name: ${w})`:S});throw Error(`Failed to find injection points for: ${JSON.stringify(i)}`)}if(D){S??=k("./@apm-js-collab/code-transformer/node_modules/source-map/source-map.js").SourceMapConsumer;let s=new(E??=k("./@apm-js-collab/code-transformer/node_modules/source-map/source-map.js").SourceMapGenerator)({file:q});s.setSourceContent(q,i);let w=T(D,{sourceMap:s});return O&&s.applySourceMap(new S(O),q),{code:w,map:s.toString()}}return{code:i}}#p(i,...s){let k="function"==typeof i.transform?i.transform:i.transforms[i.operator],{index:S=0}=i.functionQuery,[E]=s,w=E.init?.type||E.type;if("ClassDeclaration"===w||"ClassExpression"===w||"VariableDeclarator"!==E.type&&(i.functionIndex=++i.functionIndex||0,null===S||S===i.functionIndex))k(i,...s)}#u({transform:i,functionQuery:{kind:s}}){if("string"==typeof i)return i;switch(s){case"Async":return"tracePromise";case"Auto":return"traceAuto";case"Callback":return"traceCallback";default:return"traceSync"}}#s(i){let s={};for(let k of i.body)if("ExportNamedDeclaration"===k.type&&!k.source){for(let i of k.specifiers)if(i.exported&&i.local){let k=i.exported.name??i.exported.value,S=i.local.name??i.local.value;k&&S&&(s[k]=S)}}return s}#l(i,s){if(!i.isExportAlias)return i;let{functionName:k,expressionName:S,className:E}=i;return k&&s[k]?{...i,functionName:s[k]}:S&&s[S]?{...i,expressionName:s[S]}:E&&s[E]?{...i,className:s[E]}:i}#c(i){let{functionName:s,expressionName:k,className:S,objectName:E,propertyName:w}=i,C=i.privateMethodName?"PrivateIdentifier":"Identifier",T=[],_=i.methodName||i.privateMethodName;if(S?(_??="constructor",T.push(`[id.name="${S}"]`,`[id.name="${S}"] > ClassExpression`,`[id.name="${S}"] > ClassBody > [key.name="${_}"][key.type=${C}] > [async]`,`[id.name="${S}"] > ClassExpression > ClassBody > [key.name="${_}"][key.type=${C}] > [async]`)):_&&T.push(`ClassBody > [key.name="${_}"][key.type=${C}] > [async]`,`Property[key.name="${_}"][key.type=${C}] > [async]`),s?T.push(`FunctionDeclaration[id.name="${s}"][async]`):k&&T.push(`FunctionExpression[id.name="${k}"][async]`,`ArrowFunctionExpression[id.name="${k}"][async]`,`VariableDeclarator[id.name="${k}"] > FunctionExpression[async]`,`VariableDeclarator[id.name="${k}"] > ArrowFunctionExpression[async]`,`AssignmentExpression[left.property.name="${k}"] > FunctionExpression[async]`,`AssignmentExpression[left.property.name="${k}"] > ArrowFunctionExpression[async]`,`AssignmentExpression[left.name="${k}"] > FunctionExpression[async]`,`AssignmentExpression[left.name="${k}"] > ArrowFunctionExpression[async]`),E||w){if(!E||!w)throw Error(`functionQuery: 'objectName' and 'propertyName' must be used together (got objectName=${E}, propertyName=${w})`);let i="this"===E?"left.object.type=ThisExpression":`left.object.name="${E}"`;T.push(`AssignmentExpression[${i}][left.property.name="${w}"] > [async]`)}return T.join(", ")}};i.exports={Transformer}},"./@apm-js-collab/code-transformer/lib/transforms.js"(i,s,k){"use strict";let S=k("./esquery/dist/esquery.min.js"),{parse:E}=k("./meriyah/dist/meriyah.cjs"),tracingChannelPredicate=i=>i.declarations?.[0]?.id?.properties?.[0]?.value?.name==="tr_ch_apm_tracingChannel",w=/[^\w]/g,formatChannelVariable=i=>`tr_ch_apm$${i.replace(w,"_")}`;function wrapParams(i){return[...(i||[]).filter(i=>"RestElement"!==i.type&&"AssignmentPattern"!==i.type).map((i,s)=>({type:"Identifier",name:`__apm$arg${s}`})),{type:"RestElement",argument:{type:"Identifier",name:"__apm$args"}}]}function traceAny(i,s,k,S){let E=S[S.length-1];"ClassDeclaration"===s.type||"ClassExpression"===s.type?traceInstanceMethod(i,s,E):traceFunction(i,s,E)}function isChannelRunStoresReturn(i,s){if("ReturnStatement"!==i.type)return!1;let k=i.argument?.type==="CallExpression"?i.argument.callee:null;return k?.type==="MemberExpression"&&k.property?.name==="runStores"&&k.object?.type==="MemberExpression"&&k.object.property?.name==="start"&&k.object.object?.type==="Identifier"&&k.object.object.name===s}function nextWrappedFunction(i){let declInit=(i,s)=>{let k=i?.find(i=>"VariableDeclaration"===i.type&&i.declarations.some(i=>i.id?.name===s));return k?.declarations.find(i=>i.id?.name===s)?.init??null},s=declInit(i,"__apm$traced"),k=declInit(s?.body?.body,"__apm$wrapped"),S=k?.type;return"FunctionExpression"===S||"ArrowFunctionExpression"===S||"FunctionDeclaration"===S?k:null}function isWrappedForChannel(i,s){let k=new Set,S=i;for(;S&&!k.has(S);){k.add(S);let i=S.body?.body;if(!Array.isArray(i))break;if(i.some(i=>isChannelRunStoresReturn(i,s)))return!0;S=nextWrappedFunction(i)}return!1}function constructorPatchesMethod(i,s){let k=i?.value?.body?.body;return!!Array.isArray(k)&&k.some(i=>"VariableDeclaration"===i.type&&i.declarations.some(i=>i.id?.name===s))}function traceFunction(i,s,k){if(isWrappedForChannel(s,formatChannelVariable(i.channelName)))return;i.transforms.tracingChannelDeclaration(i,k);let{functionQuery:{methodName:S,privateMethodName:E,functionName:w,expressionName:C,propertyName:T}}=i,_="constructor"===S||!S&&!E&&!w&&!C&&!T,O=_?"ArrowFunctionExpression":s.type,N=s.params,D=`${formatChannelVariable(i.channelName)}$self`;i.selfBinding=_&&captureSelfAtSuper(s,D)?D:null,s.body=wrap(i,{type:O,params:N,body:s.body,async:s.async,expression:!1,generator:s.generator},k),s.params=wrapParams(N),s.generator=!1,s.async=!1,"ArrowFunctionExpression"!==O&&wrapSuper(i,s)}function traceInstanceMethod(i,s,k){let{functionQuery:S,operator:w,channelName:C}=i,{methodName:T}=S;if(!T)return;let _=s.body;if(_.body.some(({key:i})=>i?.name===T))return;let O=_.body.find(({kind:i})=>"constructor"===i),N=`${formatChannelVariable(C)}$${T}`;if(O&&constructorPatchesMethod(O,N))return;i.transforms.tracingChannelDeclaration(i,k),O||(O=E(s.superClass?"class A extends Object { constructor (...args) { super(...args) } }":"class A { constructor () {} }").body[0].body.body[0],_.body.unshift(O));let D=E(`
|
|
2
2
|
const ${N} = this["${T}"]
|
|
3
3
|
this["${T}"] = function () {}
|
|
4
4
|
if (typeof ${N} === 'function') {
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
configurable: true
|
|
8
8
|
})
|
|
9
9
|
}
|
|
10
|
-
`).body,q=D[1].expression.right;q.params=[{type:"RestElement",argument:{type:"Identifier",name:"__apm$args"}}],q.async="tracePromise"===w,q.body=wrap(i,{type:"Identifier",name:N},k),wrapSuper(i,q),O.value.body.body.push(...D)}function wrap(i,s,k){let w,{operator:C,moduleVersion:T}=i,{returnKind:
|
|
11
|
-
const __apm$arguments = [${
|
|
10
|
+
`).body,q=D[1].expression.right;q.params=[{type:"RestElement",argument:{type:"Identifier",name:"__apm$args"}}],q.async="tracePromise"===w,i.selfBinding=null,q.body=wrap(i,{type:"Identifier",name:N},k),wrapSuper(i,q),O.value.body.body.push(...D)}function wrap(i,s,k){let w,{operator:C,moduleVersion:T,selfBinding:_}=i,{returnKind:O}=i.functionQuery,N=O?generateIterPatch(i,O,k):"";"traceCallback"===C&&(w=wrapCallback(i,s,N)),"tracePromise"===C&&(w=wrapPromise(i,s,N)),"traceSync"===C&&(w=wrapSync(i,s,N)),"traceAuto"===C&&(w=wrapAuto(i,s,N));let D=(s.params||[]).filter(i=>"RestElement"!==i.type&&"AssignmentPattern"!==i.type).map((i,s)=>`__apm$arg${s}`).concat("...__apm$args").join(", "),q=w.body[0].body,j=E((_?`let ${_};`:"")+("ArrowFunctionExpression"===s.type?`
|
|
11
|
+
const __apm$arguments = [${D}];
|
|
12
12
|
const __apm$ctx = {
|
|
13
13
|
arguments: __apm$arguments,
|
|
14
14
|
moduleVersion: ${JSON.stringify(T)}
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
return __apm$wrapped(...__apm$arguments);
|
|
19
19
|
};
|
|
20
20
|
`:`
|
|
21
|
-
const __apm$arguments = [${
|
|
21
|
+
const __apm$arguments = [${D}].slice(0, arguments.length);
|
|
22
22
|
const __apm$ctx = {
|
|
23
23
|
arguments: __apm$arguments,
|
|
24
24
|
self: this,
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
const __apm$wrapped = () => {};
|
|
29
29
|
return __apm$wrapped.apply(this, __apm$arguments);
|
|
30
30
|
};
|
|
31
|
-
`).body;return
|
|
31
|
+
`)).body;return q.body.unshift(...j),S.query(q,"[id.name=__apm$wrapped]")[0].init=s,q}function captureSelfAtSuper(i,s){let k=!1,visit=(i,S)=>{let w=i[S];if(null!==w&&"object"==typeof w){if(Array.isArray(w)){for(let i=0;i<w.length;i++)visit(w,i);return}if("string"==typeof w.type&&"ClassBody"!==w.type&&"FunctionExpression"!==w.type&&"FunctionDeclaration"!==w.type){if("CallExpression"===w.type&&"Super"===w.callee.type){let C=E(`(0, ${s} = this)`).body[0].expression;C.expressions[0]=w,i[S]=C,k=!0;return}for(let i of Object.keys(w))visit(w,i)}}};return visit(i,"body"),k}function wrapSuper(i,s){let k=new Set;for(let i of(S.traverse(s.body,S.parse("[object.type=Super]"),(i,s)=>{let S,{name:w}=i.property;if(s.callee){let{expression:i}=E(`__apm$super['${w}'].call(this)`).body[0];s.callee=S=i.callee,s.arguments.unshift(...i.arguments)}else s.expression=S=E(`__apm$super['${w}']`).body[0];S.computed=s.callee.computed,S.optional=s.callee.optional,k.add(w)}),k)){let k=E(`
|
|
32
32
|
class Wrapper {
|
|
33
33
|
wrapper () {
|
|
34
34
|
__apm$super['${i}'] = super['${i}']
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
${C}.error.publish(__apm$ctx);
|
|
74
74
|
throw err;
|
|
75
75
|
} finally {
|
|
76
|
-
__apm$ctx.self ??= this;
|
|
76
|
+
__apm$ctx.self ??= ${(({selfBinding:i})=>i||"this")(i)};
|
|
77
77
|
${C}.end.publish(__apm$ctx);
|
|
78
78
|
}
|
|
79
79
|
});
|
|
@@ -134,7 +134,7 @@
|
|
|
134
134
|
${w}.error.publish(__apm$ctx);
|
|
135
135
|
throw err;
|
|
136
136
|
} finally {
|
|
137
|
-
__apm$ctx.self ??= this;
|
|
137
|
+
__apm$ctx.self ??= ${(({selfBinding:i})=>i||"this")(i)};
|
|
138
138
|
${w}.end.publish(__apm$ctx);
|
|
139
139
|
}
|
|
140
140
|
});
|
|
@@ -152,7 +152,7 @@
|
|
|
152
152
|
${w}.error.publish(__apm$ctx);
|
|
153
153
|
throw err;
|
|
154
154
|
} finally {
|
|
155
|
-
__apm$ctx.self ??= this;
|
|
155
|
+
__apm$ctx.self ??= ${(({selfBinding:i})=>i||"this")(i)};
|
|
156
156
|
${w}.end.publish(__apm$ctx);
|
|
157
157
|
}
|
|
158
158
|
return __apm$ctx.result;
|