@decocms/blocks 7.15.1 → 7.16.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/package.json +1 -1
- package/src/sdk/otel.ts +29 -0
package/package.json
CHANGED
package/src/sdk/otel.ts
CHANGED
|
@@ -99,6 +99,23 @@ import { RequestContext } from "./requestContext";
|
|
|
99
99
|
// ---------------------------------------------------------------------------
|
|
100
100
|
|
|
101
101
|
export interface OtelOptions {
|
|
102
|
+
/**
|
|
103
|
+
* When `true`, skips all observability exporters (AE, OTLP metrics,
|
|
104
|
+
* logs, traces). Overridden by the env var.
|
|
105
|
+
*/
|
|
106
|
+
disabled?: boolean;
|
|
107
|
+
/**
|
|
108
|
+
* Env var name holding the tri-state observability switch. Values:
|
|
109
|
+
* - `"on"` → force enable (even in local dev)
|
|
110
|
+
* - `"off"` → force disable
|
|
111
|
+
* - unset → auto: enabled in real deploys, disabled in local
|
|
112
|
+
*
|
|
113
|
+
* Local is detected by the absence of `CF_VERSION_METADATA` (a binding
|
|
114
|
+
* that only exists in production/preview Cloudflare deploys).
|
|
115
|
+
*
|
|
116
|
+
* Defaults to `"DECO_OTEL"`.
|
|
117
|
+
*/
|
|
118
|
+
envVar?: string;
|
|
102
119
|
/** Logical service name. Falls back to `env.DECO_SITE_NAME`, then "deco-site". */
|
|
103
120
|
serviceName?: string;
|
|
104
121
|
/** Env var name holding the AE binding. Defaults to `"DECO_METRICS"`. */
|
|
@@ -624,6 +641,18 @@ function bootObservability(opts: OtelOptions, env: Record<string, unknown>): voi
|
|
|
624
641
|
const state = getBootState();
|
|
625
642
|
if (state.booted) return;
|
|
626
643
|
|
|
644
|
+
// CF_VERSION_METADATA is only present in real (production/preview) deploys;
|
|
645
|
+
// wrangler dev never sets it, making it a reliable local-dev signal.
|
|
646
|
+
const mode = env[opts.envVar ?? "DECO_OTEL"];
|
|
647
|
+
const isLocal = !env.CF_VERSION_METADATA;
|
|
648
|
+
const isDisabled =
|
|
649
|
+
mode === "off" ||
|
|
650
|
+
(mode !== "on" && (opts.disabled || isLocal));
|
|
651
|
+
if (isDisabled) {
|
|
652
|
+
state.booted = true;
|
|
653
|
+
return;
|
|
654
|
+
}
|
|
655
|
+
|
|
627
656
|
// Capture the original console.warn BEFORE patchConsole() runs. The onError
|
|
628
657
|
// callbacks below need a direct channel to console that bypasses the logger
|
|
629
658
|
// to avoid routing exporter-level warnings back through the OTLP adapter
|