@powerhousedao/switchboard 6.0.0-dev.24 → 6.0.0-dev.240

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.
Files changed (83) hide show
  1. package/.env +5 -1
  2. package/Auth.md +45 -27
  3. package/CHANGELOG.md +1868 -5
  4. package/README.md +55 -12
  5. package/dist/esm-CigE675X.mjs +6481 -0
  6. package/dist/esm-CigE675X.mjs.map +1 -0
  7. package/dist/index.d.mts +2 -0
  8. package/dist/index.mjs +215 -0
  9. package/dist/index.mjs.map +1 -0
  10. package/dist/install-packages.d.mts +1 -0
  11. package/dist/install-packages.mjs +31 -0
  12. package/dist/install-packages.mjs.map +1 -0
  13. package/dist/migrate.d.mts +1 -0
  14. package/dist/migrate.mjs +57 -0
  15. package/dist/migrate.mjs.map +1 -0
  16. package/dist/server-DPxV64Dh.mjs +752 -0
  17. package/dist/server-DPxV64Dh.mjs.map +1 -0
  18. package/dist/server.d.mts +105 -0
  19. package/dist/server.d.mts.map +1 -0
  20. package/dist/server.mjs +4 -0
  21. package/dist/utils-DFl0ezBT.mjs +44 -0
  22. package/dist/utils-DFl0ezBT.mjs.map +1 -0
  23. package/dist/utils.d.mts +9 -0
  24. package/dist/utils.d.mts.map +1 -0
  25. package/dist/utils.mjs +2 -0
  26. package/package.json +67 -40
  27. package/test/attachments/auth.test.ts +219 -0
  28. package/test/attachments/index.test.ts +119 -0
  29. package/test/attachments/routes-integration.test.ts +103 -0
  30. package/test/attachments/routes.test.ts +864 -0
  31. package/test/metrics.test.ts +202 -0
  32. package/test/pglite-dialect.test.ts +40 -0
  33. package/test/pglite-version.test.ts +37 -0
  34. package/tsconfig.json +12 -3
  35. package/tsdown.config.ts +16 -0
  36. package/vitest.config.ts +11 -0
  37. package/Dockerfile +0 -86
  38. package/dist/src/clients/redis.d.ts +0 -5
  39. package/dist/src/clients/redis.d.ts.map +0 -1
  40. package/dist/src/clients/redis.js +0 -48
  41. package/dist/src/clients/redis.js.map +0 -1
  42. package/dist/src/config.d.ts +0 -12
  43. package/dist/src/config.d.ts.map +0 -1
  44. package/dist/src/config.js +0 -33
  45. package/dist/src/config.js.map +0 -1
  46. package/dist/src/connect-crypto.d.ts +0 -41
  47. package/dist/src/connect-crypto.d.ts.map +0 -1
  48. package/dist/src/connect-crypto.js +0 -127
  49. package/dist/src/connect-crypto.js.map +0 -1
  50. package/dist/src/feature-flags.d.ts +0 -2
  51. package/dist/src/feature-flags.d.ts.map +0 -1
  52. package/dist/src/feature-flags.js +0 -9
  53. package/dist/src/feature-flags.js.map +0 -1
  54. package/dist/src/index.d.ts +0 -3
  55. package/dist/src/index.d.ts.map +0 -1
  56. package/dist/src/index.js +0 -21
  57. package/dist/src/index.js.map +0 -1
  58. package/dist/src/install-packages.d.ts +0 -2
  59. package/dist/src/install-packages.d.ts.map +0 -1
  60. package/dist/src/install-packages.js +0 -36
  61. package/dist/src/install-packages.js.map +0 -1
  62. package/dist/src/migrate.d.ts +0 -3
  63. package/dist/src/migrate.d.ts.map +0 -1
  64. package/dist/src/migrate.js +0 -65
  65. package/dist/src/migrate.js.map +0 -1
  66. package/dist/src/profiler.d.ts +0 -9
  67. package/dist/src/profiler.d.ts.map +0 -1
  68. package/dist/src/profiler.js +0 -43
  69. package/dist/src/profiler.js.map +0 -1
  70. package/dist/src/server.d.ts +0 -6
  71. package/dist/src/server.d.ts.map +0 -1
  72. package/dist/src/server.js +0 -304
  73. package/dist/src/server.js.map +0 -1
  74. package/dist/src/types.d.ts +0 -64
  75. package/dist/src/types.d.ts.map +0 -1
  76. package/dist/src/types.js +0 -2
  77. package/dist/src/types.js.map +0 -1
  78. package/dist/src/utils.d.ts +0 -6
  79. package/dist/src/utils.d.ts.map +0 -1
  80. package/dist/src/utils.js +0 -92
  81. package/dist/src/utils.js.map +0 -1
  82. package/dist/tsconfig.tsbuildinfo +0 -1
  83. package/entrypoint.sh +0 -17
