Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 29 additions & 51 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions crates/capabilities/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "libdatadog-nodejs-capabilities"
version = "0.1.0"
version = "0.2.0"
edition = "2021"
description = "Wasm capability implementations for libdatadog-nodejs (backed by JS transports)"

Expand All @@ -15,9 +15,7 @@ http = "1"
bytes = "1.4"
futures-core = "0.3"
anyhow = "1"
# TODO: Replace this temporary libdatadog PR rev with the official release/tag
# that contains DataDog/libdatadog#2235, then regenerate Cargo.lock.
libdd-capabilities = { git = "https://github.com/DataDog/libdatadog.git", rev = "8cd68ab922fb7aade0f089ccfc91291d874673af" }
libdd-capabilities = { git = "https://github.com/DataDog/libdatadog.git", rev = "0c6e2a5df2a163d34c4f385353ffc5d7257c72f4" }

[dev-dependencies]
wasm-bindgen-test = "0.3"
33 changes: 33 additions & 0 deletions crates/capabilities/src/env.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2026-Present Datadog, Inc. https://www.datadoghq.com/
// SPDX-License-Identifier: Apache-2.0

//! Wasm implementation of [`EnvCapability`] backed by Node.js `process.env`.

use wasm_bindgen::prelude::*;

use libdd_capabilities::env::{EnvCapability, EnvError};

#[wasm_bindgen(module = "/src/env_transport.js")]
extern "C" {
#[wasm_bindgen(js_name = "get")]
fn js_env_get(name: &str) -> JsValue;
}

#[derive(Debug, Clone)]
pub struct WasmEnvCapability;

impl EnvCapability for WasmEnvCapability {
fn new() -> Self {
Self
}

fn get(&self, name: &str) -> Result<Option<String>, EnvError> {
// Node coerces every process.env value to a string, so NotUnicode is unreachable here.
let value = js_env_get(name);
if value.is_undefined() || value.is_null() {
Ok(None)
} else {
Ok(value.as_string())
}
}
}
5 changes: 5 additions & 0 deletions crates/capabilities/src/env_transport.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict'

module.exports.get = function (name) {
return process.env[name]
}
25 changes: 17 additions & 8 deletions crates/capabilities/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@
use std::future::Future;
use std::time::Duration;

use libdd_capabilities::env::{EnvCapability, EnvError};
use libdd_capabilities::http::HttpError;
use libdd_capabilities::{HttpClientCapability, LogWriterCapability, MaybeSend, SleepCapability};

pub mod env;
pub mod http;
pub mod sleep;

pub use env::WasmEnvCapability;
pub use http::WasmHttpClient;
pub use sleep::WasmSleepCapability;

Expand All @@ -33,6 +36,7 @@ pub use sleep::WasmSleepCapability;
pub struct WasmCapabilities {
http: WasmHttpClient,
sleep: WasmSleepCapability,
env: WasmEnvCapability,
}

impl Default for WasmCapabilities {
Expand All @@ -46,16 +50,14 @@ impl WasmCapabilities {
Self {
http: WasmHttpClient::new_client(),
sleep: WasmSleepCapability,
env: WasmEnvCapability,
}
}
}

impl HttpClientCapability for WasmCapabilities {
fn new_client() -> Self {
Self {
http: WasmHttpClient::new_client(),
sleep: WasmSleepCapability,
}
Self::new()
}

fn request(
Expand All @@ -68,10 +70,7 @@ impl HttpClientCapability for WasmCapabilities {

impl SleepCapability for WasmCapabilities {
fn new() -> Self {
Self {
http: WasmHttpClient::new_client(),
sleep: WasmSleepCapability,
}
Self::new()
}

fn sleep(&self, duration: Duration) -> impl Future<Output = ()> + MaybeSend {
Expand All @@ -89,3 +88,13 @@ impl LogWriterCapability for WasmCapabilities {
Ok(())
}
}

impl EnvCapability for WasmCapabilities {
fn new() -> Self {
Self::new()
}

fn get(&self, name: &str) -> Result<Option<String>, EnvError> {
self.env.get(name)
}
}
2 changes: 1 addition & 1 deletion crates/library_config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ crate-type = ["cdylib", "rlib"]

[dependencies]
anyhow = "1"
libdd-library-config = { git = "https://github.com/DataDog/libdatadog.git", rev = "353134770b312b7ccd2df6afabc253090b948e5f" }
libdd-library-config = { git = "https://github.com/DataDog/libdatadog.git", rev = "0c6e2a5df2a163d34c4f385353ffc5d7257c72f4" }

wasm-bindgen = "0.2.100"
serde = { version = "1.0", features = ["derive"] }
Expand Down
Loading
Loading