From 2a1b9f271468424e432e6abd507fde29a5960637 Mon Sep 17 00:00:00 2001 From: Richard Carson Date: Wed, 4 Dec 2024 11:15:34 -0500 Subject: [PATCH] telemetry into web --- Cargo.toml | 9 +++---- src/ext/mod.rs | 13 +--------- src/ext/telemetry/mod.rs | 27 -------------------- src/ext/{telemetry => web}/init_telemetry.js | 0 src/ext/web/mod.rs | 20 +++++++++++++++ src/ext/web/options.rs | 4 +++ src/inner_runtime.rs | 12 ++++----- 7 files changed, 34 insertions(+), 51 deletions(-) delete mode 100644 src/ext/telemetry/mod.rs rename src/ext/{telemetry => web}/init_telemetry.js (100%) diff --git a/Cargo.toml b/Cargo.toml index 6ce76e2..8e760e6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,7 +43,7 @@ network_extensions = ["web", "webstorage", "websocket", "http", "url", "crypto", # Extensions that provide access to the filesystem. Also enables file imports from JS # These extensions are not safe to use in a sandboxed environment without additional restrictions # (See [FsPermissions] -io_extensions = ["web", "webstorage", "fs", "io", "cache", "console", "ffi", "webgpu", "kv", "telemetry", "cron", "fs_import"] +io_extensions = ["web", "webstorage", "fs", "io", "cache", "console", "ffi", "webgpu", "kv", "cron", "fs_import"] # # Additional features that are not part of the core runtime @@ -107,18 +107,15 @@ web_stub = ["webidl", "base64-simd"] # Provides IO primitives for other Deno extensions (stdio streams, etc) io = ["deno_io", "web", "rustyline", "winapi", "nix", "libc", "once_cell"] - # Implements telemetry for Deno using OpenTelemetry. - telemetry = ["web", "deno_telemetry"] - # [https://url.spec.whatwg.org/] # [https://wicg.github.io/urlpattern/] url = ["deno_url", "webidl"] - # Timers, events, text encoder/decoder, + # Timers, events, text encoder/decoder, telemetry # [https://w3c.github.io/FileAPI] # [https://fetch.spec.whatwg.org/] web = [ - "deno_web", "deno_tls", "deno_fetch", "deno_net", "dep:http", "deno_permissions", + "deno_web", "deno_tls", "deno_fetch", "deno_net", "dep:http", "deno_permissions", "deno_telemetry", "webidl", "console", "url", "crypto", "url_import", "fs_import", "hyper-util" ] diff --git a/src/ext/mod.rs b/src/ext/mod.rs index 81f58a7..fa181c5 100644 --- a/src/ext/mod.rs +++ b/src/ext/mod.rs @@ -78,9 +78,6 @@ pub mod kv; #[cfg(feature = "cron")] pub mod cron; -#[cfg(feature = "telemetry")] -pub mod telemetry; - #[cfg(feature = "node_experimental")] pub mod napi; #[cfg(feature = "node_experimental")] @@ -147,11 +144,6 @@ pub struct ExtensionOptions { #[cfg_attr(docsrs, doc(cfg(feature = "kv")))] pub kv_store: kv::KvStore, - /// OpenTelemetry configuration for the `deno_telemetry` extension - #[cfg(feature = "telemetry")] - #[cfg_attr(docsrs, doc(cfg(feature = "telemetry")))] - pub telemetry_config: deno_telemetry::OtelConfig, - /// Package resolver for the `deno_node` extension /// `RustyResolver` allows you to select the base dir for modules /// as well as the filesystem implementation to use @@ -189,7 +181,7 @@ impl Default for ExtensionOptions { #[cfg(feature = "kv")] kv_store: kv::KvStore::default(), - #[cfg(feature = "telemetry")] + #[cfg(feature = "web")] telemetry_config: deno_telemetry::OtelConfig::default(), #[cfg(feature = "node_experimental")] @@ -263,9 +255,6 @@ pub(crate) fn all_extensions( #[cfg(feature = "cron")] extensions.extend(cron::extensions(is_snapshot)); - #[cfg(feature = "telemetry")] - extensions.extend(telemetry::extensions(is_snapshot)); - #[cfg(feature = "node_experimental")] { extensions.extend(napi::extensions(is_snapshot)); diff --git a/src/ext/telemetry/mod.rs b/src/ext/telemetry/mod.rs deleted file mode 100644 index 4029589..0000000 --- a/src/ext/telemetry/mod.rs +++ /dev/null @@ -1,27 +0,0 @@ -use super::ExtensionTrait; -use deno_core::{extension, Extension}; - -extension!( - init_telemetry, - deps = [rustyscript], - esm_entry_point = "ext:init_telemetry/init_telemetry.js", - esm = [ dir "src/ext/telemetry", "init_telemetry.js" ], -); -impl ExtensionTrait<()> for init_telemetry { - fn init((): ()) -> Extension { - init_telemetry::init_ops_and_esm() - } -} - -impl ExtensionTrait<()> for deno_telemetry::deno_telemetry { - fn init((): ()) -> Extension { - deno_telemetry::deno_telemetry::init_ops_and_esm() - } -} - -pub fn extensions(is_snapshot: bool) -> Vec { - vec![ - deno_telemetry::deno_telemetry::build((), is_snapshot), - init_telemetry::build((), is_snapshot), - ] -} diff --git a/src/ext/telemetry/init_telemetry.js b/src/ext/web/init_telemetry.js similarity index 100% rename from src/ext/telemetry/init_telemetry.js rename to src/ext/web/init_telemetry.js diff --git a/src/ext/web/mod.rs b/src/ext/web/mod.rs index bc34b51..3fa58b2 100644 --- a/src/ext/web/mod.rs +++ b/src/ext/web/mod.rs @@ -61,6 +61,24 @@ impl ExtensionTrait for deno_net::deno_net { } } +extension!( + init_telemetry, + deps = [rustyscript], + esm_entry_point = "ext:init_telemetry/init_telemetry.js", + esm = [ dir "src/ext/telemetry", "init_telemetry.js" ], +); +impl ExtensionTrait<()> for init_telemetry { + fn init((): ()) -> Extension { + init_telemetry::init_ops_and_esm() + } +} + +impl ExtensionTrait<()> for deno_telemetry::deno_telemetry { + fn init((): ()) -> Extension { + deno_telemetry::deno_telemetry::init_ops_and_esm() + } +} + extension!( init_web, deps = [rustyscript], @@ -95,10 +113,12 @@ impl ExtensionTrait<()> for deno_tls::deno_tls { pub fn extensions(options: WebOptions, is_snapshot: bool) -> Vec { vec![ deno_web::deno_web::build(options.clone(), is_snapshot), + deno_telemetry::deno_telemetry::build((), is_snapshot), deno_net::deno_net::build(options.clone(), is_snapshot), deno_fetch::deno_fetch::build(options.clone(), is_snapshot), deno_tls::deno_tls::build((), is_snapshot), init_web::build(options.clone(), is_snapshot), + init_telemetry::build((), is_snapshot), init_net::build(options.clone(), is_snapshot), init_fetch::build(options, is_snapshot), ] diff --git a/src/ext/web/options.rs b/src/ext/web/options.rs index 9ef4f05..5c155fc 100644 --- a/src/ext/web/options.rs +++ b/src/ext/web/options.rs @@ -47,6 +47,9 @@ pub struct WebOptions { /// Resolver for DNS resolution pub resolver: Resolver, + + /// OpenTelemetry configuration for the `deno_telemetry` extension + pub telemetry_config: deno_telemetry::OtelConfig, } impl Default for WebOptions { @@ -64,6 +67,7 @@ impl Default for WebOptions { blob_store: Arc::new(deno_web::BlobStore::default()), client_builder_hook: None, resolver: Resolver::default(), + telemetry_config: deno_telemetry::OtelConfig::default(), } } } diff --git a/src/inner_runtime.rs b/src/inner_runtime.rs index bf6d3c6..44b9f38 100644 --- a/src/inner_runtime.rs +++ b/src/inner_runtime.rs @@ -211,8 +211,12 @@ impl InnerRuntime { ..Default::default() })); - #[cfg(feature = "telemetry")] - let otel_conf = options.extension_options.telemetry_config.clone(); + // Init otel + #[cfg(feature = "web")] + { + let otel_conf = options.extension_options.telemetry_config.clone(); + deno_telemetry::init(otel_conf)?; + } // If a snapshot is provided, do not reload ESM for extensions let is_snapshot = options.startup_snapshot.is_some(); @@ -242,10 +246,6 @@ impl InnerRuntime { } }; - // Init otel - #[cfg(feature = "telemetry")] - deno_telemetry::init(otel_conf)?; - let mut feature_checker = FeatureChecker::default(); feature_checker.set_exit_cb(Box::new(|_, _| {}));