package/README.md CHANGED
@@ -13,6 +13,7 @@ A powerful document-driven server that provides a unified API for managing and s
13
13
  - **HTTPS Support**: Built-in HTTPS server with custom certificates
14
14
  - **Profiling**: Integration with Pyroscope for performance monitoring
15
15
  - **Error Tracking**: Sentry integration for error monitoring and reporting
16
+ - **Observability**: Unified OpenTelemetry tracing + metrics bootstrap, with optional Sentry APM bridging (same trace IDs in Tempo and Sentry)
16
17
 
17
18
  ## 📦 Installation
18
19
 
@@ -50,6 +51,7 @@ docker compose -f packages/reactor/docker-compose.yml up -d
50
51
  ```
51
52
 
52
53
  This starts:
54
+
53
55
  - PostgreSQL on port `5433` (mapped from container port 5432)
54
56
  - Adminer (database UI) on port `8080`
55
57
 
@@ -94,22 +96,21 @@ pnpm add -g @powerhousedao/switchboard
94
96
 
95
97
  ## 🏃‍♂️ Quick Start
96
98
 
97
-
98
99
  ## ⚙️ Configuration
99
100
 
100
101
  ### Environment Variables
101
102
 
102
- | Variable | Description | Default |
103
- | ---------------------------- | ---------------------------------- | --------------------- |
104
- | `PORT` | Server port | `4001` |
105
- | `DATABASE_URL` | Database connection string | `./.ph/drive-storage` |
106
- | `PH_REACTOR_DATABASE_URL` | PostgreSQL URL (takes precedence) | - |
107
- | `REDIS_URL` | Redis connection URL | - |
108
- | `REDIS_TLS_URL` | Redis TLS connection URL | - |
109
- | `SENTRY_DSN` | Sentry DSN for error tracking | - |
110
- | `SENTRY_ENV` | Sentry environment | - |
111
- | `PYROSCOPE_SERVER_ADDRESS` | Pyroscope server address | - |
112
- | `FEATURE_REACTORV2_ENABLED` | Enable Reactor v2 subgraph feature | `false` |
103
+ | Variable | Description | Default |
104
+ | --------------------------- | ---------------------------------- | --------------------- |
105
+ | `PORT` | Server port | `4001` |
106
+ | `DATABASE_URL` | Database connection string | `./.ph/drive-storage` |
107
+ | `PH_REACTOR_DATABASE_URL` | PostgreSQL URL (takes precedence) | - |
108
+ | `REDIS_URL` | Redis connection URL | - |
109
+ | `REDIS_TLS_URL` | Redis TLS connection URL | - |
110
+ | `PYROSCOPE_SERVER_ADDRESS` | Pyroscope server address | - |
111
+ | `FEATURE_REACTORV2_ENABLED` | Enable Reactor v2 subgraph feature | `false` |
112
+
113
+ See [Observability](#observability) below for Sentry and OpenTelemetry variables.
113
114
 
114
115
  ### Authentication Configuration
115
116
 
@@ -132,6 +133,47 @@ Switchboard supports multiple storage backends:
132
133
  - **PostgreSQL**: Persistent database storage
133
134
  - **Redis**: Caching layer (optional)
134
135
 
136
+ ### Observability
137
+
138
+ Switchboard bootstraps Sentry and OpenTelemetry from a single module (`src/observability.mts`) that is imported as the very first thing in `src/index.mts`. The OpenTelemetry instrumentations (`http`, `express`, `pg`, `graphql`) register require-time hooks at load, so the import order must not be changed.
139
+
140
+ What runs depends on which environment variables are set:
141
+
142
+ - `SENTRY_DSN` set → Sentry error reporting is initialized.
143
+ - `ENABLE_TRACING=true` or `NODE_ENV=production`, **and** at least one trace destination is configured (`TEMPO_ENDPOINT` or `SENTRY_DSN`) → OpenTelemetry tracing is initialized. Spans go to Tempo over OTLP HTTP if `TEMPO_ENDPOINT` is set, and/or to Sentry via `SentrySpanProcessor` if `SENTRY_DSN` is set. When both are set, the same trace IDs appear in Tempo and Sentry and cross-link in Grafana.
144
+ - Tracing requested (prod or `ENABLE_TRACING=true`) but no destination configured → a warning is logged and tracing is **not** started. This avoids the cost of patching `http`/`express`/`pg`/`graphql` and generating spans only to drop them. Set `TEMPO_ENDPOINT` and/or `SENTRY_DSN` to enable.
145
+ - `OTEL_EXPORTER_OTLP_ENDPOINT` set → metrics export to that OTLP HTTP endpoint via a periodic reader. Reactor metrics emitted by `@powerhousedao/opentelemetry-instrumentation-reactor` flow through the same global meter provider.
146
+
147
+ If neither Sentry nor a tracing destination is configured, the module is a no-op and no exporters or instrumentations are registered.
148
+
149
+ #### Environment Variables
150
+
151
+ | Variable | Description | Default |
152
+ | ----------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------- |
153
+ | `SENTRY_DSN` | Sentry DSN. When unset, Sentry is disabled. | - |
154
+ | `SENTRY_ENV` | `environment` tag passed to `Sentry.init`. | - |
155
+ | `SENTRY_RELEASE` | Release tag (must match the version uploaded by CI for source maps to resolve). | `v${npm_package_version}` if available |
156
+ | `SENTRY_TRACES_SAMPLE_RATE` | APM sampling rate (0.0–1.0). | `0.1` |
157
+ | `ENABLE_TRACING` | Set to `true` to request tracing outside production. Tracing only starts when a destination is also set. | `false` (also requested when `NODE_ENV=production`) |
158
+ | `NODE_ENV` | When `production`, tracing is requested automatically. Also exported as `deployment.environment` attribute. | `development` |
159
+ | `OTEL_SERVICE_NAME` | `service.name` resource attribute. | `switchboard` |
160
+ | `TENANT_ID` | `tenant.id` resource attribute (used to slice traces by tenant in Grafana). | `default` |
161
+ | `TEMPO_ENDPOINT` | OTLP HTTP endpoint for trace export. When unset, OTLP trace export is disabled. In-cluster deploys typically set `http://tempo.monitoring.svc.cluster.local:4318/v1/traces`. | - |
162
+ | `OTEL_EXPORTER_OTLP_ENDPOINT` | OTLP HTTP endpoint for metrics export. Metrics export is disabled when unset. | - |
163
+ | `OTEL_METRIC_EXPORT_INTERVAL` | Metric export interval in milliseconds. | `60000` |
164
+
165
+ #### Local Development
166
+
167
+ Tracing is off by default outside production, so a bare `pnpm dev` does not need any of these set. To exercise the full pipeline locally, point `TEMPO_ENDPOINT` and `OTEL_EXPORTER_OTLP_ENDPOINT` at a local OTel collector (or Tempo + Prometheus) and run with `ENABLE_TRACING=true`:
168
+
169
+ ```bash
170
+ ENABLE_TRACING=true \
171
+ TEMPO_ENDPOINT=http://localhost:4318/v1/traces \
172
+ OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318/v1/metrics \
173
+ SENTRY_DSN=... \
174
+ pnpm dev
175
+ ```
176
+
135
177
  ## 🐳 Docker Deployment
136
178
 
137
179
  ### Using Docker Compose
@@ -245,6 +287,7 @@ ph switchboard --db-path postgresql://user:pass@localhost:5432/db --migrate-stat
245
287
  #### Environment Variables for Migrations
246
288
 
247
289
  The migration commands check for a PostgreSQL URL in this order:
290
+
248
291
  1. `PH_REACTOR_DATABASE_URL`
249
292
  2. `DATABASE_URL`
250
293
  3. Config file (`powerhouse.config.json` -> `switchboard.database.url`)