Skip to content

Commit

Permalink
telemetry into web
Browse files Browse the repository at this point in the history
  • Loading branch information
rscarson committed Dec 4, 2024
1 parent 9a2f7ec commit 2a1b9f2
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 51 deletions.
9 changes: 3 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
]
Expand Down
13 changes: 1 addition & 12 deletions src/ext/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")]
Expand Down Expand Up @@ -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));
Expand Down
27 changes: 0 additions & 27 deletions src/ext/telemetry/mod.rs

This file was deleted.

File renamed without changes.
20 changes: 20 additions & 0 deletions src/ext/web/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,24 @@ impl ExtensionTrait<WebOptions> 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],
Expand Down Expand Up @@ -95,10 +113,12 @@ impl ExtensionTrait<()> for deno_tls::deno_tls {
pub fn extensions(options: WebOptions, is_snapshot: bool) -> Vec<Extension> {
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),
]
Expand Down
4 changes: 4 additions & 0 deletions src/ext/web/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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(),
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/inner_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,12 @@ impl<RT: RuntimeTrait> InnerRuntime<RT> {
..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();
Expand Down Expand Up @@ -242,10 +246,6 @@ impl<RT: RuntimeTrait> InnerRuntime<RT> {
}
};

// Init otel
#[cfg(feature = "telemetry")]
deno_telemetry::init(otel_conf)?;

let mut feature_checker = FeatureChecker::default();
feature_checker.set_exit_cb(Box::new(|_, _| {}));

Expand Down

0 comments on commit 2a1b9f2

Please sign in to comment.