Skip to content

Commit

Permalink
test: featurize to reduce size for serverless
Browse files Browse the repository at this point in the history
  • Loading branch information
BaptisteFoy committed Jan 23, 2025
1 parent b42da4d commit f54495b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 15 deletions.
35 changes: 21 additions & 14 deletions ddtrace/internal/native/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,28 @@
from typing import Dict

from ._native import DDSketch # noqa: F401
from ._native import PyConfigurator


def get_configuration_from_disk(debug_logs: bool = False, file_override="") -> Dict[str, str]:
"""
Retrieves the tracer configuration from disk. Calls the PyConfigurator object
to read the configuration from the disk using the libdatadog shared library
and returns the corresponding configuration
"""
configurator = PyConfigurator(debug_logs)
configurator.set_envp(["%s=%s" % (k, v) for k, v in os.environ.items()])
configurator.set_args(sys.argv)
try:
from ._native import PyConfigurator

# Set the file override if provided. Only used for testing purposes.
if file_override:
configurator.set_file_override(file_override)
def get_configuration_from_disk(debug_logs: bool = False, file_override="") -> Dict[str, str]:
"""
Retrieves the tracer configuration from disk. Calls the PyConfigurator object
to read the configuration from the disk using the libdatadog shared library
and returns the corresponding configuration
"""
configurator = PyConfigurator(debug_logs)
configurator.set_envp(["%s=%s" % (k, v) for k, v in os.environ.items()])
configurator.set_args(sys.argv)

return configurator.get_configuration()
# Set the file override if provided. Only used for testing purposes.
if file_override:
configurator.set_file_override(file_override)

return configurator.get_configuration()

except ImportError: # In some cases (serverless) we don't compile the native module

def get_configuration_from_disk(debug_logs: bool = False, file_override="") -> Dict[str, str]:
return {}
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,7 @@ def get_exts_for(name):
path="src/native/Cargo.toml",
py_limited_api="auto",
binding=Binding.PyO3,
# features=["library_config"],
debug=os.getenv("_DD_RUSTC_DEBUG") == "1",
),
],
Expand Down
7 changes: 6 additions & 1 deletion src/native/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@ lto = true
strip = "debuginfo"
opt-level = 3 # Optimize for performance

[features]
# default = ["library_config"]
default = []
library_config = ["dep:datadog-library-config"]

[dependencies]
pyo3 = { version = "0.22.3", features = ["extension-module"] }
datadog-ddsketch = { git = "https://github.com/DataDog/libdatadog", rev = "v15.0.0" }
datadog-library-config = { git = "https://github.com/DataDog/libdatadog", rev = "v15.0.0" }
datadog-library-config = { git = "https://github.com/DataDog/libdatadog", rev = "v15.0.0", optional = true }

[build-dependencies]
pyo3-build-config = "0.21.2"
Expand Down
2 changes: 2 additions & 0 deletions src/native/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
mod ddsketch;
#[cfg(feature = "library_config")]
mod library_config;

use pyo3::prelude::*;

#[pymodule]
fn _native(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_class::<ddsketch::DDSketchPy>()?;
#[cfg(feature = "library_config")]
m.add_class::<library_config::PyConfigurator>()?;
Ok(())
}

0 comments on commit f54495b

Please sign in to comment.