diff options
author | snek <snek@deno.com> | 2024-11-14 13:16:28 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-14 12:16:28 +0000 |
commit | 4e899d48cffa95617266dd8f9aef54603a87ad82 (patch) | |
tree | ec667f58ccb4126ecad38bc4600d9dd8dc372ca5 /runtime/js/telemetry.js | |
parent | cb107a762fb903973e0d0c2e4481baf2c0bc13b8 (diff) |
fix: otel resiliency (#26857)
Improving the breadth of collected data, and ensuring that the collected
data is more likely to be successfully reported.
- Use `log` crate in more places
- Hook up `log` crate to otel
- Switch to process-wide otel processors
- Handle places that use `process::exit`
Also adds a more robust testing framework, with a deterministic tracing
setting.
Refs: https://github.com/denoland/deno/issues/26852
Diffstat (limited to 'runtime/js/telemetry.js')
-rw-r--r-- | runtime/js/telemetry.js | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/runtime/js/telemetry.js b/runtime/js/telemetry.js index e9eb51f7c..195839fb1 100644 --- a/runtime/js/telemetry.js +++ b/runtime/js/telemetry.js @@ -22,11 +22,14 @@ const { ReflectApply, SymbolFor, Error, + NumberPrototypeToString, + StringPrototypePadStart, } = primordials; const { AsyncVariable, setAsyncContext } = core; const CURRENT = new AsyncVariable(); let TRACING_ENABLED = false; +let DETERMINISTIC = false; const SPAN_ID_BYTES = 8; const TRACE_ID_BYTES = 16; @@ -45,7 +48,19 @@ const hexSliceLookupTable = (function () { return table; })(); +let counter = 1; + +const INVALID_SPAN_ID = "0000000000000000"; +const INVALID_TRACE_ID = "00000000000000000000000000000000"; + function generateId(bytes) { + if (DETERMINISTIC) { + return StringPrototypePadStart( + NumberPrototypeToString(counter++, 16), + bytes * 2, + "0", + ); + } let out = ""; for (let i = 0; i < bytes / 4; i += 1) { const r32 = (MathRandom() * 2 ** 32) >>> 0; @@ -112,8 +127,6 @@ function submit(span) { const now = () => (performance.timeOrigin + performance.now()) / 1000; -const INVALID_SPAN_ID = "0000000000000000"; -const INVALID_TRACE_ID = "00000000000000000000000000000000"; const NO_ASYNC_CONTEXT = {}; class Span { @@ -362,9 +375,10 @@ const otelConsoleConfig = { export function bootstrap(config) { if (config.length === 0) return; - const { 0: consoleConfig } = config; + const { 0: consoleConfig, 1: deterministic } = config; TRACING_ENABLED = true; + DETERMINISTIC = deterministic === 1; switch (consoleConfig) { case otelConsoleConfig.capture: |