@decocms/start 4.3.0 → 4.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bun.lock +36 -110
- package/package.json +4 -3
- package/scripts/migrate/phase-report.ts +8 -0
- package/scripts/migrate/templates/server-entry.ts +39 -3
- package/scripts/migrate-to-cf-observability.test.ts +169 -0
- package/scripts/migrate-to-cf-observability.ts +611 -0
- package/src/sdk/logger.test.ts +79 -0
- package/src/sdk/logger.ts +40 -2
- package/src/sdk/otel.test.ts +128 -15
- package/src/sdk/otel.ts +179 -98
- package/src/sdk/sampler.ts +17 -5
- package/src/sdk/workerEntry.ts +7 -4
package/src/sdk/sampler.ts
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* URL-based head sampler — port of `deco-cx/deco/observability/otel/samplers/urlBased.ts`.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* **No longer wired into `instrumentWorker` by default.** As of 4.4.0 the
|
|
5
|
+
* recommended path for trace sampling is Cloudflare's wrangler-level
|
|
6
|
+
* `observability.traces.head_sampling_rate`, which is one global rate per
|
|
7
|
+
* Worker. This module stays as an opt-in escape hatch for sites that need
|
|
8
|
+
* URL-pattern-aware sampling (e.g. always trace `/checkout`, sample
|
|
9
|
+
* homepages at 1%) — those sites must wire OTel themselves outside the
|
|
10
|
+
* default `instrumentWorker` flow.
|
|
11
|
+
*
|
|
12
|
+
* The sampler reads `OTEL_SAMPLING_CONFIG` (base64-encoded JSON) and
|
|
13
|
+
* decides each trace's sample rate based on the matching pattern.
|
|
7
14
|
*
|
|
8
15
|
* Wrapped in `ParentBasedSampler` so a span inherits its parent's sampling
|
|
9
|
-
* decision when one exists (i.e. distributed traces
|
|
16
|
+
* decision when one exists (i.e. distributed traces stay consistent end
|
|
10
17
|
* to end).
|
|
11
18
|
*
|
|
12
19
|
* **Default ratio.** When no `default` is provided in the config (or the env
|
|
@@ -28,6 +35,9 @@
|
|
|
28
35
|
* ]
|
|
29
36
|
* }
|
|
30
37
|
* ```
|
|
38
|
+
*
|
|
39
|
+
* @deprecated Slated for removal in 5.0.0 unless a site declares an active
|
|
40
|
+
* need. Use Cloudflare's `head_sampling_rate` first.
|
|
31
41
|
*/
|
|
32
42
|
|
|
33
43
|
import { type Attributes, type Context, type Link, type SpanKind, trace } from "@opentelemetry/api";
|
|
@@ -189,7 +199,9 @@ export function decodeSamplingConfig(raw: string | undefined): SamplingConfig |
|
|
|
189
199
|
|
|
190
200
|
/**
|
|
191
201
|
* Build a `ParentBasedSampler` rooted at our URL-based sampler.
|
|
192
|
-
*
|
|
202
|
+
* Wire as the `headSampler` for any custom OTel SDK setup (e.g. a site
|
|
203
|
+
* that opts back into `@microlabs/otel-cf-workers` outside the default
|
|
204
|
+
* `instrumentWorker` flow).
|
|
193
205
|
*/
|
|
194
206
|
export function createUrlBasedHeadSampler(config: SamplingConfig | null): Sampler {
|
|
195
207
|
const root = new URLBasedSampler(config ?? {});
|
package/src/sdk/workerEntry.ts
CHANGED
|
@@ -949,10 +949,13 @@ export function createDecoWorkerEntry(
|
|
|
949
949
|
// via getRuntimeEnv() in sdk/otelAdapters.ts.
|
|
950
950
|
setRuntimeEnv(env);
|
|
951
951
|
|
|
952
|
-
// Wrap inner handler in a single root span
|
|
953
|
-
//
|
|
954
|
-
//
|
|
955
|
-
//
|
|
952
|
+
// Wrap inner handler in a single root span carrying our normalized
|
|
953
|
+
// path/method attributes. With Cloudflare-managed trace export
|
|
954
|
+
// (`observability.traces.destinations` in wrangler.jsonc), this
|
|
955
|
+
// span — and any `withTracing` spans nested below it — flow to
|
|
956
|
+
// HyperDX via CF's platform-managed OTLP push, since the bridge
|
|
957
|
+
// in `instrumentWorker` configures the `@opentelemetry/api`
|
|
958
|
+
// global tracer for us.
|
|
956
959
|
return withTracing(
|
|
957
960
|
"deco.http.request",
|
|
958
961
|
async () => {
|