@cedarjs/vite 6.0.0-canary.2615 → 6.0.0-canary.2619
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/dist/apiDevMiddleware.d.ts.map +1 -1
- package/dist/apiDevMiddleware.js +8 -1
- package/dist/buildApp.d.ts.map +1 -1
- package/dist/buildApp.js +2 -1
- package/dist/cjs/apiDevMiddleware.js +8 -1
- package/dist/cjs/buildApp.js +2 -1
- package/dist/cjs/index.js +4 -2
- package/dist/cjs/plugins/vite-plugin-cedar-otel-wrapping.js +225 -0
- package/dist/cjs/plugins/vite-plugin-handler-als-wrapping.js +10 -10
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -2
- package/dist/plugins/vite-plugin-cedar-otel-wrapping.d.ts +39 -0
- package/dist/plugins/vite-plugin-cedar-otel-wrapping.d.ts.map +1 -0
- package/dist/plugins/vite-plugin-cedar-otel-wrapping.js +200 -0
- package/dist/plugins/vite-plugin-handler-als-wrapping.d.ts +7 -7
- package/dist/plugins/vite-plugin-handler-als-wrapping.js +10 -10
- package/package.json +13 -13
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apiDevMiddleware.d.ts","sourceRoot":"","sources":["../src/apiDevMiddleware.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAc,aAAa,EAAE,MAAM,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"apiDevMiddleware.d.ts","sourceRoot":"","sources":["../src/apiDevMiddleware.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAc,aAAa,EAAE,MAAM,MAAM,CAAA;AA8BrD,wBAAsB,gBAAgB,CAAC,UAAU,EAAE,aAAa,iBAe/D;AA+GD,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,aAAa,CAAC,CAsGlE;AA0BD,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,aAAa,GAAG,IAAI,CA0EhE;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,KAIrB,SAAS,OAAO,KAAG,OAAO,CAAC,QAAQ,CAAC,CAoFnD;AAED,wBAAsB,qBAAqB,IAAI,OAAO,CAAC;IACrD,UAAU,EAAE,aAAa,CAAA;IACzB,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IAC1B,OAAO,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAA;CACjD,CAAC,CAcD"}
|
package/dist/apiDevMiddleware.js
CHANGED
|
@@ -14,6 +14,7 @@ import { applyGqlormInject } from "@cedarjs/internal/dist/build/api-graphql-tran
|
|
|
14
14
|
import { getConfig, getPaths, projectSideIsEsm } from "@cedarjs/project-config";
|
|
15
15
|
import { getWorkspacePackageAliases } from "./lib/workspacePackageAliases.js";
|
|
16
16
|
import { applyGraphqlOptionsExtract } from "./plugins/vite-plugin-cedar-graphql-options-extract.js";
|
|
17
|
+
import { applyOtelWrapping } from "./plugins/vite-plugin-cedar-otel-wrapping.js";
|
|
17
18
|
const LAMBDA_FUNCTIONS = {};
|
|
18
19
|
let graphqlYoga = null;
|
|
19
20
|
let loadApiFunctionsInFlight = null;
|
|
@@ -120,7 +121,6 @@ async function createApiViteServer() {
|
|
|
120
121
|
const isEsm = projectSideIsEsm("api");
|
|
121
122
|
const normalizedBase = normalizePath(cedarPaths.base);
|
|
122
123
|
const babelPlugins = getApiSideBabelPlugins({
|
|
123
|
-
openTelemetry: (cedarConfig.experimental?.opentelemetry?.enabled ?? false) && (cedarConfig.experimental?.opentelemetry?.wrapApi ?? false),
|
|
124
124
|
projectIsEsm: isEsm
|
|
125
125
|
});
|
|
126
126
|
const workspacePkgSourceMap = Object.fromEntries(
|
|
@@ -161,6 +161,13 @@ async function createApiViteServer() {
|
|
|
161
161
|
sourceCode = applyGraphqlOptionsExtract(sourceCode) ?? sourceCode;
|
|
162
162
|
sourceCode = applyGqlormInject(sourceCode, id) ?? sourceCode;
|
|
163
163
|
}
|
|
164
|
+
if (cedarConfig.experimental?.opentelemetry?.enabled && cedarConfig.experimental?.opentelemetry?.wrapApi) {
|
|
165
|
+
const relativePath = normalizePath(id).slice(
|
|
166
|
+
normalizedBase.length + "/api/src/".length
|
|
167
|
+
);
|
|
168
|
+
const apiFolder = relativePath.split("/")[0] ?? "?";
|
|
169
|
+
sourceCode = applyOtelWrapping(sourceCode, id, apiFolder) ?? sourceCode;
|
|
170
|
+
}
|
|
164
171
|
const result = await transformWithBabel(
|
|
165
172
|
sourceCode,
|
|
166
173
|
id,
|
package/dist/buildApp.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildApp.d.ts","sourceRoot":"","sources":["../src/buildApp.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"buildApp.d.ts","sourceRoot":"","sources":["../src/buildApp.ts"],"names":[],"mappings":"AAkCA,MAAM,WAAW,oBAAoB;IACnC,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAA;IACpB,EAAE,CAAC,EAAE,OAAO,CAAA;CACb;AAED;;;;;;;;GAQG;AACH,wBAAsB,aAAa,CAAC,EAClC,OAAe,EACf,SAA0B,EAC1B,EAAU,GACX,GAAE,oBAAyB,iBA8U3B"}
|
package/dist/buildApp.js
CHANGED
|
@@ -12,6 +12,7 @@ import { getConfig, getPaths, projectSideIsEsm } from "@cedarjs/project-config";
|
|
|
12
12
|
import { getWorkspacePackageAliases } from "./lib/workspacePackageAliases.js";
|
|
13
13
|
import { cedarGqlormInjectPlugin } from "./plugins/vite-plugin-cedar-gqlorm-inject.js";
|
|
14
14
|
import { cedarGraphqlOptionsExtractPlugin } from "./plugins/vite-plugin-cedar-graphql-options-extract.js";
|
|
15
|
+
import { cedarOtelWrappingPlugin } from "./plugins/vite-plugin-cedar-otel-wrapping.js";
|
|
15
16
|
import { handlerAlsWrappingPlugin } from "./plugins/vite-plugin-handler-als-wrapping.js";
|
|
16
17
|
function resolveWithExtensions(id) {
|
|
17
18
|
if (fs.existsSync(id)) {
|
|
@@ -102,7 +103,6 @@ async function buildCedarApp({
|
|
|
102
103
|
}
|
|
103
104
|
}
|
|
104
105
|
const babelPlugins = workspace.includes("api") ? getApiSideBabelPlugins({
|
|
105
|
-
openTelemetry: (cedarConfig.experimental?.opentelemetry?.enabled ?? false) && (cedarConfig.experimental?.opentelemetry?.wrapApi ?? false),
|
|
106
106
|
projectIsEsm: projectSideIsEsm("api")
|
|
107
107
|
}) : null;
|
|
108
108
|
const workspacePkgSourceMap = workspace.includes("api") ? Object.fromEntries(
|
|
@@ -228,6 +228,7 @@ async function buildCedarApp({
|
|
|
228
228
|
if (workspace.includes("api")) {
|
|
229
229
|
plugins.push(cedarGraphqlOptionsExtractPlugin());
|
|
230
230
|
plugins.push(cedarGqlormInjectPlugin());
|
|
231
|
+
plugins.push(cedarOtelWrappingPlugin());
|
|
231
232
|
plugins.push(
|
|
232
233
|
handlerAlsWrappingPlugin({ projectIsEsm: projectSideIsEsm("api") })
|
|
233
234
|
);
|
|
@@ -48,6 +48,7 @@ var import_api_graphql_transforms = require("@cedarjs/internal/dist/build/api-gr
|
|
|
48
48
|
var import_project_config = require("@cedarjs/project-config");
|
|
49
49
|
var import_workspacePackageAliases = require("./lib/workspacePackageAliases.js");
|
|
50
50
|
var import_vite_plugin_cedar_graphql_options_extract = require("./plugins/vite-plugin-cedar-graphql-options-extract.js");
|
|
51
|
+
var import_vite_plugin_cedar_otel_wrapping = require("./plugins/vite-plugin-cedar-otel-wrapping.js");
|
|
51
52
|
const LAMBDA_FUNCTIONS = {};
|
|
52
53
|
let graphqlYoga = null;
|
|
53
54
|
let loadApiFunctionsInFlight = null;
|
|
@@ -154,7 +155,6 @@ async function createApiViteServer() {
|
|
|
154
155
|
const isEsm = (0, import_project_config.projectSideIsEsm)("api");
|
|
155
156
|
const normalizedBase = (0, import_vite.normalizePath)(cedarPaths.base);
|
|
156
157
|
const babelPlugins = (0, import_babel_config.getApiSideBabelPlugins)({
|
|
157
|
-
openTelemetry: (cedarConfig.experimental?.opentelemetry?.enabled ?? false) && (cedarConfig.experimental?.opentelemetry?.wrapApi ?? false),
|
|
158
158
|
projectIsEsm: isEsm
|
|
159
159
|
});
|
|
160
160
|
const workspacePkgSourceMap = Object.fromEntries(
|
|
@@ -195,6 +195,13 @@ async function createApiViteServer() {
|
|
|
195
195
|
sourceCode = (0, import_vite_plugin_cedar_graphql_options_extract.applyGraphqlOptionsExtract)(sourceCode) ?? sourceCode;
|
|
196
196
|
sourceCode = (0, import_api_graphql_transforms.applyGqlormInject)(sourceCode, id) ?? sourceCode;
|
|
197
197
|
}
|
|
198
|
+
if (cedarConfig.experimental?.opentelemetry?.enabled && cedarConfig.experimental?.opentelemetry?.wrapApi) {
|
|
199
|
+
const relativePath = (0, import_vite.normalizePath)(id).slice(
|
|
200
|
+
normalizedBase.length + "/api/src/".length
|
|
201
|
+
);
|
|
202
|
+
const apiFolder = relativePath.split("/")[0] ?? "?";
|
|
203
|
+
sourceCode = (0, import_vite_plugin_cedar_otel_wrapping.applyOtelWrapping)(sourceCode, id, apiFolder) ?? sourceCode;
|
|
204
|
+
}
|
|
198
205
|
const result = await (0, import_babel_config.transformWithBabel)(
|
|
199
206
|
sourceCode,
|
|
200
207
|
id,
|
package/dist/cjs/buildApp.js
CHANGED
|
@@ -42,6 +42,7 @@ var import_project_config = require("@cedarjs/project-config");
|
|
|
42
42
|
var import_workspacePackageAliases = require("./lib/workspacePackageAliases.js");
|
|
43
43
|
var import_vite_plugin_cedar_gqlorm_inject = require("./plugins/vite-plugin-cedar-gqlorm-inject.js");
|
|
44
44
|
var import_vite_plugin_cedar_graphql_options_extract = require("./plugins/vite-plugin-cedar-graphql-options-extract.js");
|
|
45
|
+
var import_vite_plugin_cedar_otel_wrapping = require("./plugins/vite-plugin-cedar-otel-wrapping.js");
|
|
45
46
|
var import_vite_plugin_handler_als_wrapping = require("./plugins/vite-plugin-handler-als-wrapping.js");
|
|
46
47
|
function resolveWithExtensions(id) {
|
|
47
48
|
if (import_node_fs.default.existsSync(id)) {
|
|
@@ -132,7 +133,6 @@ async function buildCedarApp({
|
|
|
132
133
|
}
|
|
133
134
|
}
|
|
134
135
|
const babelPlugins = workspace.includes("api") ? (0, import_babel_config.getApiSideBabelPlugins)({
|
|
135
|
-
openTelemetry: (cedarConfig.experimental?.opentelemetry?.enabled ?? false) && (cedarConfig.experimental?.opentelemetry?.wrapApi ?? false),
|
|
136
136
|
projectIsEsm: (0, import_project_config.projectSideIsEsm)("api")
|
|
137
137
|
}) : null;
|
|
138
138
|
const workspacePkgSourceMap = workspace.includes("api") ? Object.fromEntries(
|
|
@@ -258,6 +258,7 @@ async function buildCedarApp({
|
|
|
258
258
|
if (workspace.includes("api")) {
|
|
259
259
|
plugins.push((0, import_vite_plugin_cedar_graphql_options_extract.cedarGraphqlOptionsExtractPlugin)());
|
|
260
260
|
plugins.push((0, import_vite_plugin_cedar_gqlorm_inject.cedarGqlormInjectPlugin)());
|
|
261
|
+
plugins.push((0, import_vite_plugin_cedar_otel_wrapping.cedarOtelWrappingPlugin)());
|
|
261
262
|
plugins.push(
|
|
262
263
|
(0, import_vite_plugin_handler_als_wrapping.handlerAlsWrappingPlugin)({ projectIsEsm: (0, import_project_config.projectSideIsEsm)("api") })
|
|
263
264
|
);
|
package/dist/cjs/index.js
CHANGED
|
@@ -28,7 +28,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
var index_exports = {};
|
|
30
30
|
__export(index_exports, {
|
|
31
|
-
applyHandlerAlsWrapping: () =>
|
|
31
|
+
applyHandlerAlsWrapping: () => import_vite_plugin_handler_als_wrapping.applyHandlerAlsWrapping,
|
|
32
32
|
cedar: () => cedar,
|
|
33
33
|
cedarAutoImportsPlugin: () => import_vite_plugin_cedar_auto_import.cedarAutoImportsPlugin,
|
|
34
34
|
cedarCellTransform: () => import_vite_plugin_cedar_cell2.cedarCellTransform,
|
|
@@ -40,6 +40,7 @@ __export(index_exports, {
|
|
|
40
40
|
cedarHtmlEnvPlugin: () => import_vite_plugin_cedar_html_env2.cedarHtmlEnvPlugin,
|
|
41
41
|
cedarImportDirPlugin: () => import_vite_plugin_cedar_import_dir.cedarImportDirPlugin,
|
|
42
42
|
cedarMergedConfig: () => import_vite_plugin_merged_config2.cedarMergedConfig,
|
|
43
|
+
cedarOtelWrappingPlugin: () => import_vite_plugin_cedar_otel_wrapping.cedarOtelWrappingPlugin,
|
|
43
44
|
cedarRemoveDevFatalErrorPage: () => import_vite_plugin_cedar_remove_dev_fatal_error_page2.cedarRemoveDevFatalErrorPage,
|
|
44
45
|
cedarRemoveFromBundle: () => import_vite_plugin_cedar_remove_from_bundle2.cedarRemoveFromBundle,
|
|
45
46
|
cedarRoutesAutoLoaderPlugin: () => import_vite_plugin_cedar_routes_auto_loader2.cedarRoutesAutoLoaderPlugin,
|
|
@@ -74,8 +75,8 @@ var import_vite_plugin_cedar_cjs_compat = require("./plugins/vite-plugin-cedar-c
|
|
|
74
75
|
var import_vite_plugin_cedar_cell2 = require("./plugins/vite-plugin-cedar-cell.js");
|
|
75
76
|
var import_vite_plugin_cedar_gqlorm_inject = require("./plugins/vite-plugin-cedar-gqlorm-inject.js");
|
|
76
77
|
var import_vite_plugin_cedar_graphql_options_extract = require("./plugins/vite-plugin-cedar-graphql-options-extract.js");
|
|
78
|
+
var import_vite_plugin_cedar_otel_wrapping = require("./plugins/vite-plugin-cedar-otel-wrapping.js");
|
|
77
79
|
var import_vite_plugin_handler_als_wrapping = require("./plugins/vite-plugin-handler-als-wrapping.js");
|
|
78
|
-
var import_vite_plugin_handler_als_wrapping2 = require("./plugins/vite-plugin-handler-als-wrapping.js");
|
|
79
80
|
var import_vite_plugin_cedar_entry_injection2 = require("./plugins/vite-plugin-cedar-entry-injection.js");
|
|
80
81
|
var import_vite_plugin_cedar_html_env2 = require("./plugins/vite-plugin-cedar-html-env.js");
|
|
81
82
|
var import_vite_plugin_cedar_import_dir = require("./plugins/vite-plugin-cedar-import-dir.js");
|
|
@@ -134,6 +135,7 @@ var index_default = cedar;
|
|
|
134
135
|
cedarHtmlEnvPlugin,
|
|
135
136
|
cedarImportDirPlugin,
|
|
136
137
|
cedarMergedConfig,
|
|
138
|
+
cedarOtelWrappingPlugin,
|
|
137
139
|
cedarRemoveDevFatalErrorPage,
|
|
138
140
|
cedarRemoveFromBundle,
|
|
139
141
|
cedarRoutesAutoLoaderPlugin,
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var vite_plugin_cedar_otel_wrapping_exports = {};
|
|
20
|
+
__export(vite_plugin_cedar_otel_wrapping_exports, {
|
|
21
|
+
applyOtelWrapping: () => applyOtelWrapping,
|
|
22
|
+
cedarOtelWrappingPlugin: () => cedarOtelWrappingPlugin
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(vite_plugin_cedar_otel_wrapping_exports);
|
|
25
|
+
var import_oxc_parser = require("oxc-parser");
|
|
26
|
+
var import_vite = require("vite");
|
|
27
|
+
var import_project_config = require("@cedarjs/project-config");
|
|
28
|
+
function cedarOtelWrappingPlugin() {
|
|
29
|
+
return {
|
|
30
|
+
name: "cedar-otel-wrapping",
|
|
31
|
+
transform(code, id) {
|
|
32
|
+
let apiSrc;
|
|
33
|
+
try {
|
|
34
|
+
apiSrc = (0, import_vite.normalizePath)((0, import_project_config.getPaths)().api.src);
|
|
35
|
+
} catch {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
if (!(0, import_vite.normalizePath)(id).startsWith(apiSrc + "/")) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
const relativePath = (0, import_vite.normalizePath)(id).slice(apiSrc.length + 1);
|
|
42
|
+
const apiFolder = relativePath.split("/")[0] ?? "?";
|
|
43
|
+
const result = applyOtelWrapping(code, id, apiFolder);
|
|
44
|
+
return result ? { code: result, map: null } : null;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function applyOtelWrapping(code, filename, apiFolder) {
|
|
49
|
+
const parseResult = (0, import_oxc_parser.parseSync)(filename, code, { sourceType: "module" });
|
|
50
|
+
const replacements = [];
|
|
51
|
+
for (const node of parseResult.program.body) {
|
|
52
|
+
if (node.type !== "ExportNamedDeclaration") {
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
const decl = node.declaration;
|
|
56
|
+
if (decl?.type !== "VariableDeclaration") {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
const declarator = decl.declarations[0];
|
|
60
|
+
if (!declarator) {
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
const fn = declarator.init;
|
|
64
|
+
if (fn?.type !== "ArrowFunctionExpression") {
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (declarator.id.type !== "Identifier") {
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
const fnName = declarator.id.name;
|
|
71
|
+
const innerArgs = buildInnerArgs(fn.params);
|
|
72
|
+
if (innerArgs === null) {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
const fnHeader = code.slice(fn.start, fn.body.start);
|
|
76
|
+
const originalFnSrc = code.slice(fn.start, fn.end);
|
|
77
|
+
const isAsync = fn.async;
|
|
78
|
+
const awaitKw = isAsync ? "await " : "";
|
|
79
|
+
const asyncKw = isAsync ? "async " : "";
|
|
80
|
+
replacements.push({
|
|
81
|
+
start: node.start,
|
|
82
|
+
end: node.end,
|
|
83
|
+
src: buildWrappedExport(
|
|
84
|
+
fnName,
|
|
85
|
+
fnHeader,
|
|
86
|
+
originalFnSrc,
|
|
87
|
+
innerArgs,
|
|
88
|
+
awaitKw,
|
|
89
|
+
asyncKw,
|
|
90
|
+
apiFolder,
|
|
91
|
+
filename
|
|
92
|
+
)
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
if (replacements.length === 0) {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
let output = code;
|
|
99
|
+
for (let i = replacements.length - 1; i >= 0; i--) {
|
|
100
|
+
const r = replacements[i];
|
|
101
|
+
output = output.slice(0, r.start) + r.src + output.slice(r.end);
|
|
102
|
+
}
|
|
103
|
+
return `import { trace as OTEL_TRACE } from '@opentelemetry/api'
|
|
104
|
+
` + output;
|
|
105
|
+
}
|
|
106
|
+
function buildInnerArgs(params) {
|
|
107
|
+
const args = [];
|
|
108
|
+
for (const param of params) {
|
|
109
|
+
if (param.type === "RestElement" || param.type === "ArrayPattern" || param.type === "TSParameterProperty") {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
if (param.type === "Identifier") {
|
|
113
|
+
args.push(param.name);
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
if (param.type === "ObjectPattern") {
|
|
117
|
+
for (const prop of param.properties) {
|
|
118
|
+
if (prop.type === "RestElement") {
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
if (prop.key.type !== "Identifier") {
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
const value = prop.value;
|
|
125
|
+
if (value.type !== "Identifier" && value.type !== "AssignmentPattern" && value.type !== "ObjectPattern") {
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
if (value.type === "AssignmentPattern") {
|
|
129
|
+
if (value.left.type !== "Identifier" && value.left.type !== "ObjectPattern") {
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
const obj = buildObjectCallArg(param);
|
|
135
|
+
if (obj === null) {
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
args.push(obj);
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
if (param.type === "AssignmentPattern") {
|
|
142
|
+
const ap = param;
|
|
143
|
+
if (ap.left.type === "Identifier") {
|
|
144
|
+
args.push(ap.left.name);
|
|
145
|
+
} else if (ap.left.type === "ObjectPattern") {
|
|
146
|
+
const obj = buildObjectCallArg(ap.left);
|
|
147
|
+
if (obj === null) {
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
args.push(obj);
|
|
151
|
+
} else {
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
return args.join(", ");
|
|
159
|
+
}
|
|
160
|
+
function buildObjectCallArg(pattern) {
|
|
161
|
+
const keys = [];
|
|
162
|
+
for (const prop of pattern.properties) {
|
|
163
|
+
if (prop.type === "RestElement") {
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
if (prop.key.type !== "Identifier") {
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
const keyName = prop.key.name;
|
|
170
|
+
let valueName = null;
|
|
171
|
+
if (prop.value.type === "Identifier") {
|
|
172
|
+
valueName = prop.value.name;
|
|
173
|
+
} else if (prop.value.type === "AssignmentPattern") {
|
|
174
|
+
if (prop.value.left.type === "Identifier") {
|
|
175
|
+
valueName = prop.value.left.name;
|
|
176
|
+
} else {
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
} else {
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
if (valueName !== keyName) {
|
|
183
|
+
keys.push(`${keyName}: ${valueName}`);
|
|
184
|
+
} else {
|
|
185
|
+
keys.push(keyName);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return `{ ${keys.join(", ")} }`;
|
|
189
|
+
}
|
|
190
|
+
function buildWrappedExport(fnName, fnHeader, originalFnSrc, innerArgs, awaitKw, asyncKw, apiFolder, filename) {
|
|
191
|
+
const privateName = `__${fnName}`;
|
|
192
|
+
const spanName = `redwoodjs:api:${apiFolder}:${fnName}`;
|
|
193
|
+
return `export const ${fnName} = ${fnHeader}{
|
|
194
|
+
const ${privateName} = ${originalFnSrc}
|
|
195
|
+
const OTEL_TRACER = OTEL_TRACE.getTracer('redwoodjs')
|
|
196
|
+
const OTEL_RESULT = ${awaitKw}OTEL_TRACER.startActiveSpan(
|
|
197
|
+
'${spanName}',
|
|
198
|
+
${asyncKw}(span) => {
|
|
199
|
+
span.setAttribute('code.function', '${fnName}')
|
|
200
|
+
span.setAttribute('code.filepath', ${JSON.stringify(filename)})
|
|
201
|
+
try {
|
|
202
|
+
const OTEL_INNER_RESULT = ${awaitKw}${privateName}(${innerArgs})
|
|
203
|
+
span.end()
|
|
204
|
+
return OTEL_INNER_RESULT
|
|
205
|
+
} catch (error) {
|
|
206
|
+
span.recordException(error)
|
|
207
|
+
span.setStatus({
|
|
208
|
+
code: 2,
|
|
209
|
+
message:
|
|
210
|
+
error?.message?.split('\\n')[0] ??
|
|
211
|
+
error?.toString()?.split('\\n')[0],
|
|
212
|
+
})
|
|
213
|
+
span.end()
|
|
214
|
+
throw error
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
)
|
|
218
|
+
return OTEL_RESULT
|
|
219
|
+
}`;
|
|
220
|
+
}
|
|
221
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
222
|
+
0 && (module.exports = {
|
|
223
|
+
applyOtelWrapping,
|
|
224
|
+
cedarOtelWrappingPlugin
|
|
225
|
+
});
|
|
@@ -65,25 +65,25 @@ function applyHandlerAlsWrapping(code, { projectIsEsm = false } = {}) {
|
|
|
65
65
|
const afterEquals = code.slice(handlerMatch.index + handlerMatch[0].length).trimStart();
|
|
66
66
|
const isAsync = /^async(?:\s*[\(\*]|\s+function)/.test(afterEquals);
|
|
67
67
|
const storePath = projectIsEsm ? "@cedarjs/context/dist/store.js" : "@cedarjs/context/dist/store";
|
|
68
|
-
const importStatement = `import { getAsyncStoreInstance as
|
|
68
|
+
const importStatement = `import { getAsyncStoreInstance as __cedar_getAsyncStoreInstance } from '${storePath}'
|
|
69
69
|
`;
|
|
70
70
|
const handlerStart = handlerMatch.index;
|
|
71
71
|
const before = code.slice(0, handlerStart);
|
|
72
72
|
const after = code.slice(handlerStart);
|
|
73
|
-
const renamed = after.replace(handlerRe, "const
|
|
73
|
+
const renamed = after.replace(handlerRe, "const __cedar_handler =");
|
|
74
74
|
const wrappedHandler = `
|
|
75
|
-
export const handler = ${isAsync ? "async " : ""}(
|
|
75
|
+
export const handler = ${isAsync ? "async " : ""}(__cedar_event, __cedar_context) => {
|
|
76
76
|
// The store will be undefined if no context isolation has been performed yet
|
|
77
|
-
const
|
|
78
|
-
if (
|
|
79
|
-
return
|
|
77
|
+
const __cedar_contextStore = __cedar_getAsyncStoreInstance().getStore()
|
|
78
|
+
if (__cedar_contextStore === undefined) {
|
|
79
|
+
return __cedar_getAsyncStoreInstance().run(
|
|
80
80
|
new Map(),
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
81
|
+
__cedar_handler,
|
|
82
|
+
__cedar_event,
|
|
83
|
+
__cedar_context
|
|
84
84
|
)
|
|
85
85
|
}
|
|
86
|
-
return
|
|
86
|
+
return __cedar_handler(__cedar_event, __cedar_context)
|
|
87
87
|
}
|
|
88
88
|
`;
|
|
89
89
|
return before + importStatement + renamed + wrappedHandler;
|
package/dist/index.d.ts
CHANGED
|
@@ -4,8 +4,8 @@ export { cedarCjsCompatPlugin } from './plugins/vite-plugin-cedar-cjs-compat.js'
|
|
|
4
4
|
export { cedarCellTransform } from './plugins/vite-plugin-cedar-cell.js';
|
|
5
5
|
export { cedarGqlormInjectPlugin } from './plugins/vite-plugin-cedar-gqlorm-inject.js';
|
|
6
6
|
export { cedarGraphqlOptionsExtractPlugin } from './plugins/vite-plugin-cedar-graphql-options-extract.js';
|
|
7
|
-
export {
|
|
8
|
-
export { applyHandlerAlsWrapping } from './plugins/vite-plugin-handler-als-wrapping.js';
|
|
7
|
+
export { cedarOtelWrappingPlugin } from './plugins/vite-plugin-cedar-otel-wrapping.js';
|
|
8
|
+
export { applyHandlerAlsWrapping, handlerAlsWrappingPlugin, } from './plugins/vite-plugin-handler-als-wrapping.js';
|
|
9
9
|
export { cedarEntryInjectionPlugin } from './plugins/vite-plugin-cedar-entry-injection.js';
|
|
10
10
|
export { cedarHtmlEnvPlugin } from './plugins/vite-plugin-cedar-html-env.js';
|
|
11
11
|
export { cedarImportDirPlugin } from './plugins/vite-plugin-cedar-import-dir.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAuBxC,OAAO,EAAE,sBAAsB,EAAE,MAAM,4CAA4C,CAAA;AACnF,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAA;AAChF,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAA;AACxE,OAAO,EAAE,uBAAuB,EAAE,MAAM,8CAA8C,CAAA;AACtF,OAAO,EAAE,gCAAgC,EAAE,MAAM,wDAAwD,CAAA;AACzG,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAuBxC,OAAO,EAAE,sBAAsB,EAAE,MAAM,4CAA4C,CAAA;AACnF,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAA;AAChF,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAA;AACxE,OAAO,EAAE,uBAAuB,EAAE,MAAM,8CAA8C,CAAA;AACtF,OAAO,EAAE,gCAAgC,EAAE,MAAM,wDAAwD,CAAA;AACzG,OAAO,EAAE,uBAAuB,EAAE,MAAM,8CAA8C,CAAA;AACtF,OAAO,EACL,uBAAuB,EACvB,wBAAwB,GACzB,MAAM,+CAA+C,CAAA;AACtD,OAAO,EAAE,yBAAyB,EAAE,MAAM,gDAAgD,CAAA;AAC1F,OAAO,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAA;AAC5E,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAA;AAChF,OAAO,EAAE,gBAAgB,EAAE,MAAM,8CAA8C,CAAA;AAC/E,OAAO,EAAE,4BAA4B,EAAE,MAAM,4DAA4D,CAAA;AACzG,OAAO,EAAE,2BAA2B,EAAE,MAAM,mDAAmD,CAAA;AAC/F,OAAO,EAAE,qBAAqB,EAAE,MAAM,mDAAmD,CAAA;AACzF,OAAO,EAAE,qCAAqC,EAAE,MAAM,8DAA8D,CAAA;AACpH,OAAO,EAAE,4BAA4B,EAAE,MAAM,oDAAoD,CAAA;AACjG,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAA;AAC3E,OAAO,EAAE,iBAAiB,EAAE,MAAM,wCAAwC,CAAA;AAC1E,OAAO,EAAE,uBAAuB,EAAE,MAAM,+CAA+C,CAAA;AACvF,OAAO,EAAE,0BAA0B,EAAE,MAAM,iDAAiD,CAAA;AAC5F,OAAO,EAAE,qBAAqB,EAAE,MAAM,oDAAoD,CAAA;AAE1F,KAAK,aAAa,GAAG;IACnB,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAC1B,CAAA;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAC,EAAE,IAAI,EAAE,GAAE,aAAkB,GAAG,YAAY,EAAE,CAgClE;AAED,8DAA8D;AAC9D,eAAe,KAAK,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -23,8 +23,11 @@ import { cedarCjsCompatPlugin } from "./plugins/vite-plugin-cedar-cjs-compat.js"
|
|
|
23
23
|
import { cedarCellTransform as cedarCellTransform2 } from "./plugins/vite-plugin-cedar-cell.js";
|
|
24
24
|
import { cedarGqlormInjectPlugin } from "./plugins/vite-plugin-cedar-gqlorm-inject.js";
|
|
25
25
|
import { cedarGraphqlOptionsExtractPlugin } from "./plugins/vite-plugin-cedar-graphql-options-extract.js";
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
26
|
+
import { cedarOtelWrappingPlugin } from "./plugins/vite-plugin-cedar-otel-wrapping.js";
|
|
27
|
+
import {
|
|
28
|
+
applyHandlerAlsWrapping,
|
|
29
|
+
handlerAlsWrappingPlugin
|
|
30
|
+
} from "./plugins/vite-plugin-handler-als-wrapping.js";
|
|
28
31
|
import { cedarEntryInjectionPlugin as cedarEntryInjectionPlugin2 } from "./plugins/vite-plugin-cedar-entry-injection.js";
|
|
29
32
|
import { cedarHtmlEnvPlugin as cedarHtmlEnvPlugin2 } from "./plugins/vite-plugin-cedar-html-env.js";
|
|
30
33
|
import { cedarImportDirPlugin } from "./plugins/vite-plugin-cedar-import-dir.js";
|
|
@@ -82,6 +85,7 @@ export {
|
|
|
82
85
|
cedarHtmlEnvPlugin2 as cedarHtmlEnvPlugin,
|
|
83
86
|
cedarImportDirPlugin,
|
|
84
87
|
cedarMergedConfig2 as cedarMergedConfig,
|
|
88
|
+
cedarOtelWrappingPlugin,
|
|
85
89
|
cedarRemoveDevFatalErrorPage2 as cedarRemoveDevFatalErrorPage,
|
|
86
90
|
cedarRemoveFromBundle2 as cedarRemoveFromBundle,
|
|
87
91
|
cedarRoutesAutoLoaderPlugin2 as cedarRoutesAutoLoaderPlugin,
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { Plugin } from 'vite';
|
|
2
|
+
/**
|
|
3
|
+
* Vite plugin that wraps exported API functions with OpenTelemetry spans to
|
|
4
|
+
* provide automatic tracing in your Cedar API.
|
|
5
|
+
*
|
|
6
|
+
* For each `export const fn = (async?) (...) => {...}` declaration in an API
|
|
7
|
+
* file this plugin:
|
|
8
|
+
*
|
|
9
|
+
* 1. Adds an import at the top of the file:
|
|
10
|
+
* import { trace as OTEL_TRACE } from '@opentelemetry/api'
|
|
11
|
+
*
|
|
12
|
+
* 2. Wraps the original export with an OTel span:
|
|
13
|
+
* export const fn = (async?) (...params) => {
|
|
14
|
+
* const __fn = (async?) (...params) => { ...original body... }
|
|
15
|
+
* const OTEL_TRACER = OTEL_TRACE.getTracer('redwoodjs')
|
|
16
|
+
* const OTEL_RESULT = (await?) OTEL_TRACER.startActiveSpan(
|
|
17
|
+
* 'redwoodjs:api:<folder>:<fnName>',
|
|
18
|
+
* (async?) (span) => { ... }
|
|
19
|
+
* )
|
|
20
|
+
* return OTEL_RESULT
|
|
21
|
+
* }
|
|
22
|
+
*
|
|
23
|
+
* This replaces `babel-plugin-redwood-otel-wrapping` for all Vite and esbuild
|
|
24
|
+
* builds. The previous Babel plugin has been removed entirely; Jest transforms
|
|
25
|
+
* through the Vite SSR pipeline.
|
|
26
|
+
*
|
|
27
|
+
* NOTE: Known limitation. Spans will close before a Promise settles if a
|
|
28
|
+
* synchronous function returns a Promise. To trace async work correctly, mark
|
|
29
|
+
* the function as `async` if it returns or awaits Promises.
|
|
30
|
+
*/
|
|
31
|
+
export declare function cedarOtelWrappingPlugin(): Plugin;
|
|
32
|
+
/**
|
|
33
|
+
* Applies OpenTelemetry span wrapping to API source files.
|
|
34
|
+
*
|
|
35
|
+
* Exported as a standalone function so it can be tested without a Vite context.
|
|
36
|
+
* Returns the transformed code string, or `null` if nothing was changed.
|
|
37
|
+
*/
|
|
38
|
+
export declare function applyOtelWrapping(code: string, filename: string, apiFolder: string): string | null;
|
|
39
|
+
//# sourceMappingURL=vite-plugin-cedar-otel-wrapping.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite-plugin-cedar-otel-wrapping.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-cedar-otel-wrapping.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAKlC;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,uBAAuB,IAAI,MAAM,CAwBhD;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,GAChB,MAAM,GAAG,IAAI,CA+Ef"}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { parseSync } from "oxc-parser";
|
|
2
|
+
import { normalizePath } from "vite";
|
|
3
|
+
import { getPaths } from "@cedarjs/project-config";
|
|
4
|
+
function cedarOtelWrappingPlugin() {
|
|
5
|
+
return {
|
|
6
|
+
name: "cedar-otel-wrapping",
|
|
7
|
+
transform(code, id) {
|
|
8
|
+
let apiSrc;
|
|
9
|
+
try {
|
|
10
|
+
apiSrc = normalizePath(getPaths().api.src);
|
|
11
|
+
} catch {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
if (!normalizePath(id).startsWith(apiSrc + "/")) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
const relativePath = normalizePath(id).slice(apiSrc.length + 1);
|
|
18
|
+
const apiFolder = relativePath.split("/")[0] ?? "?";
|
|
19
|
+
const result = applyOtelWrapping(code, id, apiFolder);
|
|
20
|
+
return result ? { code: result, map: null } : null;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function applyOtelWrapping(code, filename, apiFolder) {
|
|
25
|
+
const parseResult = parseSync(filename, code, { sourceType: "module" });
|
|
26
|
+
const replacements = [];
|
|
27
|
+
for (const node of parseResult.program.body) {
|
|
28
|
+
if (node.type !== "ExportNamedDeclaration") {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
const decl = node.declaration;
|
|
32
|
+
if (decl?.type !== "VariableDeclaration") {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
const declarator = decl.declarations[0];
|
|
36
|
+
if (!declarator) {
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
const fn = declarator.init;
|
|
40
|
+
if (fn?.type !== "ArrowFunctionExpression") {
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
if (declarator.id.type !== "Identifier") {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
const fnName = declarator.id.name;
|
|
47
|
+
const innerArgs = buildInnerArgs(fn.params);
|
|
48
|
+
if (innerArgs === null) {
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
const fnHeader = code.slice(fn.start, fn.body.start);
|
|
52
|
+
const originalFnSrc = code.slice(fn.start, fn.end);
|
|
53
|
+
const isAsync = fn.async;
|
|
54
|
+
const awaitKw = isAsync ? "await " : "";
|
|
55
|
+
const asyncKw = isAsync ? "async " : "";
|
|
56
|
+
replacements.push({
|
|
57
|
+
start: node.start,
|
|
58
|
+
end: node.end,
|
|
59
|
+
src: buildWrappedExport(
|
|
60
|
+
fnName,
|
|
61
|
+
fnHeader,
|
|
62
|
+
originalFnSrc,
|
|
63
|
+
innerArgs,
|
|
64
|
+
awaitKw,
|
|
65
|
+
asyncKw,
|
|
66
|
+
apiFolder,
|
|
67
|
+
filename
|
|
68
|
+
)
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
if (replacements.length === 0) {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
let output = code;
|
|
75
|
+
for (let i = replacements.length - 1; i >= 0; i--) {
|
|
76
|
+
const r = replacements[i];
|
|
77
|
+
output = output.slice(0, r.start) + r.src + output.slice(r.end);
|
|
78
|
+
}
|
|
79
|
+
return `import { trace as OTEL_TRACE } from '@opentelemetry/api'
|
|
80
|
+
` + output;
|
|
81
|
+
}
|
|
82
|
+
function buildInnerArgs(params) {
|
|
83
|
+
const args = [];
|
|
84
|
+
for (const param of params) {
|
|
85
|
+
if (param.type === "RestElement" || param.type === "ArrayPattern" || param.type === "TSParameterProperty") {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
if (param.type === "Identifier") {
|
|
89
|
+
args.push(param.name);
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
if (param.type === "ObjectPattern") {
|
|
93
|
+
for (const prop of param.properties) {
|
|
94
|
+
if (prop.type === "RestElement") {
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
if (prop.key.type !== "Identifier") {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
const value = prop.value;
|
|
101
|
+
if (value.type !== "Identifier" && value.type !== "AssignmentPattern" && value.type !== "ObjectPattern") {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
if (value.type === "AssignmentPattern") {
|
|
105
|
+
if (value.left.type !== "Identifier" && value.left.type !== "ObjectPattern") {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
const obj = buildObjectCallArg(param);
|
|
111
|
+
if (obj === null) {
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
args.push(obj);
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
if (param.type === "AssignmentPattern") {
|
|
118
|
+
const ap = param;
|
|
119
|
+
if (ap.left.type === "Identifier") {
|
|
120
|
+
args.push(ap.left.name);
|
|
121
|
+
} else if (ap.left.type === "ObjectPattern") {
|
|
122
|
+
const obj = buildObjectCallArg(ap.left);
|
|
123
|
+
if (obj === null) {
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
args.push(obj);
|
|
127
|
+
} else {
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
return args.join(", ");
|
|
135
|
+
}
|
|
136
|
+
function buildObjectCallArg(pattern) {
|
|
137
|
+
const keys = [];
|
|
138
|
+
for (const prop of pattern.properties) {
|
|
139
|
+
if (prop.type === "RestElement") {
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
if (prop.key.type !== "Identifier") {
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
const keyName = prop.key.name;
|
|
146
|
+
let valueName = null;
|
|
147
|
+
if (prop.value.type === "Identifier") {
|
|
148
|
+
valueName = prop.value.name;
|
|
149
|
+
} else if (prop.value.type === "AssignmentPattern") {
|
|
150
|
+
if (prop.value.left.type === "Identifier") {
|
|
151
|
+
valueName = prop.value.left.name;
|
|
152
|
+
} else {
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
} else {
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
if (valueName !== keyName) {
|
|
159
|
+
keys.push(`${keyName}: ${valueName}`);
|
|
160
|
+
} else {
|
|
161
|
+
keys.push(keyName);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return `{ ${keys.join(", ")} }`;
|
|
165
|
+
}
|
|
166
|
+
function buildWrappedExport(fnName, fnHeader, originalFnSrc, innerArgs, awaitKw, asyncKw, apiFolder, filename) {
|
|
167
|
+
const privateName = `__${fnName}`;
|
|
168
|
+
const spanName = `redwoodjs:api:${apiFolder}:${fnName}`;
|
|
169
|
+
return `export const ${fnName} = ${fnHeader}{
|
|
170
|
+
const ${privateName} = ${originalFnSrc}
|
|
171
|
+
const OTEL_TRACER = OTEL_TRACE.getTracer('redwoodjs')
|
|
172
|
+
const OTEL_RESULT = ${awaitKw}OTEL_TRACER.startActiveSpan(
|
|
173
|
+
'${spanName}',
|
|
174
|
+
${asyncKw}(span) => {
|
|
175
|
+
span.setAttribute('code.function', '${fnName}')
|
|
176
|
+
span.setAttribute('code.filepath', ${JSON.stringify(filename)})
|
|
177
|
+
try {
|
|
178
|
+
const OTEL_INNER_RESULT = ${awaitKw}${privateName}(${innerArgs})
|
|
179
|
+
span.end()
|
|
180
|
+
return OTEL_INNER_RESULT
|
|
181
|
+
} catch (error) {
|
|
182
|
+
span.recordException(error)
|
|
183
|
+
span.setStatus({
|
|
184
|
+
code: 2,
|
|
185
|
+
message:
|
|
186
|
+
error?.message?.split('\\n')[0] ??
|
|
187
|
+
error?.toString()?.split('\\n')[0],
|
|
188
|
+
})
|
|
189
|
+
span.end()
|
|
190
|
+
throw error
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
)
|
|
194
|
+
return OTEL_RESULT
|
|
195
|
+
}`;
|
|
196
|
+
}
|
|
197
|
+
export {
|
|
198
|
+
applyOtelWrapping,
|
|
199
|
+
cedarOtelWrappingPlugin
|
|
200
|
+
};
|
|
@@ -8,18 +8,18 @@ import type { Plugin } from 'vite';
|
|
|
8
8
|
* For each file in `api/src/functions/` that exports a `handler`, this plugin:
|
|
9
9
|
*
|
|
10
10
|
* 1. Adds an import at the top of the file:
|
|
11
|
-
* import { getAsyncStoreInstance as
|
|
11
|
+
* import { getAsyncStoreInstance as __cedar_getAsyncStoreInstance } from '@cedarjs/context/dist/store'
|
|
12
12
|
*
|
|
13
13
|
* 2. Renames the original handler:
|
|
14
|
-
* const
|
|
14
|
+
* const __cedar_handler = <original handler value>
|
|
15
15
|
*
|
|
16
16
|
* 3. Replaces the handler export with a wrapper that checks context isolation:
|
|
17
|
-
* export const handler = (
|
|
18
|
-
* const
|
|
19
|
-
* if (
|
|
20
|
-
* return
|
|
17
|
+
* export const handler = (__cedar_event, __cedar_context) => {
|
|
18
|
+
* const __cedar_contextStore = __cedar_getAsyncStoreInstance().getStore()
|
|
19
|
+
* if (__cedar_contextStore === undefined) {
|
|
20
|
+
* return __cedar_getAsyncStoreInstance().run(new Map(), __cedar_handler, __cedar_event, __cedar_context)
|
|
21
21
|
* }
|
|
22
|
-
* return
|
|
22
|
+
* return __cedar_handler(__cedar_event, __cedar_context)
|
|
23
23
|
* }
|
|
24
24
|
*
|
|
25
25
|
* This replaces `babel-plugin-handler-als-wrapping` for Vite builds.
|
|
@@ -31,25 +31,25 @@ function applyHandlerAlsWrapping(code, { projectIsEsm = false } = {}) {
|
|
|
31
31
|
const afterEquals = code.slice(handlerMatch.index + handlerMatch[0].length).trimStart();
|
|
32
32
|
const isAsync = /^async(?:\s*[\(\*]|\s+function)/.test(afterEquals);
|
|
33
33
|
const storePath = projectIsEsm ? "@cedarjs/context/dist/store.js" : "@cedarjs/context/dist/store";
|
|
34
|
-
const importStatement = `import { getAsyncStoreInstance as
|
|
34
|
+
const importStatement = `import { getAsyncStoreInstance as __cedar_getAsyncStoreInstance } from '${storePath}'
|
|
35
35
|
`;
|
|
36
36
|
const handlerStart = handlerMatch.index;
|
|
37
37
|
const before = code.slice(0, handlerStart);
|
|
38
38
|
const after = code.slice(handlerStart);
|
|
39
|
-
const renamed = after.replace(handlerRe, "const
|
|
39
|
+
const renamed = after.replace(handlerRe, "const __cedar_handler =");
|
|
40
40
|
const wrappedHandler = `
|
|
41
|
-
export const handler = ${isAsync ? "async " : ""}(
|
|
41
|
+
export const handler = ${isAsync ? "async " : ""}(__cedar_event, __cedar_context) => {
|
|
42
42
|
// The store will be undefined if no context isolation has been performed yet
|
|
43
|
-
const
|
|
44
|
-
if (
|
|
45
|
-
return
|
|
43
|
+
const __cedar_contextStore = __cedar_getAsyncStoreInstance().getStore()
|
|
44
|
+
if (__cedar_contextStore === undefined) {
|
|
45
|
+
return __cedar_getAsyncStoreInstance().run(
|
|
46
46
|
new Map(),
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
__cedar_handler,
|
|
48
|
+
__cedar_event,
|
|
49
|
+
__cedar_context
|
|
50
50
|
)
|
|
51
51
|
}
|
|
52
|
-
return
|
|
52
|
+
return __cedar_handler(__cedar_event, __cedar_context)
|
|
53
53
|
}
|
|
54
54
|
`;
|
|
55
55
|
return before + importStatement + renamed + wrappedHandler;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cedarjs/vite",
|
|
3
|
-
"version": "6.0.0-canary.
|
|
3
|
+
"version": "6.0.0-canary.2619",
|
|
4
4
|
"description": "Vite configuration package for CedarJS",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -63,15 +63,15 @@
|
|
|
63
63
|
"@babel/parser": "7.29.7",
|
|
64
64
|
"@babel/traverse": "7.29.7",
|
|
65
65
|
"@babel/types": "7.29.7",
|
|
66
|
-
"@cedarjs/api": "6.0.0-canary.
|
|
67
|
-
"@cedarjs/babel-config": "6.0.0-canary.
|
|
68
|
-
"@cedarjs/context": "6.0.0-canary.
|
|
69
|
-
"@cedarjs/cookie-jar": "6.0.0-canary.
|
|
70
|
-
"@cedarjs/graphql-server": "6.0.0-canary.
|
|
71
|
-
"@cedarjs/internal": "6.0.0-canary.
|
|
72
|
-
"@cedarjs/project-config": "6.0.0-canary.
|
|
73
|
-
"@cedarjs/server-store": "6.0.0-canary.
|
|
74
|
-
"@cedarjs/testing": "6.0.0-canary.
|
|
66
|
+
"@cedarjs/api": "6.0.0-canary.2619",
|
|
67
|
+
"@cedarjs/babel-config": "6.0.0-canary.2619",
|
|
68
|
+
"@cedarjs/context": "6.0.0-canary.2619",
|
|
69
|
+
"@cedarjs/cookie-jar": "6.0.0-canary.2619",
|
|
70
|
+
"@cedarjs/graphql-server": "6.0.0-canary.2619",
|
|
71
|
+
"@cedarjs/internal": "6.0.0-canary.2619",
|
|
72
|
+
"@cedarjs/project-config": "6.0.0-canary.2619",
|
|
73
|
+
"@cedarjs/server-store": "6.0.0-canary.2619",
|
|
74
|
+
"@cedarjs/testing": "6.0.0-canary.2619",
|
|
75
75
|
"@fastify/url-data": "6.0.3",
|
|
76
76
|
"@swc/core": "1.15.41",
|
|
77
77
|
"@universal-deploy/store": "^0.2.1",
|
|
@@ -104,9 +104,9 @@
|
|
|
104
104
|
},
|
|
105
105
|
"devDependencies": {
|
|
106
106
|
"@arethetypeswrong/cli": "0.18.4",
|
|
107
|
-
"@cedarjs/auth": "6.0.0-canary.
|
|
108
|
-
"@cedarjs/router": "6.0.0-canary.
|
|
109
|
-
"@cedarjs/web": "6.0.0-canary.
|
|
107
|
+
"@cedarjs/auth": "6.0.0-canary.2619",
|
|
108
|
+
"@cedarjs/router": "6.0.0-canary.2619",
|
|
109
|
+
"@cedarjs/web": "6.0.0-canary.2619",
|
|
110
110
|
"@hyrious/esbuild-plugin-commonjs": "0.2.6",
|
|
111
111
|
"@jridgewell/trace-mapping": "0.3.31",
|
|
112
112
|
"@types/aws-lambda": "8.10.162",
|