Skip to content

Commit 011b38e

Browse files
authored
feat: Remove configuration via yaml (#10)
* feat: Remove yaml configuration * update LICENSE-3rdparty.csv * simplify test module paths
1 parent d7d7a8b commit 011b38e

39 files changed

+783
-758
lines changed

Cargo.lock

Lines changed: 333 additions & 280 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,15 @@ license = "Apache-2.0"
99
# crate-type = ["cdylib"]
1010
# This was originally set as above, but commented to run tests in tests folder.
1111

12-
1312
[profile.release]
1413
lto = true
1514

1615
[dependencies]
17-
nodejs-semver = "4.1.0"
18-
swc = "16.1.0"
19-
swc_core = { version = "16.2.3", features = ["ecma_plugin_transform","ecma_quote"] }
20-
swc_ecma_parser = "10.0.0"
21-
swc_ecma_visit = { version = "8.0.0", features = ["path"] }
22-
yaml-rust2 = "0.10.0"
16+
nodejs-semver = "4"
17+
swc = "21"
18+
swc_core = { version = "22", features = ["ecma_plugin_transform","ecma_quote"] }
19+
swc_ecma_parser = "11"
20+
swc_ecma_visit = { version = "8", features = ["path"] }
2321

2422
[dev-dependencies]
25-
assert_cmd = "2.0.16"
23+
assert_cmd = "2"

LICENSE-3rdparty.csv

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@ android-tzdata,https://github.com/RumovZ/android-tzdata,MIT OR Apache-2.0,RumovZ
77
android_system_properties,https://github.com/nical/android_system_properties,MIT OR Apache-2.0,Nicolas Silva <[email protected]>
88
ansi_term,https://github.com/ogham/rust-ansi-term,MIT,"[email protected], Ryan Scheel (Havvy) <[email protected]>, Josh Triplett <[email protected]>"
99
anyhow,https://github.com/dtolnay/anyhow,MIT OR Apache-2.0,David Tolnay <[email protected]>
10-
arraydeque,https://github.com/andylokandy/arraydeque,MIT OR Apache-2.0,andylokandy
1110
arrayvec,https://github.com/bluss/arrayvec,MIT OR Apache-2.0,bluss
1211
ascii,https://github.com/tomprogrammer/rust-ascii,Apache-2.0 OR MIT,"Thomas Bahn <[email protected]>, Torbjørn Birch Moltu <[email protected]>, Simon Sapin <[email protected]>"
1312
auto_impl,https://github.com/auto-impl-rs/auto_impl,MIT OR Apache-2.0,"Ashley Mannix <[email protected]>, Lukas Kalbertodt <[email protected]>"
14-
base64,https://github.com/marshallpierce/rust-base64,MIT OR Apache-2.0,"Alice Maz <[email protected]>, Marshall Pierce <[email protected]>"
13+
base64,https://github.com/marshallpierce/rust-base64,MIT OR Apache-2.0,Marshall Pierce <[email protected]>
1514
base64-simd,https://github.com/Nugine/simd,MIT,The base64-simd Authors
1615
bitflags,https://github.com/bitflags/bitflags,MIT OR Apache-2.0,The Rust Project Developers
1716
bitvec,https://github.com/bitvecto-rs/bitvec,MIT,The bitvec Authors
@@ -39,18 +38,15 @@ difference,https://github.com/johannhof/difference.rs,MIT,Johann Hofmann <mail@j
3938
digest,https://github.com/RustCrypto/traits,MIT OR Apache-2.0,RustCrypto Developers
4039
displaydoc,https://github.com/yaahc/displaydoc,MIT OR Apache-2.0,Jane Lusby <[email protected]>
4140
either,https://github.com/rayon-rs/either,MIT OR Apache-2.0,bluss
42-
encoding_rs,https://github.com/hsivonen/encoding_rs,(Apache-2.0 OR MIT) AND BSD-3-Clause,Henri Sivonen <[email protected]>
4341
equivalent,https://github.com/indexmap-rs/equivalent,Apache-2.0 OR MIT,The equivalent Authors
44-
errno,https://github.com/lambda-fairy/rust-errno,MIT OR Apache-2.0,Chris Wong <[email protected]>
42+
errno,https://github.com/lambda-fairy/rust-errno,MIT OR Apache-2.0,"Chris Wong <[email protected]>, Dan Gohman <[email protected]>"
4543
fastrand,https://github.com/smol-rs/fastrand,Apache-2.0 OR MIT,Stjepan Glavina <[email protected]>
4644
fixedbitset,https://github.com/petgraph/fixedbitset,MIT OR Apache-2.0,bluss
47-
foldhash,https://github.com/orlp/foldhash,Zlib,Orson Peters <[email protected]>
4845
funty,https://github.com/myrrlyn/funty,MIT,myrrlyn <[email protected]>
4946
generic-array,https://github.com/fizyk20/generic-array,MIT,"Bartłomiej Kamiński <[email protected]>, Aaron Trent <[email protected]>"
5047
getrandom,https://github.com/rust-random/getrandom,MIT OR Apache-2.0,The Rand Project Developers
5148
glob,https://github.com/rust-lang/glob,MIT OR Apache-2.0,The Rust Project Developers
5249
hashbrown,https://github.com/rust-lang/hashbrown,MIT OR Apache-2.0,Amanieu d'Antras <[email protected]>
53-
hashlink,https://github.com/kyren/hashlink,MIT OR Apache-2.0,kyren <[email protected]>
5450
heck,https://github.com/withoutboats/heck,MIT OR Apache-2.0,The heck Authors
5551
hermit-abi,https://github.com/hermit-os/hermit-rs,MIT OR Apache-2.0,Stefan Lankes
5652
hex,https://github.com/KokaKiwi/rust-hex,MIT OR Apache-2.0,KokaKiwi <[email protected]>
@@ -98,6 +94,8 @@ once_cell,https://github.com/matklad/once_cell,MIT OR Apache-2.0,Aleksey Kladov
9894
outref,https://github.com/Nugine/outref,MIT,The outref Authors
9995
overload,https://github.com/danaugrs/overload,MIT,Daniel Salvadori <[email protected]>
10096
owo-colors,https://github.com/owo-colors/owo-colors,MIT,jam1garner <[email protected]>
97+
par-core,https://github.com/dudykr/ddbase,Apache-2.0,강동윤 <[email protected]>
98+
par-iter,https://github.com/dudykr/ddbase,Apache-2.0,The par-iter Authors
10199
parking_lot,https://github.com/Amanieu/parking_lot,MIT OR Apache-2.0,Amanieu d'Antras <[email protected]>
102100
path-clean,https://github.com/danreeves/path-clean,MIT OR Apache-2.0,Dan Reeves <[email protected]>
103101
pathdiff,https://github.com/Manishearth/pathdiff,MIT OR Apache-2.0,Manish Goregaokar <[email protected]>
@@ -109,6 +107,7 @@ proc-macro2,https://github.com/dtolnay/proc-macro2,MIT OR Apache-2.0,"David Toln
109107
psm,https://github.com/rust-lang/stacker,MIT OR Apache-2.0,Simonas Kazlauskas <[email protected]>
110108
ptr_meta,https://github.com/rkyv/ptr_meta,MIT,David Koloski <[email protected]>
111109
quote,https://github.com/dtolnay/quote,MIT OR Apache-2.0,David Tolnay <[email protected]>
110+
r-efi,https://github.com/r-efi/r-efi,MIT OR Apache-2.0 OR LGPL-2.1-or-later,The r-efi Authors
112111
radium,https://github.com/bitvecto-rs/radium,MIT,"Nika Layzell <[email protected]>, myrrlyn <[email protected]>"
113112
radix_fmt,https://gitlab.com/Boiethios/radix_fmt_rs,Apache-2.0,Félix <[email protected]>
114113
rancor,https://github.com/rkyv/rancor,MIT,David Koloski <[email protected]>
@@ -192,7 +191,11 @@ wasm-bindgen-shared,https://github.com/rustwasm/wasm-bindgen/tree/master/crates/
192191
winapi,https://github.com/retep998/winapi-rs,MIT OR Apache-2.0,Peter Atashian <[email protected]>
193192
winapi-util,https://github.com/BurntSushi/winapi-util,Unlicense OR MIT,Andrew Gallant <[email protected]>
194193
windows-core,https://github.com/microsoft/windows-rs,MIT OR Apache-2.0,Microsoft
194+
windows-implement,https://github.com/microsoft/windows-rs,MIT OR Apache-2.0,Microsoft
195+
windows-interface,https://github.com/microsoft/windows-rs,MIT OR Apache-2.0,Microsoft
195196
windows-link,https://github.com/microsoft/windows-rs,MIT OR Apache-2.0,Microsoft
197+
windows-result,https://github.com/microsoft/windows-rs,MIT OR Apache-2.0,Microsoft
198+
windows-strings,https://github.com/microsoft/windows-rs,MIT OR Apache-2.0,Microsoft
196199
windows-sys,https://github.com/microsoft/windows-rs,MIT OR Apache-2.0,Microsoft
197200
windows-targets,https://github.com/microsoft/windows-rs,MIT OR Apache-2.0,Microsoft
198201
windows_aarch64_gnullvm,https://github.com/microsoft/windows-rs,MIT OR Apache-2.0,Microsoft
@@ -204,11 +207,10 @@ windows_x86_64_gnu,https://github.com/microsoft/windows-rs,MIT OR Apache-2.0,Mic
204207
windows_x86_64_gnullvm,https://github.com/microsoft/windows-rs,MIT OR Apache-2.0,Microsoft
205208
windows_x86_64_msvc,https://github.com/microsoft/windows-rs,MIT OR Apache-2.0,Microsoft
206209
winnow,https://github.com/winnow-rs/winnow,MIT,The winnow Authors
207-
wit-bindgen-rt,https://github.com/bytecodealliance/wasi-rs,Apache-2.0 WITH LLVM-exception OR Apache-2.0 OR MIT,The wit-bindgen-rt Authors
210+
wit-bindgen-rt,https://github.com/bytecodealliance/wit-bindgen,Apache-2.0 WITH LLVM-exception OR Apache-2.0 OR MIT,The wit-bindgen-rt Authors
208211
write16,https://github.com/hsivonen/write16,Apache-2.0 OR MIT,The write16 Authors
209212
writeable,https://github.com/unicode-org/icu4x,Unicode-3.0,The ICU4X Project Developers
210213
wyz,https://github.com/myrrlyn/wyz,MIT,myrrlyn <[email protected]>
211-
yaml-rust2,https://github.com/Ethiraric/yaml-rust2,MIT OR Apache-2.0,"Yuheng Chen <[email protected]>, Ethiraric <[email protected]>, David Aguilar <[email protected]>"
212214
yansi,https://github.com/SergioBenitez/yansi,MIT OR Apache-2.0,Sergio Benitez <[email protected]>
213215
yoke,https://github.com/unicode-org/icu4x,Unicode-3.0,Manish Goregaokar <[email protected]>
214216
yoke-derive,https://github.com/unicode-org/icu4x,Unicode-3.0,Manish Goregaokar <[email protected]>

src/config.rs

Lines changed: 23 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,9 @@
22
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
33
* This product includes software developed at Datadog (<https://www.datadoghq.com>/). Copyright 2025 Datadog, Inc.
44
**/
5-
use std::path::PathBuf;
6-
7-
use nodejs_semver::{Range, Version};
8-
9-
use crate::error::OrchestrionError;
105
use crate::function_query::FunctionQuery;
11-
12-
use yaml_rust2::{Yaml, YamlLoader};
13-
14-
macro_rules! get_str {
15-
($property:expr, $name:expr) => {
16-
$property[$name]
17-
.as_str()
18-
.ok_or(format!("Invalid config: '{}' must be a string", $name))?
19-
};
20-
}
21-
22-
macro_rules! get_arr {
23-
($property:expr, $name:expr) => {
24-
$property[$name]
25-
.as_vec()
26-
.ok_or(format!("Invalid config: '{}' must be a array", $name))?
27-
};
28-
}
6+
use nodejs_semver::{Range, Version};
7+
use std::path::PathBuf;
298

309
#[derive(Clone, Debug)]
3110
pub enum InstrumentationOperator {
@@ -36,6 +15,7 @@ pub enum InstrumentationOperator {
3615
}
3716

3817
impl InstrumentationOperator {
18+
#[must_use]
3919
pub fn as_str(&self) -> &'static str {
4020
match self {
4121
InstrumentationOperator::Callback => "traceCallback",
@@ -44,19 +24,9 @@ impl InstrumentationOperator {
4424
InstrumentationOperator::Async => "traceAsync",
4525
}
4626
}
47-
48-
pub fn from_str(s: &str) -> Option<InstrumentationOperator> {
49-
match s {
50-
"traceCallback" => Some(InstrumentationOperator::Callback),
51-
"tracePromise" => Some(InstrumentationOperator::Promise),
52-
"traceSync" => Some(InstrumentationOperator::Sync),
53-
"traceAsync" => Some(InstrumentationOperator::Async),
54-
_ => None,
55-
}
56-
}
5727
}
5828

59-
#[derive(Debug)]
29+
#[derive(Debug, Clone)]
6030
pub struct InstrumentationConfig {
6131
pub module_name: String,
6232
pub version_range: Range,
@@ -66,85 +36,43 @@ pub struct InstrumentationConfig {
6636
pub channel_name: String,
6737
}
6838

39+
#[derive(Debug, Clone)]
6940
pub struct Config {
7041
pub instrumentations: Vec<InstrumentationConfig>,
7142
pub dc_module: String,
7243
}
7344

7445
impl Config {
75-
pub fn from_yaml_data(yaml_str: &str) -> Result<Config, OrchestrionError> {
76-
let docs = YamlLoader::load_from_str(yaml_str)?;
77-
let doc = &docs[0];
78-
79-
let version = doc["version"]
80-
.as_i64()
81-
.ok_or("Invalid config: 'version' must be a number")?;
82-
if version != 1 {
83-
return Err("Invalid config version".into());
46+
#[must_use]
47+
pub fn new(instrumentations: Vec<InstrumentationConfig>, dc_module: String) -> Self {
48+
Self {
49+
instrumentations,
50+
dc_module,
8451
}
85-
86-
let dc_module = doc["dc_module"].as_str().unwrap_or("diagnostics_channel");
87-
88-
let configs = InstrumentationConfig::from_yaml(doc)?;
89-
90-
Ok(Config {
91-
instrumentations: configs,
92-
dc_module: dc_module.to_string(),
93-
})
9452
}
95-
}
96-
97-
impl InstrumentationConfig {
98-
pub fn from_yaml(doc: &Yaml) -> Result<Vec<InstrumentationConfig>, OrchestrionError> {
99-
let instrumentations = get_arr!(doc, "instrumentations");
100-
let mut configs = Vec::new();
10153

102-
for instr in instrumentations {
103-
instr
104-
.as_hash()
105-
.ok_or("Invalid config: 'instrumentations' must be a array of objects")?;
106-
configs.push(instr.try_into()?);
54+
#[must_use]
55+
pub fn new_single_with_default_dc_module(instrumentation: InstrumentationConfig) -> Self {
56+
Self {
57+
instrumentations: vec![instrumentation],
58+
dc_module: "diagnostics_channel".to_string(),
10759
}
108-
109-
Ok(configs)
11060
}
61+
}
11162

63+
impl InstrumentationConfig {
64+
#[must_use]
11265
pub fn matches(&self, module_name: &str, version: &str, file_path: &PathBuf) -> bool {
11366
let version: Version = match version.parse() {
11467
Ok(v) => v,
115-
Err(_) => return false,
68+
Err(e) => {
69+
println!("Failed to parse version {version}: {e}");
70+
return false;
71+
}
11672
};
73+
11774
self.module_name == module_name
11875
&& version.satisfies(&self.version_range)
11976
&& self.file_path == *file_path
12077
}
12178
}
122-
123-
impl TryFrom<&Yaml> for InstrumentationConfig {
124-
type Error = OrchestrionError;
125-
126-
fn try_from(instr: &Yaml) -> Result<Self, Self::Error> {
127-
let module_name = get_str!(instr, "module_name");
128-
let version_range = get_str!(instr, "version_range");
129-
let version_range: Range = version_range
130-
.parse()
131-
.map_err(|_| format!("Invalid version range: {version_range}"))?;
132-
let file_path = PathBuf::from(get_str!(instr, "file_path"));
133-
if instr["function_query"].as_hash().is_none() {
134-
return Err("Invalid config: 'function_query' must be a object".into());
135-
}
136-
let function_query = (&instr["function_query"]).try_into()?;
137-
let operator = InstrumentationOperator::from_str(get_str!(instr, "operator"))
138-
.unwrap_or(InstrumentationOperator::Sync);
139-
let channel_name = get_str!(instr, "channel_name");
140-
141-
Ok(InstrumentationConfig {
142-
module_name: module_name.to_string(),
143-
version_range,
144-
file_path,
145-
function_query,
146-
operator,
147-
channel_name: channel_name.to_string(),
148-
})
149-
}
150-
}

src/error.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ use std::fmt::{self, Display, Formatter};
66

77
#[derive(Debug)]
88
pub enum OrchestrionError {
9-
InvalidVersionRange(String),
109
IoError(std::io::Error),
11-
YamlParseError(yaml_rust2::ScanError),
1210
StrError(String),
1311
}
1412

@@ -18,12 +16,6 @@ impl From<std::io::Error> for OrchestrionError {
1816
}
1917
}
2018

21-
impl From<yaml_rust2::ScanError> for OrchestrionError {
22-
fn from(e: yaml_rust2::ScanError) -> Self {
23-
OrchestrionError::YamlParseError(e)
24-
}
25-
}
26-
2719
impl From<String> for OrchestrionError {
2820
fn from(s: String) -> Self {
2921
OrchestrionError::StrError(s)
@@ -39,9 +31,7 @@ impl From<&str> for OrchestrionError {
3931
impl Display for OrchestrionError {
4032
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
4133
match self {
42-
OrchestrionError::InvalidVersionRange(s) => write!(f, "Invalid version range: {s}"),
4334
OrchestrionError::IoError(e) => write!(f, "IO error: {e}"),
44-
OrchestrionError::YamlParseError(e) => write!(f, "YAML parse error: {e}"),
4535
OrchestrionError::StrError(s) => write!(f, "String error: {s}"),
4636
}
4737
}

0 commit comments

Comments
 (0)