dd-trace 6.13.0 → 6.14.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 +3 -1
- package/ci/init.js +8 -3
- package/ci/test-optimization-validation/ci-package-scripts.js +2 -2
- package/ci/test-optimization-validation/ci-remediation.js +6 -6
- package/ci/test-optimization-validation/command-blocker.js +7 -5
- package/ci/test-optimization-validation/framework-adapters/cucumber.js +1 -1
- package/ci/test-optimization-validation/framework-adapters/vitest.js +3 -3
- package/ci/test-optimization-validation/package-check.js +1 -1
- package/ci/test-optimization-validation/report-writer.js +7 -5
- package/ci/vitest-no-worker-init-runner-setup.mjs +8 -0
- package/ci/vitest-no-worker-init-setup.mjs +13 -13
- package/ci/vitest-no-worker-init-v5-setup.mjs +4 -0
- package/package.json +13 -10
- package/packages/datadog-esbuild/index.js +3 -1
- package/packages/datadog-instrumentations/src/cypress-config.js +19 -17
- package/packages/datadog-instrumentations/src/fs.js +24 -20
- package/packages/datadog-instrumentations/src/google-cloud-vertexai.js +2 -2
- package/packages/datadog-instrumentations/src/graphql.js +16 -16
- package/packages/datadog-instrumentations/src/helpers/graphql-jit-runtime.js +504 -0
- package/packages/datadog-instrumentations/src/helpers/hooks.js +2 -0
- package/packages/datadog-instrumentations/src/helpers/pool-acquire.js +265 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/compiler.js +1 -2
- package/packages/datadog-instrumentations/src/helpers/rewriter/index.js +95 -30
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/ai.js +0 -25
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/graphql-jit.js +83 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/graphql.js +85 -1
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/index.js +1 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/mercurius.js +30 -12
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/playwright.js +13 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/webdriverio.js +251 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/targets.json +11 -1
- package/packages/datadog-instrumentations/src/helpers/rewriter/transforms.js +562 -27
- package/packages/datadog-instrumentations/src/jest.js +25 -20
- package/packages/datadog-instrumentations/src/knex.js +76 -0
- package/packages/datadog-instrumentations/src/mariadb.js +6 -0
- package/packages/datadog-instrumentations/src/mocha/common.js +59 -2
- package/packages/datadog-instrumentations/src/mocha/main.js +25 -15
- package/packages/datadog-instrumentations/src/mocha/utils.js +2 -1
- package/packages/datadog-instrumentations/src/mocha/webdriverio-protocol.js +98 -0
- package/packages/datadog-instrumentations/src/mocha/worker.js +12 -8
- package/packages/datadog-instrumentations/src/net.js +14 -17
- package/packages/datadog-instrumentations/src/next.js +212 -62
- package/packages/datadog-instrumentations/src/openai.js +42 -40
- package/packages/datadog-instrumentations/src/pg.js +15 -0
- package/packages/datadog-instrumentations/src/playwright.js +109 -13
- package/packages/datadog-instrumentations/src/rum-browser-scripts.js +40 -0
- package/packages/datadog-instrumentations/src/sequelize.js +94 -2
- package/packages/datadog-instrumentations/src/undici.js +53 -4
- package/packages/datadog-instrumentations/src/vitest-main-no-worker-init.js +37 -3
- package/packages/datadog-instrumentations/src/vitest-main.js +92 -9
- package/packages/datadog-instrumentations/src/vitest-worker.js +71 -14
- package/packages/datadog-instrumentations/src/webdriverio.js +965 -6
- package/packages/datadog-plugin-amqp10/src/consumer.js +3 -1
- package/packages/datadog-plugin-amqp10/src/producer.js +3 -1
- package/packages/datadog-plugin-amqp10/src/util.js +2 -1
- package/packages/datadog-plugin-avsc/src/schema_iterator.js +6 -1
- package/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/utils.js +16 -5
- package/packages/datadog-plugin-cassandra-driver/src/index.js +8 -3
- package/packages/datadog-plugin-cucumber/src/index.js +0 -2
- package/packages/datadog-plugin-cypress/src/cypress-plugin.js +262 -48
- package/packages/datadog-plugin-google-cloud-pubsub/src/client.js +4 -1
- package/packages/datadog-plugin-graphql/src/execute.js +998 -196
- package/packages/datadog-plugin-graphql/src/index.js +27 -7
- package/packages/datadog-plugin-graphql/src/jit.js +136 -0
- package/packages/datadog-plugin-graphql/src/request.js +18 -27
- package/packages/datadog-plugin-graphql/src/resolve-error.js +108 -0
- package/packages/datadog-plugin-graphql/src/tools/signature.js +1 -2
- package/packages/datadog-plugin-graphql/src/tools/transforms.js +45 -3
- package/packages/datadog-plugin-graphql/src/utils.js +208 -120
- package/packages/datadog-plugin-graphql/src/validate.js +10 -23
- package/packages/datadog-plugin-jest/src/index.js +0 -6
- package/packages/datadog-plugin-langchain/src/tracing.js +7 -0
- package/packages/datadog-plugin-mocha/src/index.js +403 -75
- package/packages/datadog-plugin-mongodb-core/src/query.js +6 -0
- package/packages/datadog-plugin-mysql/src/index.js +41 -15
- package/packages/datadog-plugin-net/src/tcp.js +3 -1
- package/packages/datadog-plugin-next/src/index.js +63 -29
- package/packages/datadog-plugin-playwright/src/index.js +167 -27
- package/packages/datadog-plugin-undici/src/index.js +27 -41
- package/packages/datadog-plugin-vitest/src/index.js +6 -12
- package/packages/dd-trace/src/aiguard/evaluation.js +2 -1
- package/packages/dd-trace/src/aiguard/messages/anthropic.js +8 -1
- package/packages/dd-trace/src/aiguard/messages/openai.js +8 -1
- package/packages/dd-trace/src/aiguard/messages/vercel-ai.js +20 -6
- package/packages/dd-trace/src/appsec/api_security/index.js +23 -6
- package/packages/dd-trace/src/appsec/api_security/sampler.js +99 -40
- package/packages/dd-trace/src/appsec/graphql.js +6 -2
- package/packages/dd-trace/src/appsec/iast/taint-tracking/plugin.js +3 -3
- package/packages/dd-trace/src/appsec/iast/taint-tracking/taint-tracking-impl.js +2 -1
- package/packages/dd-trace/src/appsec/iast/telemetry/span-tags.js +8 -2
- package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-analyzers/sql-sensitive-analyzer.js +11 -36
- package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-analyzers/url-sensitive-analyzer.js +1 -1
- package/packages/dd-trace/src/appsec/lambda.js +44 -26
- package/packages/dd-trace/src/ci-visibility/encode/json-encoder.js +32 -2
- package/packages/dd-trace/src/ci-visibility/exporters/agent-proxy/index.js +8 -8
- package/packages/dd-trace/src/ci-visibility/exporters/agentless/coverage-writer.js +6 -4
- package/packages/dd-trace/src/ci-visibility/exporters/agentless/di-logs-writer.js +20 -4
- package/packages/dd-trace/src/ci-visibility/exporters/agentless/request-tracker.js +5 -173
- package/packages/dd-trace/src/ci-visibility/exporters/agentless/writer.js +7 -6
- package/packages/dd-trace/src/ci-visibility/exporters/agents.js +54 -0
- package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/writer.js +1 -2
- package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +394 -225
- package/packages/dd-trace/src/ci-visibility/exporters/limits.js +9 -0
- package/packages/dd-trace/src/ci-visibility/exporters/request.js +323 -31
- package/packages/dd-trace/src/ci-visibility/exporters/settings-cache-key.js +42 -0
- package/packages/dd-trace/src/ci-visibility/final-flush.js +2 -1
- package/packages/dd-trace/src/ci-visibility/requests/fs-cache.js +57 -18
- package/packages/dd-trace/src/ci-visibility/requests/get-library-configuration.js +0 -3
- package/packages/dd-trace/src/ci-visibility/requests/upload-test-screenshot.js +164 -71
- package/packages/dd-trace/src/ci-visibility/requests/video-request.js +176 -0
- package/packages/dd-trace/src/ci-visibility/telemetry.js +10 -7
- package/packages/dd-trace/src/ci-visibility/test-video.js +61 -0
- package/packages/dd-trace/src/config/generated-config-types.d.ts +4 -0
- package/packages/dd-trace/src/config/index.js +73 -13
- package/packages/dd-trace/src/config/parsers.js +11 -1
- package/packages/dd-trace/src/config/stable.js +3 -3
- package/packages/dd-trace/src/config/supported-configurations.json +20 -2
- package/packages/dd-trace/src/crashtracking/crashtracker.js +82 -18
- package/packages/dd-trace/src/debugger/config.js +12 -1
- package/packages/dd-trace/src/debugger/constants.js +1 -0
- package/packages/dd-trace/src/debugger/devtools_client/breakpoints.js +2 -1
- package/packages/dd-trace/src/debugger/devtools_client/request-options.js +33 -0
- package/packages/dd-trace/src/debugger/devtools_client/send.js +7 -40
- package/packages/dd-trace/src/debugger/devtools_client/status.js +11 -6
- package/packages/dd-trace/src/debugger/devtools_client/tags.js +41 -0
- package/packages/dd-trace/src/debugger/index.js +23 -3
- package/packages/dd-trace/src/dogstatsd.js +510 -76
- package/packages/dd-trace/src/encode/0.4-cross-payload.js +170 -0
- package/packages/dd-trace/src/encode/0.4.js +5 -5
- package/packages/dd-trace/src/encode/agentless-ci-visibility.js +9 -8
- package/packages/dd-trace/src/evp_proxy/direct.js +27 -23
- package/packages/dd-trace/src/exporters/agent/index.js +2 -1
- package/packages/dd-trace/src/exporters/agent/writer.js +24 -7
- package/packages/dd-trace/src/exporters/agentless/index.js +7 -9
- package/packages/dd-trace/src/exporters/agentless/writer.js +100 -118
- package/packages/dd-trace/src/exporters/common/agents.js +28 -6
- package/packages/dd-trace/src/exporters/common/buffering-exporter.js +2 -2
- package/packages/dd-trace/src/exporters/common/final-flush-request-tracker.js +191 -0
- package/packages/dd-trace/src/exporters/common/request.js +31 -11
- package/packages/dd-trace/src/exporters/common/url.js +40 -1
- package/packages/dd-trace/src/exporters/common/writer.js +9 -7
- package/packages/dd-trace/src/flush.js +6 -3
- package/packages/dd-trace/src/id.js +14 -0
- package/packages/dd-trace/src/index.js +5 -2
- package/packages/dd-trace/src/llmobs/experiments/dataset.js +2 -1
- package/packages/dd-trace/src/llmobs/index.js +32 -32
- package/packages/dd-trace/src/llmobs/plugins/ai/ddTelemetry.js +22 -71
- package/packages/dd-trace/src/llmobs/plugins/ai/vercelTelemetry.js +23 -13
- package/packages/dd-trace/src/llmobs/plugins/langchain/index.js +7 -0
- package/packages/dd-trace/src/llmobs/util.js +0 -33
- package/packages/dd-trace/src/llmobs/writers/base.js +49 -32
- package/packages/dd-trace/src/log/index.js +7 -1
- package/packages/dd-trace/src/{ci-visibility/log-submission → log-submission}/log-submission-plugin.js +48 -19
- package/packages/dd-trace/src/openfeature/writers/base.js +14 -12
- package/packages/dd-trace/src/openfeature/writers/util.js +1 -1
- package/packages/dd-trace/src/opentelemetry/logs/index.js +5 -24
- package/packages/dd-trace/src/opentelemetry/logs/otlp_http_log_exporter.js +14 -4
- package/packages/dd-trace/src/opentelemetry/metrics/index.js +15 -22
- package/packages/dd-trace/src/opentelemetry/metrics/otlp_http_metric_exporter.js +14 -4
- package/packages/dd-trace/src/opentelemetry/metrics/otlp_span_stats_exporter.js +10 -0
- package/packages/dd-trace/src/opentelemetry/otlp/otlp_transformer_base.js +19 -4
- package/packages/dd-trace/src/opentelemetry/resource-attributes.js +55 -0
- package/packages/dd-trace/src/opentelemetry/trace/index.js +6 -1
- package/packages/dd-trace/src/opentelemetry/trace/otlp_http_trace_exporter.js +10 -0
- package/packages/dd-trace/src/opentracing/propagation/text_map.js +93 -18
- package/packages/dd-trace/src/payload-tagging/index.js +2 -1
- package/packages/dd-trace/src/plugins/ci_plugin.js +1 -6
- package/packages/dd-trace/src/plugins/tracing.js +12 -10
- package/packages/dd-trace/src/plugins/util/ci.js +3 -1
- package/packages/dd-trace/src/plugins/util/inferred_proxy.js +16 -15
- package/packages/dd-trace/src/plugins/util/test.js +83 -20
- package/packages/dd-trace/src/plugins/util/url.js +2 -2
- package/packages/dd-trace/src/plugins/util/web.js +4 -9
- package/packages/dd-trace/src/profiling/config.js +1 -0
- package/packages/dd-trace/src/profiling/oom.js +7 -2
- package/packages/dd-trace/src/profiling/profiler.js +23 -13
- package/packages/dd-trace/src/profiling/profilers/space.js +38 -11
- package/packages/dd-trace/src/profiling/webspan-utils.js +7 -4
- package/packages/dd-trace/src/proxy.js +75 -5
- package/packages/dd-trace/src/remote_config/index.js +319 -101
- package/packages/dd-trace/src/remote_config/scheduler.js +37 -12
- package/packages/dd-trace/src/runtime_metrics/client.js +37 -8
- package/packages/dd-trace/src/runtime_metrics/otlp_runtime_metrics.js +5 -1
- package/packages/dd-trace/src/runtime_metrics/runtime_metrics.js +5 -1
- package/packages/dd-trace/src/sampling_rule.js +36 -9
- package/packages/dd-trace/src/serverless/telemetry-delivery-tracker.js +4 -8
- package/packages/dd-trace/src/serverless/vercel.js +53 -20
- package/packages/dd-trace/src/serverless.js +10 -3
- package/packages/dd-trace/src/service-naming/schemas/util.js +1 -1
- package/packages/dd-trace/src/span_stats.js +24 -28
- package/packages/dd-trace/src/startup-log.js +3 -2
- package/packages/dd-trace/src/telemetry/agentless-url.js +28 -0
- package/packages/dd-trace/src/telemetry/send-data.js +18 -16
- package/packages/dd-trace/src/telemetry/session-propagation.js +3 -2
- package/packages/dd-trace/src/tracer.js +4 -5
- package/packages/dd-trace/src/tracer_metadata.js +11 -3
- 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/packages/datadog-instrumentations/src/playwright-browser-scripts.js +0 -27
- package/packages/dd-trace/src/encode/agentless-json.js +0 -210
|
@@ -0,0 +1,504 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @typedef {{
|
|
5
|
+
* collapsedPath: string,
|
|
6
|
+
* collapsedPathSegments: string[],
|
|
7
|
+
* parentPathKey: string | undefined,
|
|
8
|
+
* pathDepth: number,
|
|
9
|
+
* pathKey: string,
|
|
10
|
+
* runtimePath: string,
|
|
11
|
+
* selectionDepth: number
|
|
12
|
+
* }} CompilerPathAnalysis
|
|
13
|
+
* @typedef {{
|
|
14
|
+
* fieldName: string,
|
|
15
|
+
* fieldNodes: [import('graphql').FieldNode, ...import('graphql').FieldNode[]],
|
|
16
|
+
* returnType: import('graphql').GraphQLOutputType,
|
|
17
|
+
* parentType: import('graphql').GraphQLCompositeType
|
|
18
|
+
* }} DescriptorInput
|
|
19
|
+
* @typedef {{
|
|
20
|
+
* key: string,
|
|
21
|
+
* prev?: ArgumentPath
|
|
22
|
+
* }} ArgumentPath
|
|
23
|
+
* @typedef {{
|
|
24
|
+
* missing: { path: ArgumentPath, valueNode: { name: { value: string } } }[],
|
|
25
|
+
* values: Record<string, unknown>
|
|
26
|
+
* }} CompiledArguments
|
|
27
|
+
* @typedef {{
|
|
28
|
+
* baseTypeName: string,
|
|
29
|
+
* resource: string,
|
|
30
|
+
* tags: Record<string, string | undefined>
|
|
31
|
+
* }} FieldMetadata
|
|
32
|
+
* @typedef {{
|
|
33
|
+
* id: number,
|
|
34
|
+
* baseTypeName: string,
|
|
35
|
+
* collapsedPath: string,
|
|
36
|
+
* collapsedPathSegments: string[],
|
|
37
|
+
* staticArguments?: Record<string, unknown>,
|
|
38
|
+
* hasArgumentVariables?: boolean,
|
|
39
|
+
* fieldName: string,
|
|
40
|
+
* fieldNode: import('graphql').FieldNode,
|
|
41
|
+
* fieldNodes: [import('graphql').FieldNode, ...import('graphql').FieldNode[]],
|
|
42
|
+
* parentId?: number,
|
|
43
|
+
* parentPathKey?: string,
|
|
44
|
+
* parentTypeName: string,
|
|
45
|
+
* pathDepth: number,
|
|
46
|
+
* resource: string,
|
|
47
|
+
* returnType: import('graphql').GraphQLOutputType,
|
|
48
|
+
* selectionDepth: number,
|
|
49
|
+
* tags: Record<string, string | undefined>
|
|
50
|
+
* }} JitFieldDescriptor
|
|
51
|
+
* @typedef {{
|
|
52
|
+
* fields: JitFieldDescriptor[],
|
|
53
|
+
* fieldsByPath: Map<string, JitFieldDescriptor>
|
|
54
|
+
* }} BuildingJitPlan
|
|
55
|
+
* @typedef {{ fields: JitFieldDescriptor[] }} JitPlan
|
|
56
|
+
* @typedef {Record<string, import('graphql').GraphQLFieldResolver<unknown, unknown>>} GraphQLResolverMap
|
|
57
|
+
* @typedef {{
|
|
58
|
+
* ddTraceDefaultResolvers?: boolean,
|
|
59
|
+
* ddTracePlan?: BuildingJitPlan,
|
|
60
|
+
* ddTraceRuntime?: GraphqlJitRuntime,
|
|
61
|
+
* hoistedFunctions: string[],
|
|
62
|
+
* resolvers: GraphQLResolverMap
|
|
63
|
+
* }} JitCompilationContext
|
|
64
|
+
* @typedef {JitCompilationContext & { ddTracePlan: BuildingJitPlan }} ConfiguredJitCompilationContext
|
|
65
|
+
* @typedef {(
|
|
66
|
+
* parentTypeName: string,
|
|
67
|
+
* fieldName: string,
|
|
68
|
+
* returnType: import('graphql').GraphQLOutputType,
|
|
69
|
+
* collapsedPath: string
|
|
70
|
+
* ) => FieldMetadata} CreateFieldMetadata
|
|
71
|
+
* @typedef {(
|
|
72
|
+
* variableValues: Record<string, unknown> | undefined,
|
|
73
|
+
* cloneValue?: (value: unknown) => unknown
|
|
74
|
+
* ) => Record<string, unknown>} ArgumentFactory
|
|
75
|
+
* @typedef {(
|
|
76
|
+
* rootCtx: object,
|
|
77
|
+
* descriptorId: number,
|
|
78
|
+
* source: Record<string, unknown>,
|
|
79
|
+
* path: (string | number)[] | undefined,
|
|
80
|
+
* argumentFactory: ArgumentFactory | undefined
|
|
81
|
+
* ) => unknown} ResolveDefaultInvocation
|
|
82
|
+
* @typedef {(
|
|
83
|
+
* rootCtx: object,
|
|
84
|
+
* descriptorId: number,
|
|
85
|
+
* source: Record<string, unknown>,
|
|
86
|
+
* path: (string | number)[] | undefined
|
|
87
|
+
* ) => unknown} ReadDefaultInScope
|
|
88
|
+
* @typedef {(variableValues: Record<string, unknown> | undefined) => object | undefined} StartExecution
|
|
89
|
+
* @typedef {(rootCtx: object, descriptorId: number, error: unknown) => void} RecordResolverError
|
|
90
|
+
* @typedef {(
|
|
91
|
+
* rootCtx: object,
|
|
92
|
+
* descriptorId: number,
|
|
93
|
+
* resolver: import('graphql').GraphQLFieldResolver<unknown, unknown>,
|
|
94
|
+
* self: unknown,
|
|
95
|
+
* source: unknown,
|
|
96
|
+
* args: Record<string, unknown>,
|
|
97
|
+
* contextValue: unknown,
|
|
98
|
+
* info: import('graphql').GraphQLResolveInfo
|
|
99
|
+
* ) => unknown} ResolveField
|
|
100
|
+
* @typedef {(
|
|
101
|
+
* resolver: import('graphql').GraphQLFieldResolver<unknown, unknown>
|
|
102
|
+
* ) => import('graphql').GraphQLFieldResolver<unknown, unknown>} UnwrapResolver
|
|
103
|
+
* @typedef {(
|
|
104
|
+
* resolver: import('graphql').GraphQLFieldResolver<unknown, unknown>
|
|
105
|
+
* ) => import('graphql').GraphQLFieldResolver<unknown, unknown>} WrapResolver
|
|
106
|
+
* @typedef {{
|
|
107
|
+
* createFieldMetadata: CreateFieldMetadata,
|
|
108
|
+
* readDefaultInScope: ReadDefaultInScope,
|
|
109
|
+
* recordResolverError: RecordResolverError,
|
|
110
|
+
* resolveDefaultInvocation: ResolveDefaultInvocation,
|
|
111
|
+
* resolveField: ResolveField,
|
|
112
|
+
* startExecution: StartExecution,
|
|
113
|
+
* unwrapResolver: UnwrapResolver,
|
|
114
|
+
* wrapResolver: WrapResolver
|
|
115
|
+
* }} GraphqlJitRuntimeOptions
|
|
116
|
+
* @typedef {{
|
|
117
|
+
* compileResolverCall: (
|
|
118
|
+
* context: JitCompilationContext,
|
|
119
|
+
* resolverCall: string,
|
|
120
|
+
* resolverName: string,
|
|
121
|
+
* descriptorId: number | undefined
|
|
122
|
+
* ) => string,
|
|
123
|
+
* compileDefaultField: (
|
|
124
|
+
* context: ConfiguredJitCompilationContext,
|
|
125
|
+
* responsePath: unknown,
|
|
126
|
+
* parentType: import('graphql').GraphQLCompositeType,
|
|
127
|
+
* field: {
|
|
128
|
+
* name: string,
|
|
129
|
+
* type: import('graphql').GraphQLOutputType,
|
|
130
|
+
* args: import('graphql').GraphQLArgument[]
|
|
131
|
+
* },
|
|
132
|
+
* fieldNodes: [import('graphql').FieldNode, ...import('graphql').FieldNode[]],
|
|
133
|
+
* originPaths: string[],
|
|
134
|
+
* args: CompiledArguments,
|
|
135
|
+
* argumentSource: string,
|
|
136
|
+
* compiledField: string
|
|
137
|
+
* ) => string,
|
|
138
|
+
* finalizeCompilation: (
|
|
139
|
+
* context: JitCompilationContext & { ddTracePlan: BuildingJitPlan }
|
|
140
|
+
* ) => JitPlan,
|
|
141
|
+
* registerField: (
|
|
142
|
+
* context: ConfiguredJitCompilationContext,
|
|
143
|
+
* responsePath: unknown,
|
|
144
|
+
* input: DescriptorInput
|
|
145
|
+
* ) => number | undefined,
|
|
146
|
+
* readDefaultInScope: ReadDefaultInScope,
|
|
147
|
+
* recordResolverError: RecordResolverError,
|
|
148
|
+
* resolveDefaultInvocation: ResolveDefaultInvocation,
|
|
149
|
+
* resolveField: ResolveField,
|
|
150
|
+
* startExecution: StartExecution
|
|
151
|
+
* }} GraphqlJitRuntime
|
|
152
|
+
*/
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* @param {GraphqlJitRuntimeOptions} options
|
|
156
|
+
* @returns {{
|
|
157
|
+
* configureCompilationContext: (message: { result?: JitCompilationContext }) => void,
|
|
158
|
+
* runtime: GraphqlJitRuntime
|
|
159
|
+
* }}
|
|
160
|
+
*/
|
|
161
|
+
function createGraphqlJitRuntime ({
|
|
162
|
+
createFieldMetadata,
|
|
163
|
+
readDefaultInScope,
|
|
164
|
+
recordResolverError,
|
|
165
|
+
resolveDefaultInvocation,
|
|
166
|
+
resolveField,
|
|
167
|
+
startExecution,
|
|
168
|
+
unwrapResolver,
|
|
169
|
+
wrapResolver,
|
|
170
|
+
}) {
|
|
171
|
+
const runtime = {
|
|
172
|
+
compileDefaultField,
|
|
173
|
+
compileResolverCall,
|
|
174
|
+
finalizeCompilation,
|
|
175
|
+
recordResolverError,
|
|
176
|
+
registerField,
|
|
177
|
+
readDefaultInScope,
|
|
178
|
+
resolveDefaultInvocation,
|
|
179
|
+
resolveField,
|
|
180
|
+
startExecution,
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* @param {{ result?: JitCompilationContext }} message
|
|
185
|
+
*/
|
|
186
|
+
function configureCompilationContext ({ result: context }) {
|
|
187
|
+
if (!context) return
|
|
188
|
+
|
|
189
|
+
context.ddTraceDefaultResolvers = true
|
|
190
|
+
context.ddTraceRuntime = runtime
|
|
191
|
+
context.ddTracePlan = {
|
|
192
|
+
fields: [],
|
|
193
|
+
fieldsByPath: new Map(),
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* @param {ConfiguredJitCompilationContext} context
|
|
199
|
+
* @param {unknown} responsePath
|
|
200
|
+
* @param {DescriptorInput} input
|
|
201
|
+
* @returns {number | undefined}
|
|
202
|
+
*/
|
|
203
|
+
function registerField (context, responsePath, input) {
|
|
204
|
+
const [fieldNode] = input.fieldNodes
|
|
205
|
+
const compilerPath = analyzeCompilerPath(responsePath)
|
|
206
|
+
/* istanbul ignore next: a future graphql-jit version may change its private response-path shape. */
|
|
207
|
+
if (compilerPath === undefined) return
|
|
208
|
+
|
|
209
|
+
return createDescriptor(context, compilerPath, input, fieldNode, createFieldMetadata).id
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* @param {JitCompilationContext} context
|
|
214
|
+
* @param {string} resolverCall
|
|
215
|
+
* @param {string} resolverName
|
|
216
|
+
* @param {number | undefined} descriptorId
|
|
217
|
+
* @returns {string}
|
|
218
|
+
*/
|
|
219
|
+
function compileResolverCall (context, resolverCall, resolverName, descriptorId) {
|
|
220
|
+
const openParenthesis = resolverCall.indexOf('(')
|
|
221
|
+
const resolver = resolverCall.slice(0, openParenthesis)
|
|
222
|
+
if (descriptorId === undefined) {
|
|
223
|
+
context.resolvers[resolverName] = wrapResolver(context.resolvers[resolverName])
|
|
224
|
+
return resolverCall
|
|
225
|
+
}
|
|
226
|
+
context.resolvers[resolverName] = unwrapResolver(context.resolvers[resolverName])
|
|
227
|
+
|
|
228
|
+
const args = resolverCall.slice(openParenthesis + 1, -1)
|
|
229
|
+
return `__context.ddTrace !== undefined &&
|
|
230
|
+
(!__context.ddTrace.depthDisabled ||
|
|
231
|
+
__context.ddTrace.hasIastSub ||
|
|
232
|
+
__context.ddTrace.hasResolverSub)
|
|
233
|
+
? __context.ddTrace.jitRuntime.resolveField(
|
|
234
|
+
__context.ddTrace,
|
|
235
|
+
${descriptorId},
|
|
236
|
+
${resolver},
|
|
237
|
+
__context.resolvers,
|
|
238
|
+
${args}
|
|
239
|
+
)
|
|
240
|
+
: ${resolverCall}`
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* @param {ConfiguredJitCompilationContext} context
|
|
245
|
+
* @param {unknown} responsePath
|
|
246
|
+
* @param {import('graphql').GraphQLCompositeType} parentType
|
|
247
|
+
* @param {{
|
|
248
|
+
* name: string,
|
|
249
|
+
* type: import('graphql').GraphQLOutputType,
|
|
250
|
+
* args: import('graphql').GraphQLArgument[]
|
|
251
|
+
* }} field
|
|
252
|
+
* @param {[import('graphql').FieldNode, ...import('graphql').FieldNode[]]} fieldNodes
|
|
253
|
+
* @param {string[]} originPaths
|
|
254
|
+
* @param {CompiledArguments} args
|
|
255
|
+
* @param {string} argumentSource
|
|
256
|
+
* @param {string} compiledField
|
|
257
|
+
* @returns {string}
|
|
258
|
+
*/
|
|
259
|
+
function compileDefaultField (
|
|
260
|
+
context,
|
|
261
|
+
responsePath,
|
|
262
|
+
parentType,
|
|
263
|
+
field,
|
|
264
|
+
fieldNodes,
|
|
265
|
+
originPaths,
|
|
266
|
+
args,
|
|
267
|
+
argumentSource,
|
|
268
|
+
compiledField
|
|
269
|
+
) {
|
|
270
|
+
const parentPath = originPaths.join('.')
|
|
271
|
+
const sourcePath = `${parentPath}.${field.name}`
|
|
272
|
+
const sourceIndex = compiledField.indexOf(sourcePath)
|
|
273
|
+
/* istanbul ignore next: a future compiler may stop emitting the source path in its completion expression. */
|
|
274
|
+
if (sourceIndex === -1) return compiledField
|
|
275
|
+
|
|
276
|
+
const compilerPath = analyzeCompilerPath(responsePath)
|
|
277
|
+
/* istanbul ignore next: a future graphql-jit version may change its private response-path shape. */
|
|
278
|
+
if (compilerPath === undefined) return compiledField
|
|
279
|
+
|
|
280
|
+
const descriptor = createDescriptor(context, compilerPath, {
|
|
281
|
+
arguments: field.args,
|
|
282
|
+
fieldName: field.name,
|
|
283
|
+
fieldNodes,
|
|
284
|
+
returnType: field.type,
|
|
285
|
+
parentType,
|
|
286
|
+
}, fieldNodes[0], createFieldMetadata)
|
|
287
|
+
descriptor.staticArguments = args.values
|
|
288
|
+
descriptor.hasArgumentVariables = args.missing.length !== 0
|
|
289
|
+
const argumentFactory = compileArgumentFactory(context, descriptor, args.missing, argumentSource)
|
|
290
|
+
|
|
291
|
+
const shouldTrace = '__context.ddTrace !== undefined && ' +
|
|
292
|
+
'(__context.ddTrace.jitTraceAll || ' +
|
|
293
|
+
`(__context.ddTrace.jitTraceFirst && __context.ddTrace.jitFields[${descriptor.id}] === undefined))`
|
|
294
|
+
const resolveDefault = '__context.ddTrace.jitRuntime.resolveDefaultInvocation(' +
|
|
295
|
+
`__context.ddTrace, ${descriptor.id}, ${parentPath}, ` +
|
|
296
|
+
`__context.ddTrace.config.collapse ? undefined : ${compilerPath.runtimePath}, ${argumentFactory})`
|
|
297
|
+
const readDefaultInScope = '__context.ddTrace.jitRuntime.readDefaultInScope(' +
|
|
298
|
+
`__context.ddTrace, ${descriptor.id}, ${parentPath}, ` +
|
|
299
|
+
`__context.ddTrace.config.collapse ? undefined : ${compilerPath.runtimePath})`
|
|
300
|
+
const collapsedRead = '(__context.ddTrace !== undefined && __context.ddTrace.jitTraceFirst' +
|
|
301
|
+
` ? ${readDefaultInScope} : ${sourcePath})`
|
|
302
|
+
const tracedRead = `(${shouldTrace} ? ${resolveDefault} : ${collapsedRead})`
|
|
303
|
+
const remainingRead = '(__context.ddTrace !== undefined && ' +
|
|
304
|
+
'(__context.ddTrace.jitTraceAll || __context.ddTrace.jitTraceFirst)' +
|
|
305
|
+
` ? ${readDefaultInScope} : ${sourcePath})`
|
|
306
|
+
|
|
307
|
+
return compiledField.slice(0, sourceIndex) + tracedRead +
|
|
308
|
+
compiledField.slice(sourceIndex + sourcePath.length).replaceAll(sourcePath, remainingRead)
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
return { configureCompilationContext, runtime }
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* @param {JitCompilationContext & { ddTracePlan: BuildingJitPlan }} context
|
|
316
|
+
* @returns {JitPlan}
|
|
317
|
+
*/
|
|
318
|
+
function finalizeCompilation (context) {
|
|
319
|
+
const plan = context.ddTracePlan
|
|
320
|
+
|
|
321
|
+
for (const field of plan.fields) {
|
|
322
|
+
if (field.parentPathKey !== undefined) {
|
|
323
|
+
field.parentId = plan.fieldsByPath.get(field.parentPathKey)?.id
|
|
324
|
+
field.parentPathKey = undefined
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
return {
|
|
328
|
+
fields: plan.fields,
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* @param {ConfiguredJitCompilationContext} context
|
|
334
|
+
* @param {CompilerPathAnalysis} compilerPath
|
|
335
|
+
* @param {DescriptorInput} input
|
|
336
|
+
* @param {import('graphql').FieldNode} fieldNode
|
|
337
|
+
* @param {CreateFieldMetadata} createFieldMetadata
|
|
338
|
+
* @returns {JitFieldDescriptor}
|
|
339
|
+
*/
|
|
340
|
+
function createDescriptor (context, compilerPath, input, fieldNode, createFieldMetadata) {
|
|
341
|
+
const plan = context.ddTracePlan
|
|
342
|
+
|
|
343
|
+
const parentTypeName = input.parentType.name
|
|
344
|
+
const { baseTypeName, resource, tags } = createFieldMetadata(
|
|
345
|
+
parentTypeName,
|
|
346
|
+
input.fieldName,
|
|
347
|
+
input.returnType,
|
|
348
|
+
compilerPath.collapsedPath
|
|
349
|
+
)
|
|
350
|
+
const descriptor = {
|
|
351
|
+
id: plan.fields.length,
|
|
352
|
+
baseTypeName,
|
|
353
|
+
collapsedPath: compilerPath.collapsedPath,
|
|
354
|
+
collapsedPathSegments: compilerPath.collapsedPathSegments,
|
|
355
|
+
fieldName: input.fieldName,
|
|
356
|
+
fieldNode,
|
|
357
|
+
fieldNodes: input.fieldNodes,
|
|
358
|
+
hasArgumentVariables: undefined,
|
|
359
|
+
parentId: undefined,
|
|
360
|
+
parentPathKey: compilerPath.parentPathKey,
|
|
361
|
+
parentTypeName,
|
|
362
|
+
pathDepth: compilerPath.pathDepth,
|
|
363
|
+
resource,
|
|
364
|
+
returnType: input.returnType,
|
|
365
|
+
selectionDepth: compilerPath.selectionDepth,
|
|
366
|
+
staticArguments: undefined,
|
|
367
|
+
tags,
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
plan.fields.push(descriptor)
|
|
371
|
+
plan.fieldsByPath.set(compilerPath.pathKey, descriptor)
|
|
372
|
+
return descriptor
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* @param {ConfiguredJitCompilationContext} context
|
|
377
|
+
* @param {JitFieldDescriptor} descriptor
|
|
378
|
+
* @param {CompiledArguments['missing']} missing
|
|
379
|
+
* @param {string} argumentSource
|
|
380
|
+
* @returns {string}
|
|
381
|
+
*/
|
|
382
|
+
function compileArgumentFactory (context, descriptor, missing, argumentSource) {
|
|
383
|
+
if (missing.length === 0 && argumentSource === '{}') return 'undefined'
|
|
384
|
+
|
|
385
|
+
const name = `ddTraceArguments${descriptor.id}`
|
|
386
|
+
let source = `function ${name} (variableValues, cloneValue) {\n const args = ${argumentSource}\n`
|
|
387
|
+
const pathsByVariable = new Map()
|
|
388
|
+
|
|
389
|
+
for (const { path, valueNode } of missing) {
|
|
390
|
+
const variableName = valueNode.name.value
|
|
391
|
+
let paths = pathsByVariable.get(variableName)
|
|
392
|
+
if (paths === undefined) {
|
|
393
|
+
paths = []
|
|
394
|
+
pathsByVariable.set(variableName, paths)
|
|
395
|
+
}
|
|
396
|
+
paths.push(path)
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
let variableIndex = 0
|
|
400
|
+
for (const [variableName, paths] of pathsByVariable) {
|
|
401
|
+
const variableSource = `ddTraceVariable${variableIndex++}`
|
|
402
|
+
const quotedName = quoteString(variableName)
|
|
403
|
+
source += ` if (variableValues !== undefined && Object.hasOwn(variableValues, ${quotedName})) {
|
|
404
|
+
const ${variableSource} = cloneValue === undefined
|
|
405
|
+
? variableValues[${quotedName}]
|
|
406
|
+
: cloneValue(variableValues[${quotedName}])
|
|
407
|
+
`
|
|
408
|
+
for (const path of paths) {
|
|
409
|
+
source += ` ${compileArgumentPath(path)} = ${variableSource}\n`
|
|
410
|
+
}
|
|
411
|
+
source += ' }\n'
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
source += ' return args\n}\n'
|
|
415
|
+
context.hoistedFunctions.push(source)
|
|
416
|
+
return name
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* @param {ArgumentPath} path
|
|
421
|
+
* @returns {string}
|
|
422
|
+
*/
|
|
423
|
+
function compileArgumentPath (path) {
|
|
424
|
+
let source = 'args'
|
|
425
|
+
for (let current = path; current !== undefined; current = current.prev) {
|
|
426
|
+
source += `[${quoteString(current.key)}]`
|
|
427
|
+
}
|
|
428
|
+
return source
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* @param {string} value
|
|
433
|
+
* @returns {string}
|
|
434
|
+
*/
|
|
435
|
+
function quoteString (value) {
|
|
436
|
+
const json = JSON.stringify(value)
|
|
437
|
+
const content = json.slice(1, -1)
|
|
438
|
+
.replaceAll("'", String.raw`\'`)
|
|
439
|
+
.replaceAll(String.raw`\"`, '"')
|
|
440
|
+
return `'${content}'`
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* @param {unknown} path
|
|
445
|
+
* @returns {CompilerPathAnalysis | undefined}
|
|
446
|
+
*/
|
|
447
|
+
function analyzeCompilerPath (path) {
|
|
448
|
+
const segments = []
|
|
449
|
+
let current = path
|
|
450
|
+
while (current !== undefined) {
|
|
451
|
+
/* istanbul ignore next: only a future graphql-jit path representation can exercise this fallback. */
|
|
452
|
+
if (current === null || typeof current !== 'object') return
|
|
453
|
+
|
|
454
|
+
const key = Reflect.get(current, 'key')
|
|
455
|
+
const type = Reflect.get(current, 'type')
|
|
456
|
+
/* istanbul ignore next: only a future graphql-jit path segment can exercise this fallback. */
|
|
457
|
+
if (typeof key !== 'string' || (type !== 'literal' && type !== 'meta' && type !== 'variable')) return
|
|
458
|
+
|
|
459
|
+
segments.push({ key, type })
|
|
460
|
+
current = Reflect.get(current, 'prev')
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
const collapsedPathSegments = []
|
|
464
|
+
let lastLiteralPathKey
|
|
465
|
+
let parentPathKey
|
|
466
|
+
let pathDepth = 0
|
|
467
|
+
let pathKey = ''
|
|
468
|
+
let runtimePath = '['
|
|
469
|
+
let selectionDepth = 0
|
|
470
|
+
for (let index = segments.length - 1; index >= 0; index--) {
|
|
471
|
+
const { key, type } = segments[index]
|
|
472
|
+
pathKey += `${type}:${key}/`
|
|
473
|
+
if (type === 'meta') continue
|
|
474
|
+
|
|
475
|
+
if (pathDepth !== 0) {
|
|
476
|
+
runtimePath += ', '
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
if (type === 'literal') {
|
|
480
|
+
collapsedPathSegments.push(key)
|
|
481
|
+
parentPathKey = lastLiteralPathKey
|
|
482
|
+
lastLiteralPathKey = pathKey
|
|
483
|
+
runtimePath += `'${key}'`
|
|
484
|
+
selectionDepth++
|
|
485
|
+
} else {
|
|
486
|
+
collapsedPathSegments.push('*')
|
|
487
|
+
runtimePath += key
|
|
488
|
+
}
|
|
489
|
+
pathDepth++
|
|
490
|
+
}
|
|
491
|
+
runtimePath += ']'
|
|
492
|
+
|
|
493
|
+
return {
|
|
494
|
+
collapsedPath: collapsedPathSegments.join('.'),
|
|
495
|
+
collapsedPathSegments,
|
|
496
|
+
parentPathKey,
|
|
497
|
+
pathDepth,
|
|
498
|
+
pathKey,
|
|
499
|
+
runtimePath,
|
|
500
|
+
selectionDepth,
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
module.exports = createGraphqlJitRuntime
|
|
@@ -89,6 +89,7 @@ module.exports = {
|
|
|
89
89
|
'find-my-way': () => require('../find-my-way'),
|
|
90
90
|
'generic-pool': () => require('../generic-pool'),
|
|
91
91
|
graphql: () => require('../graphql'),
|
|
92
|
+
'graphql-jit': () => require('../graphql'),
|
|
92
93
|
grpc: () => require('../grpc'),
|
|
93
94
|
handlebars: () => require('../handlebars'),
|
|
94
95
|
hapi: () => require('../hapi'),
|
|
@@ -157,6 +158,7 @@ module.exports = {
|
|
|
157
158
|
tinypool: { esmFirst: true, fn: () => require('../vitest') },
|
|
158
159
|
undici: () => require('../undici'),
|
|
159
160
|
vitest: { esmFirst: true, fn: () => require('../vitest') },
|
|
161
|
+
webdriverio: { esmFirst: true, fn: () => require('../webdriverio') },
|
|
160
162
|
when: () => require('../when'),
|
|
161
163
|
winston: () => require('../winston'),
|
|
162
164
|
workerpool: () => require('../mocha'),
|