@malloy-publisher/server 0.0.198-dev1 → 0.0.198-dev2

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/build.ts CHANGED
@@ -5,14 +5,14 @@ fs.rmSync("./dist", { recursive: true, force: true });
5
5
  fs.mkdirSync("./dist");
6
6
 
7
7
  await build({
8
- // compile_worker.ts is bundled as a SEPARATE entrypoint so it can
9
- // be loaded by `new Worker(...)` at runtime. It must NOT be
10
- // inlined into server.mjs (workers can't share module state with
11
- // the parent process — they get their own JS realm).
12
8
  entrypoints: [
13
9
  "./src/server.ts",
14
10
  "./src/instrumentation.ts",
15
- "./src/compile/compile_worker.ts",
11
+ // Schema-introspection worker. Loaded at runtime via
12
+ // `new Worker(new URL("./schema_worker.mjs", import.meta.url))`
13
+ // from `schema_worker_pool.ts`, so it has to be a separate
14
+ // bundle output sitting next to server.mjs in dist/.
15
+ "./src/service/schema_worker.ts",
16
16
  ],
17
17
  outdir: "./dist",
18
18
  target: "node",
@@ -56,23 +56,13 @@ fs.copyFileSync(
56
56
  // Rename ESM outputs to .mjs so both Node and Bun can execute them
57
57
  fs.renameSync("./dist/server.js", "./dist/server.mjs");
58
58
  fs.renameSync("./dist/instrumentation.js", "./dist/instrumentation.mjs");
59
- // Bun emits compile_worker into its source-relative subdir; flatten
60
- // so compile_pool.ts's `resolveWorkerScript()` finds it as a sibling
61
- // of server.mjs. The path layout match is intentional keep these
62
- // two in sync or the worker pool falls back to in-process compile.
63
- if (fs.existsSync("./dist/compile/compile_worker.js")) {
64
- fs.renameSync(
65
- "./dist/compile/compile_worker.js",
66
- "./dist/compile_worker.mjs",
67
- );
68
- try {
69
- fs.rmdirSync("./dist/compile");
70
- } catch {
71
- /* directory may be non-empty if Bun produced sourcemaps; leave it */
72
- }
73
- } else if (fs.existsSync("./dist/compile_worker.js")) {
74
- fs.renameSync("./dist/compile_worker.js", "./dist/compile_worker.mjs");
75
- }
59
+ // Bun nests outputs by their path relative to the common entrypoint
60
+ // root (./src). schema_worker.ts is under src/service/, so its output
61
+ // lands at dist/service/schema_worker.jsnot dist/.
62
+ fs.renameSync(
63
+ "./dist/service/schema_worker.js",
64
+ "./dist/service/schema_worker.mjs",
65
+ );
76
66
 
77
67
  // Add shebang to server.mjs for npx/bunx compatibility
78
68
  const serverJsPath = "./dist/server.mjs";
@@ -43,7 +43,6 @@ var __export = (target, all) => {
43
43
  set: __exportSetter.bind(all, name)
44
44
  });
45
45
  };
46
- var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
47
46
  var __require = /* @__PURE__ */ createRequire(import.meta.url);
48
47
 
49
48
  // ../../node_modules/@opentelemetry/api/build/src/platform/node/globalThis.js
@@ -115087,7 +115086,40 @@ var require_winston = __commonJS((exports) => {
115087
115086
  warn.forProperties(exports, "deprecated", ["emitErrs", "levelLength"]);
115088
115087
  });
115089
115088
 
115089
+ // src/instrumentation.ts
115090
+ var import_api = __toESM(require_src(), 1);
115091
+ var import_auto_instrumentations_node = __toESM(require_src59(), 1);
115092
+ var import_exporter_logs_otlp_proto = __toESM(require_src66(), 1);
115093
+ var import_exporter_prometheus = __toESM(require_src71(), 1);
115094
+ var import_exporter_trace_otlp_proto = __toESM(require_src72(), 1);
115095
+ var import_instrumentation_express = __toESM(require_src17(), 1);
115096
+ var import_resources = __toESM(require_src57(), 1);
115097
+ var import_sdk_logs = __toESM(require_src75(), 1);
115098
+ var import_sdk_node = __toESM(require_src106(), 1);
115099
+ var import_sdk_trace_base = __toESM(require_src82(), 1);
115100
+ var import_semantic_conventions = __toESM(require_src2(), 1);
115101
+ import { monitorEventLoopDelay } from "node:perf_hooks";
115102
+
115090
115103
  // src/logger.ts
115104
+ var import_winston = __toESM(require_winston(), 1);
115105
+ var isTelemetryEnabled = Boolean(process.env.OTEL_EXPORTER_OTLP_ENDPOINT);
115106
+ var VALID_LOG_LEVELS = ["error", "warn", "info", "verbose", "debug", "silly"];
115107
+ var getLogLevel = () => {
115108
+ if (process.env.LOG_LEVEL) {
115109
+ const logLevel = process.env.LOG_LEVEL.toLowerCase();
115110
+ if (VALID_LOG_LEVELS.includes(logLevel)) {
115111
+ return logLevel;
115112
+ } else {
115113
+ console.error(`Invalid log level: ${process.env.LOG_LEVEL}. Valid log levels are: ${VALID_LOG_LEVELS.join(", ")}. Defaulting to "debug".`);
115114
+ }
115115
+ }
115116
+ return "debug";
115117
+ };
115118
+ var logger = import_winston.default.createLogger({
115119
+ level: getLogLevel(),
115120
+ format: isTelemetryEnabled ? import_winston.default.format.combine(import_winston.default.format.uncolorize(), import_winston.default.format.timestamp(), import_winston.default.format.errors({ stack: true }), import_winston.default.format.json()) : import_winston.default.format.combine(import_winston.default.format.colorize(), import_winston.default.format.simple()),
115121
+ transports: [new import_winston.default.transports.Console]
115122
+ });
115091
115123
  function extractTraceIdFromTraceparent(traceparent) {
115092
115124
  if (!traceparent) {
115093
115125
  return;
@@ -115099,6 +115131,7 @@ function extractTraceIdFromTraceparent(traceparent) {
115099
115131
  }
115100
115132
  return;
115101
115133
  }
115134
+ var DISABLE_RESPONSE_LOGGING = process.env.DISABLE_RESPONSE_LOGGING === "true" || process.env.DISABLE_RESPONSE_LOGGING === "1";
115102
115135
  function formatDuration(durationMs) {
115103
115136
  if (durationMs >= 1000) {
115104
115137
  const seconds = durationMs / 1000;
@@ -115106,17 +115139,7 @@ function formatDuration(durationMs) {
115106
115139
  }
115107
115140
  return `${durationMs.toFixed(2)}ms`;
115108
115141
  }
115109
- var import_winston, isTelemetryEnabled, VALID_LOG_LEVELS, getLogLevel = () => {
115110
- if (process.env.LOG_LEVEL) {
115111
- const logLevel = process.env.LOG_LEVEL.toLowerCase();
115112
- if (VALID_LOG_LEVELS.includes(logLevel)) {
115113
- return logLevel;
115114
- } else {
115115
- console.error(`Invalid log level: ${process.env.LOG_LEVEL}. Valid log levels are: ${VALID_LOG_LEVELS.join(", ")}. Defaulting to "debug".`);
115116
- }
115117
- }
115118
- return "debug";
115119
- }, logger, DISABLE_RESPONSE_LOGGING, loggerMiddleware = (req, res, next) => {
115142
+ var loggerMiddleware = (req, res, next) => {
115120
115143
  const startTime = performance.now();
115121
115144
  const resJson = res.json;
115122
115145
  res.json = (body) => {
@@ -115146,7 +115169,8 @@ var import_winston, isTelemetryEnabled, VALID_LOG_LEVELS, getLogLevel = () => {
115146
115169
  }
115147
115170
  });
115148
115171
  next();
115149
- }, logAxiosError = (error) => {
115172
+ };
115173
+ var logAxiosError = (error) => {
115150
115174
  if (error.response) {
115151
115175
  logger.error("Axios server-side error", {
115152
115176
  url: error.response.config.url,
@@ -115160,31 +115184,8 @@ var import_winston, isTelemetryEnabled, VALID_LOG_LEVELS, getLogLevel = () => {
115160
115184
  logger.error("Axios unknown error", { error });
115161
115185
  }
115162
115186
  };
115163
- var init_logger = __esm(() => {
115164
- import_winston = __toESM(require_winston(), 1);
115165
- isTelemetryEnabled = Boolean(process.env.OTEL_EXPORTER_OTLP_ENDPOINT);
115166
- VALID_LOG_LEVELS = ["error", "warn", "info", "verbose", "debug", "silly"];
115167
- logger = import_winston.default.createLogger({
115168
- level: getLogLevel(),
115169
- format: isTelemetryEnabled ? import_winston.default.format.combine(import_winston.default.format.uncolorize(), import_winston.default.format.timestamp(), import_winston.default.format.errors({ stack: true }), import_winston.default.format.json()) : import_winston.default.format.combine(import_winston.default.format.colorize(), import_winston.default.format.simple()),
115170
- transports: [new import_winston.default.transports.Console]
115171
- });
115172
- DISABLE_RESPONSE_LOGGING = process.env.DISABLE_RESPONSE_LOGGING === "true" || process.env.DISABLE_RESPONSE_LOGGING === "1";
115173
- });
115174
115187
 
115175
115188
  // src/instrumentation.ts
115176
- init_logger();
115177
- var import_api = __toESM(require_src(), 1);
115178
- var import_auto_instrumentations_node = __toESM(require_src59(), 1);
115179
- var import_exporter_logs_otlp_proto = __toESM(require_src66(), 1);
115180
- var import_exporter_prometheus = __toESM(require_src71(), 1);
115181
- var import_exporter_trace_otlp_proto = __toESM(require_src72(), 1);
115182
- var import_instrumentation_express = __toESM(require_src17(), 1);
115183
- var import_resources = __toESM(require_src57(), 1);
115184
- var import_sdk_logs = __toESM(require_src75(), 1);
115185
- var import_sdk_node = __toESM(require_src106(), 1);
115186
- var import_sdk_trace_base = __toESM(require_src82(), 1);
115187
- var import_semantic_conventions = __toESM(require_src2(), 1);
115188
115189
  var prometheusExporter = null;
115189
115190
  var sdk = null;
115190
115191
  function getPrometheusMetricsHandler() {
@@ -115266,6 +115267,26 @@ var httpRequestDuration = meter.createHistogram("http_server_request_duration_ms
115266
115267
  var httpRequestCount = meter.createCounter("http_server_requests_total", {
115267
115268
  description: "Total number of HTTP requests"
115268
115269
  });
115270
+ var eventLoopHistogram = monitorEventLoopDelay({ resolution: 20 });
115271
+ eventLoopHistogram.enable();
115272
+ var eventLoopLagP50 = meter.createObservableGauge("publisher_event_loop_lag_p50_ms", {
115273
+ description: "Event loop delay p50 since the last scrape, in milliseconds",
115274
+ unit: "ms"
115275
+ });
115276
+ var eventLoopLagP99 = meter.createObservableGauge("publisher_event_loop_lag_p99_ms", {
115277
+ description: "Event loop delay p99 since the last scrape, in milliseconds",
115278
+ unit: "ms"
115279
+ });
115280
+ var eventLoopLagMax = meter.createObservableGauge("publisher_event_loop_lag_max_ms", {
115281
+ description: "Event loop delay max since the last scrape, in milliseconds",
115282
+ unit: "ms"
115283
+ });
115284
+ meter.addBatchObservableCallback((observableResult) => {
115285
+ observableResult.observe(eventLoopLagP50, eventLoopHistogram.percentile(50) / 1e6);
115286
+ observableResult.observe(eventLoopLagP99, eventLoopHistogram.percentile(99) / 1e6);
115287
+ observableResult.observe(eventLoopLagMax, eventLoopHistogram.max / 1e6);
115288
+ eventLoopHistogram.reset();
115289
+ }, [eventLoopLagP50, eventLoopLagP99, eventLoopLagMax]);
115269
115290
  var IGNORED_PATHS = new Set([
115270
115291
  "/health",
115271
115292
  "/health/liveness",