@open-mercato/cli 0.8.1-develop.7275.1.f772b944d4 → 0.8.1-develop.7295.1.d0e0e33014
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/.turbo/turbo-build.log +3 -1
- package/dist/agentic/guides/module-facts.json +1164 -142
- package/dist/agentic/guides/module-facts.v2.json +1164 -142
- package/dist/agentic/guides/modules/agent_orchestrator/index.md +1 -1
- package/dist/agentic/guides/modules/ai_assistant/index.md +1 -1
- package/dist/agentic/guides/modules/api_docs/index.md +1 -1
- package/dist/agentic/guides/modules/api_keys/index.md +1 -1
- package/dist/agentic/guides/modules/attachments/index.md +1 -1
- package/dist/agentic/guides/modules/audit_logs/index.md +1 -1
- package/dist/agentic/guides/modules/auth/index.md +1 -1
- package/dist/agentic/guides/modules/business_rules/index.md +1 -1
- package/dist/agentic/guides/modules/catalog/index.md +1 -1
- package/dist/agentic/guides/modules/channel_apns/index.md +1 -1
- package/dist/agentic/guides/modules/channel_discord/index.md +1 -1
- package/dist/agentic/guides/modules/channel_expo/index.md +1 -1
- package/dist/agentic/guides/modules/channel_fcm/index.md +1 -1
- package/dist/agentic/guides/modules/channel_gmail/index.md +1 -1
- package/dist/agentic/guides/modules/channel_imap/index.md +1 -1
- package/dist/agentic/guides/modules/channel_resend/index.md +1 -1
- package/dist/agentic/guides/modules/channel_ses/index.md +1 -1
- package/dist/agentic/guides/modules/checkout/index.md +1 -1
- package/dist/agentic/guides/modules/communication_channels/index.md +1 -1
- package/dist/agentic/guides/modules/configs/index.md +1 -1
- package/dist/agentic/guides/modules/content/index.md +1 -1
- package/dist/agentic/guides/modules/currencies/index.md +1 -1
- package/dist/agentic/guides/modules/customer_accounts/index.md +1 -1
- package/dist/agentic/guides/modules/customers/index.md +1 -1
- package/dist/agentic/guides/modules/dashboards/index.md +1 -1
- package/dist/agentic/guides/modules/data_sync/active-extension-bindings.md +1 -1
- package/dist/agentic/guides/modules/data_sync/index.md +1 -1
- package/dist/agentic/guides/modules/design_system/index.md +1 -1
- package/dist/agentic/guides/modules/devices/index.md +1 -1
- package/dist/agentic/guides/modules/dictionaries/index.md +1 -1
- package/dist/agentic/guides/modules/directory/index.md +1 -1
- package/dist/agentic/guides/modules/documents/index.md +1 -1
- package/dist/agentic/guides/modules/entities/index.md +1 -1
- package/dist/agentic/guides/modules/eudr/index.md +1 -1
- package/dist/agentic/guides/modules/events/index.md +1 -1
- package/dist/agentic/guides/modules/feature_toggles/index.md +1 -1
- package/dist/agentic/guides/modules/gateway_stripe/index.md +1 -1
- package/dist/agentic/guides/modules/generators/index.md +1 -1
- package/dist/agentic/guides/modules/inbox_ops/index.md +1 -1
- package/dist/agentic/guides/modules/integrations/index.md +1 -1
- package/dist/agentic/guides/modules/messages/index.md +1 -1
- package/dist/agentic/guides/modules/notifications/index.md +1 -1
- package/dist/agentic/guides/modules/onboarding/index.md +1 -1
- package/dist/agentic/guides/modules/payment_gateways/index.md +1 -1
- package/dist/agentic/guides/modules/perspectives/index.md +1 -1
- package/dist/agentic/guides/modules/phone_calls/index.md +1 -1
- package/dist/agentic/guides/modules/planner/index.md +1 -1
- package/dist/agentic/guides/modules/portal/index.md +1 -1
- package/dist/agentic/guides/modules/progress/index.md +1 -1
- package/dist/agentic/guides/modules/push_notifications/index.md +1 -1
- package/dist/agentic/guides/modules/query_index/index.md +1 -1
- package/dist/agentic/guides/modules/record_locks/index.md +1 -1
- package/dist/agentic/guides/modules/resources/index.md +1 -1
- package/dist/agentic/guides/modules/sales/index.md +1 -1
- package/dist/agentic/guides/modules/scheduler/index.md +1 -1
- package/dist/agentic/guides/modules/search/index.md +1 -1
- package/dist/agentic/guides/modules/security/index.md +1 -1
- package/dist/agentic/guides/modules/seeds/index.md +1 -1
- package/dist/agentic/guides/modules/shipping_carriers/index.md +1 -1
- package/dist/agentic/guides/modules/sso/index.md +1 -1
- package/dist/agentic/guides/modules/staff/host-extension-points.md +1 -1
- package/dist/agentic/guides/modules/staff/index.md +10 -10
- package/dist/agentic/guides/modules/staff/umes-diagnostics.md +4 -0
- package/dist/agentic/guides/modules/staff/umes-hosts.md +36 -0
- package/dist/agentic/guides/modules/storage_s3/index.md +1 -1
- package/dist/agentic/guides/modules/sync_akeneo/index.md +1 -1
- package/dist/agentic/guides/modules/sync_excel/index.md +1 -1
- package/dist/agentic/guides/modules/system_status_overlays/index.md +1 -1
- package/dist/agentic/guides/modules/telemetry/index.md +12 -0
- package/dist/agentic/guides/modules/telemetry/owned-contract-module-metadata.md +11 -0
- package/dist/agentic/guides/modules/tillio/index.md +1 -1
- package/dist/agentic/guides/modules/translations/index.md +1 -1
- package/dist/agentic/guides/modules/warranty_claims/index.md +1 -1
- package/dist/agentic/guides/modules/webhooks/index.md +1 -1
- package/dist/agentic/guides/modules/wms/index.md +1 -1
- package/dist/agentic/guides/modules/workflows/index.md +1 -1
- package/dist/agentic/guides/reference-module-facts.json +1 -1
- package/dist/agentic/guides/upstream/manifest.json +1 -1
- package/dist/agentic/shared/ai/harness/README.md +2 -2
- package/dist/agentic/shared/ai/harness/RELEASE.md +4 -4
- package/dist/agentic/shared/ai/harness/cases.json +77 -0
- package/dist/agentic/shared/ai/harness/cases.schema.json +4 -4
- package/dist/agentic/shared/ai/harness/validators.json +1 -1
- package/dist/lib/telemetry-init.js +109 -4
- package/dist/lib/telemetry-init.js.map +2 -2
- package/dist/lib/testing/integration.js +10 -0
- package/dist/lib/testing/integration.js.map +2 -2
- package/package.json +6 -6
- package/src/lib/__tests__/telemetry-init.test.ts +174 -4
- package/src/lib/telemetry-init.ts +166 -8
- package/src/lib/testing/integration.ts +10 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/lib/telemetry-init.ts"],
|
|
4
|
-
"sourcesContent": ["import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'node:fs'\nimport { dirname, join, resolve } from 'node:path'\n\n/**\n * `mercato telemetry init` \u2014 wire `@open-mercato/telemetry` into an app that was\n * scaffolded before telemetry existed. Deterministic, idempotent, and safe to\n * re-run: each step detects whether it is already applied and skips.\n *\n * The web-tier wiring lives in app-owned source files (a dependency bump cannot\n * touch them), so this patches them in place using the same idioms the rest of\n * the CLI uses: JSON edits, detect-before-append for `.env`, a ts-morph edit for\n * `next.config.ts`, and anchored insertion for `instrumentation.ts` + the API\n * dispatcher. When a file's shape is not recognized (a customized dispatcher, an\n * unusual next.config), the step degrades to printing the exact snippet and\n * flags it as a manual step rather than editing code it does not understand.\n *\n * Worker/scheduler telemetry is not handled here \u2014 it ships transitively via\n * `@open-mercato/cli`'s telemetry dependency once the app updates its packages.\n */\n\nconst BULLMQ_OTEL_VERSION = '^1.3.1'\n\ntype StepStatus = 'created' | 'patched' | 'skipped' | 'manual'\n\ntype StepResult = {\n file: string\n status: StepStatus\n detail: string\n /** Snippet to show when the step needs manual work. */\n manualSnippet?: string\n}\n\ntype TelemetryInitOptions = {\n dryRun: boolean\n}\n\nconst ENV_BLOCK = `\n# --- Telemetry & Observability (vendor-neutral OTLP: traces, logs, metrics, errors) ---\n# Off by default: leave TELEMETRY_BACKEND unset (or =noop) for a hard no-op\n# (the OpenTelemetry SDK is never loaded). Set to 'console' for local span/metric\n# output, or an OTLP backend to export: 'signoz' | 'newrelic' | 'otlp' (generic).\n# All three OTLP names use the same exporter \u2014 they differ only by the endpoint +\n# headers below. Any OTLP backend is a one-line swap; no code change.\n# TELEMETRY_BACKEND=otlp\n# Logs use the shared logger facade and its OM_LOG_LEVEL / OM_LOG_PRETTY /\n# OM_LOG_DESTINATION controls. Telemetry adds remote export; it does not create\n# a second local output path.\n# TELEMETRY_SAMPLING_RATIO=1.0 # 0.0\u20131.0 (default 1.0 dev / 0.1 prod)\n# TELEMETRY_TRUST_INBOUND_TRACE=false # default false: root-per-request (ignore an\n# # inbound traceparent from a proxy/LB). Set true\n# # only behind a trusted upstream whose trace continues.\n# # This also enables richer bullmq-otel spans;\n# # otherwise async queues use metadata._trace.\n#\n# OTLP endpoint + auth \u2014 pick ONE vendor (use your region's host):\n# SigNoz Cloud:\n# OTEL_EXPORTER_OTLP_ENDPOINT=https://ingest.<region>.signoz.cloud:443\n# OTEL_EXPORTER_OTLP_HEADERS=signoz-ingestion-key=<your-ingestion-key>\n# New Relic (OTLP-native; EU host shown, US is https://otlp.nr-data.net):\n# OTEL_EXPORTER_OTLP_ENDPOINT=https://otlp.eu01.nr-data.net\n# OTEL_EXPORTER_OTLP_HEADERS=api-key=<your-ingest-license-key>\n#\n# Resource identity: keep one stable service name across environments and\n# separate envs via the deployment.environment resource attribute.\n# OTEL_SERVICE_NAME=open-mercato\n# OTEL_RESOURCE_ATTRIBUTES=deployment.environment=local\n`\n\nconst INSTRUMENTATION_TS = `import { isTelemetryBackendEnabled } from '@open-mercato/shared/lib/telemetry/runtime'\n\nexport async function register(): Promise<void> {\n // Initialize telemetry (no-op unless TELEMETRY_BACKEND is set). OTEL's NodeSDK\n // is Node-only and incompatible with the edge runtime, so the telemetry\n // bootstrap \u2014 which can pull in the SDK \u2014 is imported only on the Node.js\n // runtime. The helper owns init + graceful degrade + shutdown flush.\n if (\n process.env.NEXT_RUNTIME === 'nodejs'\n && isTelemetryBackendEnabled()\n ) {\n const { registerTelemetryForNextjs } = await import('@open-mercato/telemetry/nextjs')\n await registerTelemetryForNextjs()\n }\n}\n`\n\nconst DISPATCHER_SNIPPET = ` // add near the other imports:\n import { getTelemetryRuntime } from '@open-mercato/shared/lib/telemetry/runtime'\n\n // in the dispatcher's success path, just before returning the response:\n getTelemetryRuntime()?.recordHttpDuration(method, match.route.path, finalResponse.status, startedAt)\n\n // in the dispatcher's catch (error) block, before re-throwing:\n getTelemetryRuntime()?.reportError(error, {\n attributes: { 'http.request.method': method, 'http.route': match.route.path, 'http.response.status_code': 500 },\n })\n getTelemetryRuntime()?.recordHttpDuration(method, match.route.path, 500, startedAt)`\n\nfunction parseArgs(args: string[]): TelemetryInitOptions {\n return {\n dryRun: args.includes('--dry-run') || args.includes('-n'),\n }\n}\n\n/** Read the version an app already pins its `@open-mercato/*` deps to (lockstep). */\nfunction resolveOpenMercatoVersion(pkg: Record<string, unknown>): string {\n for (const field of ['dependencies', 'devDependencies'] as const) {\n const deps = pkg[field]\n if (deps && typeof deps === 'object') {\n for (const [name, version] of Object.entries(deps as Record<string, string>)) {\n if (name.startsWith('@open-mercato/') && typeof version === 'string') return version\n }\n }\n }\n return '*'\n}\n\nfunction patchPackageJson(appDir: string, options: TelemetryInitOptions): StepResult {\n const file = 'package.json'\n const path = join(appDir, file)\n const raw = readFileSync(path, 'utf8')\n const pkg = JSON.parse(raw) as {\n dependencies?: Record<string, string>\n optionalDependencies?: Record<string, string>\n }\n const version = resolveOpenMercatoVersion(pkg)\n const hasTelemetry = Boolean(pkg.dependencies?.['@open-mercato/telemetry'])\n const hasBullmqOtel = Boolean(pkg.optionalDependencies?.['bullmq-otel'])\n if (hasTelemetry && hasBullmqOtel) {\n return { file, status: 'skipped', detail: '@open-mercato/telemetry already installed' }\n }\n\n const deps = { ...(pkg.dependencies ?? {}) }\n if (!hasTelemetry) deps['@open-mercato/telemetry'] = version\n const optDeps = { ...(pkg.optionalDependencies ?? {}) }\n if (!hasBullmqOtel) optDeps['bullmq-otel'] = BULLMQ_OTEL_VERSION\n\n const next = {\n ...pkg,\n dependencies: sortRecord(deps),\n optionalDependencies: sortRecord(optDeps),\n }\n if (!options.dryRun) writeFileSync(path, `${JSON.stringify(next, null, 2)}\\n`)\n return {\n file,\n status: 'patched',\n detail: `+@open-mercato/telemetry@${version}${hasBullmqOtel ? '' : ` +bullmq-otel@${BULLMQ_OTEL_VERSION} (optional)`} \u2014 run \\`yarn install\\``,\n }\n}\n\nfunction sortRecord(record: Record<string, string>): Record<string, string> {\n return Object.fromEntries(Object.entries(record).sort(([a], [b]) => a.localeCompare(b)))\n}\n\nfunction patchEnvFile(appDir: string, relativePath: string, options: TelemetryInitOptions): StepResult | null {\n const path = join(appDir, relativePath)\n if (!existsSync(path)) return null\n const content = readFileSync(path, 'utf8')\n if (content.includes('TELEMETRY_BACKEND')) {\n return { file: relativePath, status: 'skipped', detail: 'TELEMETRY_* block already present' }\n }\n const next = `${content.replace(/\\s*$/, '')}\\n${ENV_BLOCK}`\n if (!options.dryRun) writeFileSync(path, next)\n return { file: relativePath, status: 'patched', detail: 'appended commented TELEMETRY_* / OTEL_* block' }\n}\n\nfunction patchInstrumentation(appDir: string, options: TelemetryInitOptions): StepResult {\n const file = 'src/instrumentation.ts'\n const path = join(appDir, file)\n if (!existsSync(path)) {\n if (!options.dryRun) {\n mkdirSync(dirname(path), { recursive: true })\n writeFileSync(path, INSTRUMENTATION_TS)\n }\n return { file, status: 'created', detail: 'Node-runtime-guarded registerTelemetryForNextjs() bootstrap' }\n }\n const content = readFileSync(path, 'utf8')\n if (content.includes('registerTelemetryForNextjs')) {\n if (content.includes('isTelemetryBackendEnabled')) {\n return { file, status: 'skipped', detail: 'telemetry already wired' }\n }\n const migrated =\n `import { isTelemetryBackendEnabled } from '@open-mercato/shared/lib/telemetry/runtime'\\n` +\n content.replace(\n `if (process.env.NEXT_RUNTIME === 'nodejs') {`,\n `if (process.env.NEXT_RUNTIME === 'nodejs' && isTelemetryBackendEnabled()) {`,\n )\n if (!options.dryRun) writeFileSync(path, migrated)\n return { file, status: 'patched', detail: 'added the explicit backend import guard' }\n }\n const anchor = content.match(/export\\s+async\\s+function\\s+register\\s*\\([^)]*\\)\\s*:\\s*Promise<void>\\s*\\{/)\n if (!anchor || anchor.index === undefined) {\n return {\n file,\n status: 'manual',\n detail: 'register() not found \u2014 add the telemetry bootstrap manually',\n manualSnippet: INSTRUMENTATION_TS,\n }\n }\n const insertAt = anchor.index + anchor[0].length\n const block =\n `\\n // Initialize telemetry (no-op unless TELEMETRY_BACKEND is set); Node-only.` +\n `\\n if (process.env.NEXT_RUNTIME === 'nodejs' && isTelemetryBackendEnabled()) {` +\n `\\n const { registerTelemetryForNextjs } = await import('@open-mercato/telemetry/nextjs')` +\n `\\n await registerTelemetryForNextjs()` +\n `\\n }`\n const importLine = `import { isTelemetryBackendEnabled } from '@open-mercato/shared/lib/telemetry/runtime'\\n`\n const withImport = content.includes('isTelemetryBackendEnabled')\n ? content\n : importLine + content\n const shiftedInsertAt = insertAt + (withImport.length - content.length)\n const next = withImport.slice(0, shiftedInsertAt) + block + withImport.slice(shiftedInsertAt)\n if (!options.dryRun) writeFileSync(path, next)\n return { file, status: 'patched', detail: 'inserted registerTelemetryForNextjs() into register()' }\n}\n\nasync function patchNextConfig(appDir: string, options: TelemetryInitOptions): Promise<StepResult> {\n const file = 'next.config.ts'\n const path = join(appDir, file)\n if (!existsSync(path)) {\n return { file, status: 'manual', detail: 'next.config.ts not found', manualSnippet: nextConfigSnippet() }\n }\n // Use ts-morph to *detect* the real `serverExternalPackages` array literal\n // (robust against a match inside a comment/string), then do the *insertion*\n // via a formatting-preserving text splice so the user's config stays tidy.\n const { Project, SyntaxKind } = await import('ts-morph')\n const project = new Project({ skipAddingFilesFromTsConfig: true, skipFileDependencyResolution: true })\n const sf = project.addSourceFileAtPath(path)\n\n const telemetryConfigImport = sf\n .getImportDeclarations()\n .find((decl) => [\n '@open-mercato/telemetry/nextjs',\n '@open-mercato/telemetry/nextjs-config',\n ].includes(decl.getModuleSpecifierValue()))\n const hasImport = Boolean(telemetryConfigImport)\n const hasCanonicalImport =\n telemetryConfigImport?.getModuleSpecifierValue() === '@open-mercato/telemetry/nextjs-config'\n\n const arrayProp = sf\n .getDescendantsOfKind(SyntaxKind.PropertyAssignment)\n .find((prop) => prop.getName() === 'serverExternalPackages')\n const arrayInit = arrayProp?.getInitializerIfKind(SyntaxKind.ArrayLiteralExpression)\n if (!arrayInit) {\n return {\n file,\n status: 'manual',\n detail: 'serverExternalPackages array not found',\n manualSnippet: nextConfigSnippet(),\n }\n }\n const hasSpread = arrayInit.getElements().some((el) => el.getText().includes('telemetryServerExternalPackages'))\n if (hasCanonicalImport && hasSpread) {\n return { file, status: 'skipped', detail: 'telemetryServerExternalPackages already wired' }\n }\n\n let text = readFileSync(path, 'utf8')\n // Splice the array first, using the AST node's byte offsets (formatting-agnostic:\n // handles both single-line and multi-line arrays). Do this before modifying\n // imports, because either an inserted import or the legacy import migration\n // shifts the array offsets captured from the original source.\n if (!hasSpread) {\n const start = arrayInit.getStart()\n const end = arrayInit.getEnd()\n text = text.slice(0, start) + insertSpread(text.slice(start, end)) + text.slice(end)\n }\n text = text.replace(\n \"from '@open-mercato/telemetry/nextjs'\",\n \"from '@open-mercato/telemetry/nextjs-config'\",\n )\n if (!hasImport) {\n const importRegex = /^import[^\\n]*$/gm\n let lastImport: RegExpExecArray | null = null\n let match: RegExpExecArray | null\n while ((match = importRegex.exec(text)) !== null) lastImport = match\n const insertAt = lastImport ? lastImport.index + lastImport[0].length : 0\n text =\n text.slice(0, insertAt) +\n `\\nimport { telemetryServerExternalPackages } from '@open-mercato/telemetry/nextjs-config'` +\n text.slice(insertAt)\n }\n if (!options.dryRun) writeFileSync(path, text)\n return { file, status: 'patched', detail: 'spread telemetryServerExternalPackages into serverExternalPackages' }\n}\n\n/** Add `...telemetryServerExternalPackages` as the last element of an array literal, preserving its style. */\nfunction insertSpread(arrayText: string): string {\n const inner = arrayText.slice(1, -1)\n if (inner.includes('\\n')) {\n const elementIndent = inner.match(/\\n([ \\t]+)\\S/)?.[1] ?? ' '\n const closeIndent = arrayText.match(/\\n([ \\t]*)\\]$/)?.[1] ?? ''\n const trimmed = inner.replace(/\\s*$/, '')\n const separator = trimmed === '' || trimmed.endsWith(',') ? '' : ','\n return `[${trimmed}${separator}\\n${elementIndent}...telemetryServerExternalPackages,\\n${closeIndent}]`\n }\n const flat = inner.trim()\n return flat === '' ? '[...telemetryServerExternalPackages]' : `[${flat}, ...telemetryServerExternalPackages]`\n}\n\nfunction nextConfigSnippet(): string {\n return (\n `import { telemetryServerExternalPackages } from '@open-mercato/telemetry/nextjs-config'\\n` +\n `// serverExternalPackages: [ ...existing, ...telemetryServerExternalPackages ]`\n )\n}\n\n/**\n * Auto-patch the catch-all API dispatcher \u2014 but only when it still matches the\n * known scaffold shape (all anchors present, telemetry not yet wired). On any\n * mismatch, print the snippet and mark it manual rather than editing an\n * unrecognized (customized) handler.\n */\nfunction patchDispatcher(appDir: string, options: TelemetryInitOptions): StepResult {\n const file = 'src/app/api/[...slug]/route.ts'\n const path = join(appDir, file)\n if (!existsSync(path)) {\n return { file, status: 'manual', detail: 'dispatcher not found', manualSnippet: DISPATCHER_SNIPPET }\n }\n let content = readFileSync(path, 'utf8')\n if (\n content.includes(\"from '@open-mercato/shared/lib/telemetry/runtime'\")\n && content.includes('getTelemetryRuntime()?.recordHttpDuration')\n ) {\n return { file, status: 'skipped', detail: 'telemetry already wired' }\n }\n if (\n content.includes(\"import { reportError } from '@open-mercato/telemetry'\")\n && content.includes(\"import { recordHttpDuration } from '@open-mercato/telemetry/nextjs'\")\n ) {\n content = content\n .replace(\n \"import { reportError } from '@open-mercato/telemetry'\\nimport { recordHttpDuration } from '@open-mercato/telemetry/nextjs'\",\n \"import { getTelemetryRuntime } from '@open-mercato/shared/lib/telemetry/runtime'\",\n )\n .replace(/\\brecordHttpDuration\\(/g, 'getTelemetryRuntime()?.recordHttpDuration(')\n .replace(/\\breportError\\(/g, 'getTelemetryRuntime()?.reportError(')\n if (!options.dryRun) writeFileSync(path, content)\n return { file, status: 'patched', detail: 'migrated dispatcher to the default-off runtime bridge' }\n }\n\n const importAnchor = \"import { isCrudHttpError } from '@open-mercato/shared/lib/crud/errors'\"\n const returnMatch = content.match(/^([ \\t]*)return finalResponse\\s*$/m)\n // The handleRequest catch is the first `} catch (error) {` after the success return.\n const catchRegex = /^([ \\t]*)\\}\\s*catch\\s*\\(error\\)\\s*\\{[ \\t]*$/gm\n const catchMatch = findCatchAfter(content, catchRegex, returnMatch?.index ?? -1)\n\n if (!content.includes(importAnchor) || !returnMatch || returnMatch.index === undefined || !catchMatch) {\n return {\n file,\n status: 'manual',\n detail: 'dispatcher shape not recognized \u2014 apply the snippet by hand',\n manualSnippet: DISPATCHER_SNIPPET,\n }\n }\n\n // 1) imports\n content = content.replace(\n importAnchor,\n `${importAnchor}\\nimport { getTelemetryRuntime } from '@open-mercato/shared/lib/telemetry/runtime'`,\n )\n\n // 2) success-path metric (re-match after the import edit shifted offsets)\n const ret = content.match(/^([ \\t]*)return finalResponse\\s*$/m)\n if (!ret || ret.index === undefined) {\n return { file, status: 'manual', detail: 'success-path anchor lost', manualSnippet: DISPATCHER_SNIPPET }\n }\n const retIndent = ret[1]\n content =\n content.slice(0, ret.index) +\n `${retIndent}getTelemetryRuntime()?.recordHttpDuration(method, match.route.path, finalResponse.status, startedAt)\\n` +\n content.slice(ret.index)\n\n // 3) catch-block error funnel + 500 metric\n const catch2 = findCatchAfter(content, /^([ \\t]*)\\}\\s*catch\\s*\\(error\\)\\s*\\{[ \\t]*$/gm, content.indexOf('return finalResponse'))\n if (!catch2) {\n return { file, status: 'manual', detail: 'catch anchor lost', manualSnippet: DISPATCHER_SNIPPET }\n }\n const bodyIndent = `${catch2.indent} `\n const insertAt = catch2.index + catch2.length\n const block =\n `\\n${bodyIndent}getTelemetryRuntime()?.reportError(error, {` +\n `\\n${bodyIndent} attributes: { 'http.request.method': method, 'http.route': match.route.path, 'http.response.status_code': 500 },` +\n `\\n${bodyIndent}})` +\n `\\n${bodyIndent}getTelemetryRuntime()?.recordHttpDuration(method, match.route.path, 500, startedAt)`\n content = content.slice(0, insertAt) + block + content.slice(insertAt)\n\n if (!options.dryRun) writeFileSync(path, content)\n return { file, status: 'patched', detail: 'wired reportError (5xx) + http.server.request.duration metric' }\n}\n\nfunction findCatchAfter(\n content: string,\n regex: RegExp,\n afterIndex: number,\n): { index: number; length: number; indent: string } | null {\n regex.lastIndex = 0\n let match: RegExpExecArray | null\n while ((match = regex.exec(content)) !== null) {\n if (match.index > afterIndex) {\n return { index: match.index, length: match[0].length, indent: match[1] }\n }\n }\n return null\n}\n\nexport async function runTelemetryInit(args: string[]): Promise<number> {\n const appDir = resolve('.')\n const options = parseArgs(args)\n\n if (!existsSync(join(appDir, 'src', 'modules.ts'))) {\n console.error('\u274C Not an Open Mercato app directory (src/modules.ts not found)')\n return 1\n }\n if (!existsSync(join(appDir, 'package.json'))) {\n console.error('\u274C package.json not found')\n return 1\n }\n\n console.log('')\n console.log(options.dryRun ? '\uD83D\uDD2D Telemetry init (dry run \u2014 no files written)\\n' : '\uD83D\uDD2D Wiring @open-mercato/telemetry into this app\\n')\n\n const results: StepResult[] = []\n results.push(patchPackageJson(appDir, options))\n const envExample = patchEnvFile(appDir, '.env.example', options)\n if (envExample) results.push(envExample)\n const env = patchEnvFile(appDir, '.env', options)\n if (env) results.push(env)\n results.push(patchInstrumentation(appDir, options))\n results.push(await patchNextConfig(appDir, options))\n results.push(patchDispatcher(appDir, options))\n\n const icon: Record<StepStatus, string> = { created: '\u270D\uFE0F ', patched: '\u2705', skipped: '\u23ED\uFE0F ', manual: '\u26A0\uFE0F ' }\n for (const result of results) {\n console.log(`${icon[result.status]} ${result.file} \u2014 ${result.detail}`)\n }\n\n const manual = results.filter((result) => result.status === 'manual')\n for (const result of manual) {\n if (!result.manualSnippet) continue\n console.log('')\n console.log(`\u2500\u2500 manual step for ${result.file} \u2500\u2500`)\n console.log(result.manualSnippet)\n }\n\n console.log('')\n const changed = results.some((result) => result.status === 'patched' || result.status === 'created')\n if (options.dryRun) {\n console.log('Dry run complete \u2014 re-run without --dry-run to apply.')\n } else if (changed) {\n console.log('Next steps:')\n console.log(' 1. yarn install (resolve @open-mercato/telemetry + the OTEL SDK)')\n console.log(' 2. set TELEMETRY_BACKEND + OTEL_EXPORTER_OTLP_* in .env')\n console.log(' 3. yarn typecheck && yarn build (verify the wiring)')\n } else {\n console.log('Nothing to do \u2014 telemetry is already wired.')\n }\n if (manual.length > 0) {\n console.log('')\n console.log(`\u26A0\uFE0F ${manual.length} file(s) need a manual edit (shown above) \u2014 the rest were applied automatically.`)\n }\n return 0\n}\n"],
|
|
5
|
-
"mappings": "AAA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sourcesContent": ["import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'node:fs'\nimport { dirname, join, resolve } from 'node:path'\n\n/**\n * `mercato telemetry init` \u2014 wire `@open-mercato/telemetry` into an app that was\n * scaffolded before telemetry existed. Deterministic, idempotent, and safe to\n * re-run: each step detects whether it is already applied and skips.\n *\n * The web-tier wiring lives in app-owned source files (a dependency bump cannot\n * touch them), so this patches them in place using the same idioms the rest of\n * the CLI uses: JSON edits, detect-before-append for `.env`, a ts-morph edit for\n * `next.config.ts`, and anchored insertion for `instrumentation.ts`, the API\n * dispatcher, `src/modules.ts`, and the backoffice layout. When a file's shape is\n * not recognized (a customized dispatcher, an unusual next.config, a rewritten\n * layout), the step degrades to printing the exact snippet and flags it as a\n * manual step rather than editing code it does not understand.\n *\n * \"Already wired\" is decided per capability, not per file: an app initialized\n * before browser RUM shipped has the core telemetry block and none of the RUM\n * wiring, and re-running the command is how it adopts the difference.\n *\n * Worker/scheduler telemetry is not handled here \u2014 it ships transitively via\n * `@open-mercato/cli`'s telemetry dependency once the app updates its packages.\n */\n\nconst BULLMQ_OTEL_VERSION = '^1.3.1'\n\ntype StepStatus = 'created' | 'patched' | 'skipped' | 'manual'\n\ntype StepResult = {\n file: string\n status: StepStatus\n detail: string\n /** Snippet to show when the step needs manual work. */\n manualSnippet?: string\n}\n\ntype TelemetryInitOptions = {\n dryRun: boolean\n}\n\nconst ENV_CORE_BLOCK = `\n# --- Telemetry & Observability (vendor-neutral OTLP: traces, logs, metrics, errors) ---\n# Off by default: leave TELEMETRY_BACKEND unset (or =noop) for a hard no-op\n# (the OpenTelemetry SDK is never loaded). Set to 'console' for local span/metric\n# output, or an OTLP backend to export: 'signoz' | 'newrelic' | 'otlp' (generic).\n# All three OTLP names use the same exporter \u2014 they differ only by the endpoint +\n# headers below. Any OTLP backend is a one-line swap; no code change.\n# TELEMETRY_BACKEND=otlp\n# Logs use the shared logger facade and its OM_LOG_LEVEL / OM_LOG_PRETTY /\n# OM_LOG_DESTINATION controls. Telemetry adds remote export; it does not create\n# a second local output path.\n# TELEMETRY_SAMPLING_RATIO=1.0 # 0.0\u20131.0 (default 1.0 dev / 0.1 prod)\n# TELEMETRY_TRUST_INBOUND_TRACE=false # default false: root-per-request (ignore an\n# # inbound traceparent from a proxy/LB). Set true\n# # only behind a trusted upstream whose trace continues.\n# # This also enables richer bullmq-otel spans;\n# # otherwise async queues use metadata._trace.\n#\n# OTLP endpoint + auth \u2014 pick ONE vendor (use your region's host):\n# SigNoz Cloud:\n# OTEL_EXPORTER_OTLP_ENDPOINT=https://ingest.<region>.signoz.cloud:443\n# OTEL_EXPORTER_OTLP_HEADERS=signoz-ingestion-key=<your-ingestion-key>\n# New Relic (OTLP-native; EU host shown, US is https://otlp.nr-data.net):\n# OTEL_EXPORTER_OTLP_ENDPOINT=https://otlp.eu01.nr-data.net\n# OTEL_EXPORTER_OTLP_HEADERS=api-key=<your-ingest-license-key>\n#\n# Resource identity: keep one stable service name across environments and\n# separate envs via the deployment.environment resource attribute.\n# OTEL_SERVICE_NAME=open-mercato\n# OTEL_RESOURCE_ATTRIBUTES=deployment.environment=local\n`\n\n/**\n * Appended on its own when an app already carries the core block \u2014 an app\n * initialized before browser RUM shipped must be able to adopt it by re-running\n * the command.\n */\nconst ENV_BROWSER_BLOCK = `\n# --- Browser RUM (client-side telemetry) ---\n# Document-load and fetch spans exported from the backoffice through a\n# same-origin proxy (/api/telemetry/browser-traces) that adds the collector\n# credential server-side. Off by default; requires an active\n# TELEMETRY_BACKEND + OTLP endpoint above.\n# Read at request time (not NEXT_PUBLIC_*), so toggling needs no rebuild.\n# Browser spans join their server spans only when TELEMETRY_TRUST_INBOUND_TRACE=true\n# above; without it RUM still works, but each page yields two separate traces.\n# Ingest budget: each open tab exports at most 20 batches/min (a 3s batch delay),\n# and the proxy allows 400/min per authenticated user \u2014 roughly 20 concurrent tabs.\n# Over that, batches are dropped with 204 rather than a retryable status, so the\n# only symptom is missing spans for that one user, never a client retry storm.\n# TELEMETRY_BROWSER_ENABLED=false\n# TELEMETRY_BROWSER_SAMPLING_RATIO=1.0 # 0.0-1.0 (default 1.0)\n# TELEMETRY_BROWSER_SERVICE_NAME= # default: <OTEL_SERVICE_NAME>-browser\n`\n\nconst ENV_BLOCK = `${ENV_CORE_BLOCK}${ENV_BROWSER_BLOCK}`\n\nconst INSTRUMENTATION_TS = `import { isTelemetryBackendEnabled } from '@open-mercato/shared/lib/telemetry/runtime'\n\nexport async function register(): Promise<void> {\n // Initialize telemetry (no-op unless TELEMETRY_BACKEND is set). OTEL's NodeSDK\n // is Node-only and incompatible with the edge runtime, so the telemetry\n // bootstrap \u2014 which can pull in the SDK \u2014 is imported only on the Node.js\n // runtime. The helper owns init + graceful degrade + shutdown flush.\n if (\n process.env.NEXT_RUNTIME === 'nodejs'\n && isTelemetryBackendEnabled()\n ) {\n const { registerTelemetryForNextjs } = await import('@open-mercato/telemetry/nextjs')\n await registerTelemetryForNextjs()\n }\n}\n`\n\nconst DISPATCHER_SNIPPET = ` // add near the other imports:\n import { getTelemetryRuntime } from '@open-mercato/shared/lib/telemetry/runtime'\n\n // in the dispatcher's success path, just before returning the response:\n getTelemetryRuntime()?.recordHttpDuration(method, match.route.path, finalResponse.status, startedAt)\n\n // in the dispatcher's catch (error) block, before re-throwing:\n getTelemetryRuntime()?.reportError(error, {\n attributes: { 'http.request.method': method, 'http.route': match.route.path, 'http.response.status_code': 500 },\n })\n getTelemetryRuntime()?.recordHttpDuration(method, match.route.path, 500, startedAt)`\n\nfunction parseArgs(args: string[]): TelemetryInitOptions {\n return {\n dryRun: args.includes('--dry-run') || args.includes('-n'),\n }\n}\n\n/** Read the version an app already pins its `@open-mercato/*` deps to (lockstep). */\nfunction resolveOpenMercatoVersion(pkg: Record<string, unknown>): string {\n for (const field of ['dependencies', 'devDependencies'] as const) {\n const deps = pkg[field]\n if (deps && typeof deps === 'object') {\n for (const [name, version] of Object.entries(deps as Record<string, string>)) {\n if (name.startsWith('@open-mercato/') && typeof version === 'string') return version\n }\n }\n }\n return '*'\n}\n\nfunction patchPackageJson(appDir: string, options: TelemetryInitOptions): StepResult {\n const file = 'package.json'\n const path = join(appDir, file)\n const raw = readFileSync(path, 'utf8')\n const pkg = JSON.parse(raw) as {\n dependencies?: Record<string, string>\n optionalDependencies?: Record<string, string>\n }\n const version = resolveOpenMercatoVersion(pkg)\n const hasTelemetry = Boolean(pkg.dependencies?.['@open-mercato/telemetry'])\n const hasBullmqOtel = Boolean(pkg.optionalDependencies?.['bullmq-otel'])\n if (hasTelemetry && hasBullmqOtel) {\n return { file, status: 'skipped', detail: '@open-mercato/telemetry already installed' }\n }\n\n const deps = { ...(pkg.dependencies ?? {}) }\n if (!hasTelemetry) deps['@open-mercato/telemetry'] = version\n const optDeps = { ...(pkg.optionalDependencies ?? {}) }\n if (!hasBullmqOtel) optDeps['bullmq-otel'] = BULLMQ_OTEL_VERSION\n\n const next = {\n ...pkg,\n dependencies: sortRecord(deps),\n optionalDependencies: sortRecord(optDeps),\n }\n if (!options.dryRun) writeFileSync(path, `${JSON.stringify(next, null, 2)}\\n`)\n return {\n file,\n status: 'patched',\n detail: `+@open-mercato/telemetry@${version}${hasBullmqOtel ? '' : ` +bullmq-otel@${BULLMQ_OTEL_VERSION} (optional)`} \u2014 run \\`yarn install\\``,\n }\n}\n\nfunction sortRecord(record: Record<string, string>): Record<string, string> {\n return Object.fromEntries(Object.entries(record).sort(([a], [b]) => a.localeCompare(b)))\n}\n\nfunction patchEnvFile(appDir: string, relativePath: string, options: TelemetryInitOptions): StepResult | null {\n const path = join(appDir, relativePath)\n if (!existsSync(path)) return null\n const content = readFileSync(path, 'utf8')\n // Checked key by key, not block by block: an app initialized before browser RUM\n // shipped has the core keys and none of the browser ones, and re-running the\n // command is how it adopts them.\n const hasCore = content.includes('TELEMETRY_BACKEND')\n const hasBrowser = content.includes('TELEMETRY_BROWSER_ENABLED')\n if (hasCore && hasBrowser) {\n return { file: relativePath, status: 'skipped', detail: 'TELEMETRY_* block already present' }\n }\n const next = `${content.replace(/\\s*$/, '')}\\n${hasCore ? ENV_BROWSER_BLOCK : ENV_BLOCK}`\n if (!options.dryRun) writeFileSync(path, next)\n return {\n file: relativePath,\n status: 'patched',\n detail: hasCore\n ? 'appended the missing TELEMETRY_BROWSER_* block'\n : 'appended commented TELEMETRY_* / OTEL_* block',\n }\n}\n\nconst MODULES_SNIPPET = ` // in the enabledModules array:\n { id: 'telemetry', from: '@open-mercato/telemetry' },`\n\n/**\n * Register the `telemetry` module, which owns the same-origin OTLP proxy the\n * browser exporter posts to. Without it `TELEMETRY_BROWSER_ENABLED` produces a\n * client that exports into a 404.\n */\nfunction patchModules(appDir: string, options: TelemetryInitOptions): StepResult {\n const file = 'src/modules.ts'\n const path = join(appDir, file)\n const content = readFileSync(path, 'utf8')\n if (/id:\\s*'telemetry'/.test(content)) {\n return { file, status: 'skipped', detail: 'telemetry module already enabled' }\n }\n const anchor = content.match(/export\\s+const\\s+enabledModules[^=]*=\\s*\\[/)\n if (!anchor || anchor.index === undefined) {\n return {\n file,\n status: 'manual',\n detail: 'enabledModules array not found \u2014 add the entry by hand',\n manualSnippet: MODULES_SNIPPET,\n }\n }\n const insertAt = anchor.index + anchor[0].length\n const block =\n `\\n // Same-origin OTLP proxy for browser RUM spans; inert unless` +\n `\\n // TELEMETRY_BROWSER_ENABLED is set alongside an active telemetry backend.` +\n `\\n { id: 'telemetry', from: '@open-mercato/telemetry' },`\n if (!options.dryRun) writeFileSync(path, content.slice(0, insertAt) + block + content.slice(insertAt))\n return { file, status: 'patched', detail: \"enabled the 'telemetry' module (browser-traces proxy route)\" }\n}\n\nconst LAYOUT_FILE = 'src/app/(backend)/backend/layout.tsx'\n\nconst LAYOUT_SNIPPET = ` // add near the other imports:\n import { BrowserTelemetry } from '@open-mercato/telemetry/browser'\n import { resolveBrowserTelemetryConfig } from '@open-mercato/telemetry/browser/server'\n\n // in the component body, before the returned JSX:\n // pass the request's Cookie header when the layout already reads cookies\n // (only consulted by the integration-test opt-in; production is env-only):\n const browserTelemetryConfig = resolveBrowserTelemetryConfig({ cookieHeader: cookieStore.toString() })\n\n // as the last child of <AppShell>:\n <BrowserTelemetry config={browserTelemetryConfig} />`\n\n/**\n * The config resolver takes the request's `Cookie` header so an integration spec can opt one page\n * into browser RUM; production resolution is env-only and never reads it. A scaffolded layout\n * already awaits `cookies()`, so reuse that binding \u2014 but an app that removed it must still get a\n * layout that compiles, hence the argument-free fallback. Both forms behave identically outside an\n * `OM_TEST_MODE` environment.\n */\nfunction resolveArgument(layout: string): string {\n const binding = layout.match(/const\\s+(\\w+)\\s*=\\s*await\\s+cookies\\(\\)/)\n return binding ? `{ cookieHeader: ${binding[1]}.toString() }` : ''\n}\n\n/**\n * Render the client bootstrap in the backoffice shell. The config is resolved\n * per request (the layout is `force-dynamic`), so RUM toggles per environment\n * without a rebuild.\n *\n * A backoffice layout is the file apps customize most, so this only edits one\n * that still matches the scaffold shape; anything else gets the snippet.\n */\nfunction patchBackendLayout(appDir: string, options: TelemetryInitOptions): StepResult {\n const path = join(appDir, LAYOUT_FILE)\n if (!existsSync(path)) {\n return { file: LAYOUT_FILE, status: 'manual', detail: 'backend layout not found', manualSnippet: LAYOUT_SNIPPET }\n }\n const content = readFileSync(path, 'utf8')\n if (content.includes('<BrowserTelemetry')) {\n return { file: LAYOUT_FILE, status: 'skipped', detail: 'BrowserTelemetry already rendered' }\n }\n const closingShell = content.lastIndexOf('</AppShell>')\n const returnMatch = content.match(/^([ \\t]*)return \\(\\s*$/m)\n const lastImport = [...content.matchAll(/^import[^\\n]*$/gm)].at(-1)\n if (closingShell === -1 || !returnMatch || returnMatch.index === undefined || !lastImport) {\n return {\n file: LAYOUT_FILE,\n status: 'manual',\n detail: 'layout shape not recognized \u2014 apply the snippet by hand',\n manualSnippet: LAYOUT_SNIPPET,\n }\n }\n\n // Edit back to front so each earlier anchor's offset stays valid.\n const shellIndent = content.slice(0, closingShell).match(/\\n([ \\t]*)$/)?.[1] ?? ' '\n let next =\n content.slice(0, closingShell) +\n `<BrowserTelemetry config={browserTelemetryConfig} />\\n${shellIndent}` +\n content.slice(closingShell)\n\n const returnIndent = returnMatch[1]\n next =\n next.slice(0, returnMatch.index) +\n `${returnIndent}// Resolved per request (this layout is force-dynamic), so browser RUM can be\\n` +\n `${returnIndent}// toggled per environment without a rebuild. Null keeps the SDK chunk from\\n` +\n `${returnIndent}// ever being requested.\\n` +\n `${returnIndent}const browserTelemetryConfig = resolveBrowserTelemetryConfig(${resolveArgument(content)})\\n\\n` +\n next.slice(returnMatch.index)\n\n const importInsertAt = (lastImport.index ?? 0) + lastImport[0].length\n next =\n next.slice(0, importInsertAt) +\n `\\nimport { BrowserTelemetry } from '@open-mercato/telemetry/browser'` +\n `\\nimport { resolveBrowserTelemetryConfig } from '@open-mercato/telemetry/browser/server'` +\n next.slice(importInsertAt)\n\n if (!options.dryRun) writeFileSync(path, next)\n return { file: LAYOUT_FILE, status: 'patched', detail: 'rendered <BrowserTelemetry /> in the backoffice shell' }\n}\n\nfunction patchInstrumentation(appDir: string, options: TelemetryInitOptions): StepResult {\n const file = 'src/instrumentation.ts'\n const path = join(appDir, file)\n if (!existsSync(path)) {\n if (!options.dryRun) {\n mkdirSync(dirname(path), { recursive: true })\n writeFileSync(path, INSTRUMENTATION_TS)\n }\n return { file, status: 'created', detail: 'Node-runtime-guarded registerTelemetryForNextjs() bootstrap' }\n }\n const content = readFileSync(path, 'utf8')\n if (content.includes('registerTelemetryForNextjs')) {\n if (content.includes('isTelemetryBackendEnabled')) {\n return { file, status: 'skipped', detail: 'telemetry already wired' }\n }\n const migrated =\n `import { isTelemetryBackendEnabled } from '@open-mercato/shared/lib/telemetry/runtime'\\n` +\n content.replace(\n `if (process.env.NEXT_RUNTIME === 'nodejs') {`,\n `if (process.env.NEXT_RUNTIME === 'nodejs' && isTelemetryBackendEnabled()) {`,\n )\n if (!options.dryRun) writeFileSync(path, migrated)\n return { file, status: 'patched', detail: 'added the explicit backend import guard' }\n }\n const anchor = content.match(/export\\s+async\\s+function\\s+register\\s*\\([^)]*\\)\\s*:\\s*Promise<void>\\s*\\{/)\n if (!anchor || anchor.index === undefined) {\n return {\n file,\n status: 'manual',\n detail: 'register() not found \u2014 add the telemetry bootstrap manually',\n manualSnippet: INSTRUMENTATION_TS,\n }\n }\n const insertAt = anchor.index + anchor[0].length\n const block =\n `\\n // Initialize telemetry (no-op unless TELEMETRY_BACKEND is set); Node-only.` +\n `\\n if (process.env.NEXT_RUNTIME === 'nodejs' && isTelemetryBackendEnabled()) {` +\n `\\n const { registerTelemetryForNextjs } = await import('@open-mercato/telemetry/nextjs')` +\n `\\n await registerTelemetryForNextjs()` +\n `\\n }`\n const importLine = `import { isTelemetryBackendEnabled } from '@open-mercato/shared/lib/telemetry/runtime'\\n`\n const withImport = content.includes('isTelemetryBackendEnabled')\n ? content\n : importLine + content\n const shiftedInsertAt = insertAt + (withImport.length - content.length)\n const next = withImport.slice(0, shiftedInsertAt) + block + withImport.slice(shiftedInsertAt)\n if (!options.dryRun) writeFileSync(path, next)\n return { file, status: 'patched', detail: 'inserted registerTelemetryForNextjs() into register()' }\n}\n\nasync function patchNextConfig(appDir: string, options: TelemetryInitOptions): Promise<StepResult> {\n const file = 'next.config.ts'\n const path = join(appDir, file)\n if (!existsSync(path)) {\n return { file, status: 'manual', detail: 'next.config.ts not found', manualSnippet: nextConfigSnippet() }\n }\n // Use ts-morph to *detect* the real `serverExternalPackages` array literal\n // (robust against a match inside a comment/string), then do the *insertion*\n // via a formatting-preserving text splice so the user's config stays tidy.\n const { Project, SyntaxKind } = await import('ts-morph')\n const project = new Project({ skipAddingFilesFromTsConfig: true, skipFileDependencyResolution: true })\n const sf = project.addSourceFileAtPath(path)\n\n const telemetryConfigImport = sf\n .getImportDeclarations()\n .find((decl) => [\n '@open-mercato/telemetry/nextjs',\n '@open-mercato/telemetry/nextjs-config',\n ].includes(decl.getModuleSpecifierValue()))\n const hasImport = Boolean(telemetryConfigImport)\n const hasCanonicalImport =\n telemetryConfigImport?.getModuleSpecifierValue() === '@open-mercato/telemetry/nextjs-config'\n\n const arrayProp = sf\n .getDescendantsOfKind(SyntaxKind.PropertyAssignment)\n .find((prop) => prop.getName() === 'serverExternalPackages')\n const arrayInit = arrayProp?.getInitializerIfKind(SyntaxKind.ArrayLiteralExpression)\n if (!arrayInit) {\n return {\n file,\n status: 'manual',\n detail: 'serverExternalPackages array not found',\n manualSnippet: nextConfigSnippet(),\n }\n }\n const hasSpread = arrayInit.getElements().some((el) => el.getText().includes('telemetryServerExternalPackages'))\n if (hasCanonicalImport && hasSpread) {\n return { file, status: 'skipped', detail: 'telemetryServerExternalPackages already wired' }\n }\n\n let text = readFileSync(path, 'utf8')\n // Splice the array first, using the AST node's byte offsets (formatting-agnostic:\n // handles both single-line and multi-line arrays). Do this before modifying\n // imports, because either an inserted import or the legacy import migration\n // shifts the array offsets captured from the original source.\n if (!hasSpread) {\n const start = arrayInit.getStart()\n const end = arrayInit.getEnd()\n text = text.slice(0, start) + insertSpread(text.slice(start, end)) + text.slice(end)\n }\n text = text.replace(\n \"from '@open-mercato/telemetry/nextjs'\",\n \"from '@open-mercato/telemetry/nextjs-config'\",\n )\n if (!hasImport) {\n const importRegex = /^import[^\\n]*$/gm\n let lastImport: RegExpExecArray | null = null\n let match: RegExpExecArray | null\n while ((match = importRegex.exec(text)) !== null) lastImport = match\n const insertAt = lastImport ? lastImport.index + lastImport[0].length : 0\n text =\n text.slice(0, insertAt) +\n `\\nimport { telemetryServerExternalPackages } from '@open-mercato/telemetry/nextjs-config'` +\n text.slice(insertAt)\n }\n if (!options.dryRun) writeFileSync(path, text)\n return { file, status: 'patched', detail: 'spread telemetryServerExternalPackages into serverExternalPackages' }\n}\n\n/** Add `...telemetryServerExternalPackages` as the last element of an array literal, preserving its style. */\nfunction insertSpread(arrayText: string): string {\n const inner = arrayText.slice(1, -1)\n if (inner.includes('\\n')) {\n const elementIndent = inner.match(/\\n([ \\t]+)\\S/)?.[1] ?? ' '\n const closeIndent = arrayText.match(/\\n([ \\t]*)\\]$/)?.[1] ?? ''\n const trimmed = inner.replace(/\\s*$/, '')\n const separator = trimmed === '' || trimmed.endsWith(',') ? '' : ','\n return `[${trimmed}${separator}\\n${elementIndent}...telemetryServerExternalPackages,\\n${closeIndent}]`\n }\n const flat = inner.trim()\n return flat === '' ? '[...telemetryServerExternalPackages]' : `[${flat}, ...telemetryServerExternalPackages]`\n}\n\nfunction nextConfigSnippet(): string {\n return (\n `import { telemetryServerExternalPackages } from '@open-mercato/telemetry/nextjs-config'\\n` +\n `// serverExternalPackages: [ ...existing, ...telemetryServerExternalPackages ]`\n )\n}\n\n/**\n * Auto-patch the catch-all API dispatcher \u2014 but only when it still matches the\n * known scaffold shape (all anchors present, telemetry not yet wired). On any\n * mismatch, print the snippet and mark it manual rather than editing an\n * unrecognized (customized) handler.\n */\nfunction patchDispatcher(appDir: string, options: TelemetryInitOptions): StepResult {\n const file = 'src/app/api/[...slug]/route.ts'\n const path = join(appDir, file)\n if (!existsSync(path)) {\n return { file, status: 'manual', detail: 'dispatcher not found', manualSnippet: DISPATCHER_SNIPPET }\n }\n let content = readFileSync(path, 'utf8')\n if (\n content.includes(\"from '@open-mercato/shared/lib/telemetry/runtime'\")\n && content.includes('getTelemetryRuntime()?.recordHttpDuration')\n ) {\n return { file, status: 'skipped', detail: 'telemetry already wired' }\n }\n if (\n content.includes(\"import { reportError } from '@open-mercato/telemetry'\")\n && content.includes(\"import { recordHttpDuration } from '@open-mercato/telemetry/nextjs'\")\n ) {\n content = content\n .replace(\n \"import { reportError } from '@open-mercato/telemetry'\\nimport { recordHttpDuration } from '@open-mercato/telemetry/nextjs'\",\n \"import { getTelemetryRuntime } from '@open-mercato/shared/lib/telemetry/runtime'\",\n )\n .replace(/\\brecordHttpDuration\\(/g, 'getTelemetryRuntime()?.recordHttpDuration(')\n .replace(/\\breportError\\(/g, 'getTelemetryRuntime()?.reportError(')\n if (!options.dryRun) writeFileSync(path, content)\n return { file, status: 'patched', detail: 'migrated dispatcher to the default-off runtime bridge' }\n }\n\n const importAnchor = \"import { isCrudHttpError } from '@open-mercato/shared/lib/crud/errors'\"\n const returnMatch = content.match(/^([ \\t]*)return finalResponse\\s*$/m)\n // The handleRequest catch is the first `} catch (error) {` after the success return.\n const catchRegex = /^([ \\t]*)\\}\\s*catch\\s*\\(error\\)\\s*\\{[ \\t]*$/gm\n const catchMatch = findCatchAfter(content, catchRegex, returnMatch?.index ?? -1)\n\n if (!content.includes(importAnchor) || !returnMatch || returnMatch.index === undefined || !catchMatch) {\n return {\n file,\n status: 'manual',\n detail: 'dispatcher shape not recognized \u2014 apply the snippet by hand',\n manualSnippet: DISPATCHER_SNIPPET,\n }\n }\n\n // 1) imports\n content = content.replace(\n importAnchor,\n `${importAnchor}\\nimport { getTelemetryRuntime } from '@open-mercato/shared/lib/telemetry/runtime'`,\n )\n\n // 2) success-path metric (re-match after the import edit shifted offsets)\n const ret = content.match(/^([ \\t]*)return finalResponse\\s*$/m)\n if (!ret || ret.index === undefined) {\n return { file, status: 'manual', detail: 'success-path anchor lost', manualSnippet: DISPATCHER_SNIPPET }\n }\n const retIndent = ret[1]\n content =\n content.slice(0, ret.index) +\n `${retIndent}getTelemetryRuntime()?.recordHttpDuration(method, match.route.path, finalResponse.status, startedAt)\\n` +\n content.slice(ret.index)\n\n // 3) catch-block error funnel + 500 metric\n const catch2 = findCatchAfter(content, /^([ \\t]*)\\}\\s*catch\\s*\\(error\\)\\s*\\{[ \\t]*$/gm, content.indexOf('return finalResponse'))\n if (!catch2) {\n return { file, status: 'manual', detail: 'catch anchor lost', manualSnippet: DISPATCHER_SNIPPET }\n }\n const bodyIndent = `${catch2.indent} `\n const insertAt = catch2.index + catch2.length\n const block =\n `\\n${bodyIndent}getTelemetryRuntime()?.reportError(error, {` +\n `\\n${bodyIndent} attributes: { 'http.request.method': method, 'http.route': match.route.path, 'http.response.status_code': 500 },` +\n `\\n${bodyIndent}})` +\n `\\n${bodyIndent}getTelemetryRuntime()?.recordHttpDuration(method, match.route.path, 500, startedAt)`\n content = content.slice(0, insertAt) + block + content.slice(insertAt)\n\n if (!options.dryRun) writeFileSync(path, content)\n return { file, status: 'patched', detail: 'wired reportError (5xx) + http.server.request.duration metric' }\n}\n\nfunction findCatchAfter(\n content: string,\n regex: RegExp,\n afterIndex: number,\n): { index: number; length: number; indent: string } | null {\n regex.lastIndex = 0\n let match: RegExpExecArray | null\n while ((match = regex.exec(content)) !== null) {\n if (match.index > afterIndex) {\n return { index: match.index, length: match[0].length, indent: match[1] }\n }\n }\n return null\n}\n\nexport async function runTelemetryInit(args: string[]): Promise<number> {\n const appDir = resolve('.')\n const options = parseArgs(args)\n\n if (!existsSync(join(appDir, 'src', 'modules.ts'))) {\n console.error('\u274C Not an Open Mercato app directory (src/modules.ts not found)')\n return 1\n }\n if (!existsSync(join(appDir, 'package.json'))) {\n console.error('\u274C package.json not found')\n return 1\n }\n\n console.log('')\n console.log(options.dryRun ? '\uD83D\uDD2D Telemetry init (dry run \u2014 no files written)\\n' : '\uD83D\uDD2D Wiring @open-mercato/telemetry into this app\\n')\n\n const results: StepResult[] = []\n results.push(patchPackageJson(appDir, options))\n const envExample = patchEnvFile(appDir, '.env.example', options)\n if (envExample) results.push(envExample)\n const env = patchEnvFile(appDir, '.env', options)\n if (env) results.push(env)\n results.push(patchInstrumentation(appDir, options))\n results.push(await patchNextConfig(appDir, options))\n results.push(patchDispatcher(appDir, options))\n results.push(patchModules(appDir, options))\n results.push(patchBackendLayout(appDir, options))\n\n const icon: Record<StepStatus, string> = { created: '\u270D\uFE0F ', patched: '\u2705', skipped: '\u23ED\uFE0F ', manual: '\u26A0\uFE0F ' }\n for (const result of results) {\n console.log(`${icon[result.status]} ${result.file} \u2014 ${result.detail}`)\n }\n\n const manual = results.filter((result) => result.status === 'manual')\n for (const result of manual) {\n if (!result.manualSnippet) continue\n console.log('')\n console.log(`\u2500\u2500 manual step for ${result.file} \u2500\u2500`)\n console.log(result.manualSnippet)\n }\n\n console.log('')\n const changed = results.some((result) => result.status === 'patched' || result.status === 'created')\n if (options.dryRun) {\n console.log('Dry run complete \u2014 re-run without --dry-run to apply.')\n } else if (changed) {\n console.log('Next steps:')\n console.log(' 1. yarn install (resolve @open-mercato/telemetry + the OTEL SDK)')\n console.log(' 2. set TELEMETRY_BACKEND + OTEL_EXPORTER_OTLP_* in .env')\n console.log(' 3. yarn typecheck && yarn build (verify the wiring)')\n } else {\n console.log('Nothing to do \u2014 telemetry is already wired.')\n }\n if (manual.length > 0) {\n console.log('')\n console.log(`\u26A0\uFE0F ${manual.length} file(s) need a manual edit (shown above) \u2014 the rest were applied automatically.`)\n }\n return 0\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,YAAY,cAAc,eAAe,iBAAiB;AACnE,SAAS,SAAS,MAAM,eAAe;AAwBvC,MAAM,sBAAsB;AAgB5B,MAAM,iBAAiB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAqCvB,MAAM,oBAAoB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAkB1B,MAAM,YAAY,GAAG,cAAc,GAAG,iBAAiB;AAEvD,MAAM,qBAAqB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiB3B,MAAM,qBAAqB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAY3B,SAAS,UAAU,MAAsC;AACvD,SAAO;AAAA,IACL,QAAQ,KAAK,SAAS,WAAW,KAAK,KAAK,SAAS,IAAI;AAAA,EAC1D;AACF;AAGA,SAAS,0BAA0B,KAAsC;AACvE,a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IAAI,gCAAsB,OAAO,IAAI,eAAK;AAClD,YAAQ,IAAI,OAAO,aAAa;AAAA,EAClC;AAEA,UAAQ,IAAI,EAAE;AACd,QAAM,UAAU,QAAQ,KAAK,CAAC,WAAW,OAAO,WAAW,aAAa,OAAO,WAAW,SAAS;AACnG,MAAI,QAAQ,QAAQ;AAClB,YAAQ,IAAI,4DAAuD;AAAA,EACrE,WAAW,SAAS;AAClB,YAAQ,IAAI,aAAa;AACzB,YAAQ,IAAI,oFAAoF;AAChG,YAAQ,IAAI,2DAA2D;AACvE,YAAQ,IAAI,uDAAuD;AAAA,EACrE,OAAO;AACL,YAAQ,IAAI,kDAA6C;AAAA,EAC3D;AACA,MAAI,OAAO,SAAS,GAAG;AACrB,YAAQ,IAAI,EAAE;AACd,YAAQ,IAAI,iBAAO,OAAO,MAAM,uFAAkF;AAAA,EACpH;AACA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1585,6 +1585,11 @@ function buildReusableEnvironment(baseUrl, databaseUrl, queueBaseDir, captureScr
|
|
|
1585
1585
|
OM_TEST_MODE: "1",
|
|
1586
1586
|
OM_TEST_EMAIL_CAPTURE_PATH: process.env.OM_TEST_EMAIL_CAPTURE_PATH ?? EPHEMERAL_EMAIL_CAPTURE_PATH,
|
|
1587
1587
|
OM_TEST_AUTH_RATE_LIMIT_MODE: "opt-in",
|
|
1588
|
+
// Browser RUM is an environment-wide env switch, so without a per-request opt-in a spec
|
|
1589
|
+
// could only cover the enabled path by booting the OTel web SDK on every page of every
|
|
1590
|
+
// other spec. Same shape as the auth rate-limit escape hatch above: inert unless a request
|
|
1591
|
+
// also carries the `om_test_browser_telemetry=on` cookie, which only TC-TELEMETRY-002 sets.
|
|
1592
|
+
OM_TEST_BROWSER_TELEMETRY_MODE: "opt-in",
|
|
1588
1593
|
OM_DISABLE_EMAIL_DELIVERY: "0",
|
|
1589
1594
|
OM_ENABLE_TEST_CHANNEL_SEEDING: "true",
|
|
1590
1595
|
OM_ENABLE_TEST_EMAIL_CAPTURE_DELIVERY: "true",
|
|
@@ -2796,6 +2801,11 @@ async function startEphemeralEnvironment(options) {
|
|
|
2796
2801
|
OM_TEST_MODE: "1",
|
|
2797
2802
|
OM_TEST_EMAIL_CAPTURE_PATH: process.env.OM_TEST_EMAIL_CAPTURE_PATH ?? EPHEMERAL_EMAIL_CAPTURE_PATH,
|
|
2798
2803
|
OM_TEST_AUTH_RATE_LIMIT_MODE: "opt-in",
|
|
2804
|
+
// Browser RUM is an environment-wide env switch, so without a per-request opt-in a spec
|
|
2805
|
+
// could only cover the enabled path by booting the OTel web SDK on every page of every
|
|
2806
|
+
// other spec. Same shape as the auth rate-limit escape hatch above: inert unless a request
|
|
2807
|
+
// also carries the `om_test_browser_telemetry=on` cookie, which only TC-TELEMETRY-002 sets.
|
|
2808
|
+
OM_TEST_BROWSER_TELEMETRY_MODE: "opt-in",
|
|
2799
2809
|
OM_ENABLE_TEST_CHANNEL_SEEDING: "true",
|
|
2800
2810
|
OM_ENABLE_TEST_EMAIL_CAPTURE_DELIVERY: "true",
|
|
2801
2811
|
OM_TEST_SYSTEM_EMAIL_CAPTURE_PATH: EPHEMERAL_SYSTEM_EMAIL_CAPTURE_PATH,
|