Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace log with tracing, instrument conversion functions #150

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
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
109 changes: 104 additions & 5 deletions Cargo.lock

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

66 changes: 66 additions & 0 deletions thirdparty_rust.yaml

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion vl-convert-python/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ lazy_static = "1.4.0"
futures = "0.3.28"
pythonize = "0.20.0"
tokio = { version= "1.32" }

tracing = "0.1"
tracing-subscriber = { version="0.3", features = ["env-filter"] }
23 changes: 19 additions & 4 deletions vl-convert-python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use pyo3::types::{PyBytes, PyDict};
use pythonize::{depythonize, pythonize};
use std::str::FromStr;
use std::sync::Mutex;
use tracing_subscriber::{fmt, fmt::format::FmtSpan, prelude::*, EnvFilter};
use vl_convert_rs::converter::{FormatLocale, Renderer, TimeFormatLocale, VgOpts, VlOpts};
use vl_convert_rs::html::bundle_vega_snippet;
use vl_convert_rs::module_loader::import_map::VlVersion;
Expand Down Expand Up @@ -139,6 +140,7 @@ fn vega_to_svg(
/// time_format_locale (str | dict): d3-time-format locale name or dictionary
/// Returns:
/// dict: scenegraph
#[tracing::instrument(skip_all, name = "py_vega_to_scenegraph")]
#[pyfunction]
#[pyo3(text_signature = "(vg_spec, allowed_base_urls, format_locale, time_format_locale)")]
fn vega_to_scenegraph(
Expand Down Expand Up @@ -171,8 +173,11 @@ fn vega_to_scenegraph(
)))
}
};
Python::with_gil(|py| -> PyResult<PyObject> {
pythonize(py, &sg).map_err(|err| PyValueError::new_err(err.to_string()))
let span = tracing::info_span!("pythonize");
span.in_scope(|| {
Python::with_gil(|py| -> PyResult<PyObject> {
pythonize(py, &sg).map_err(|err| PyValueError::new_err(err.to_string()))
})
})
}

Expand Down Expand Up @@ -260,6 +265,7 @@ fn vegalite_to_svg(
/// time_format_locale (str | dict): d3-time-format locale name or dictionary
/// Returns:
/// str: SVG image string
#[tracing::instrument(skip_all, name = "py_vegalite_to_scenegraph")]
#[pyfunction]
#[pyo3(
text_signature = "(vl_spec, vl_version, config, theme, show_warnings, allowed_base_urls, format_locale, time_format_locale)"
Expand Down Expand Up @@ -309,8 +315,11 @@ fn vegalite_to_scenegraph(
)))
}
};
Python::with_gil(|py| -> PyResult<PyObject> {
pythonize(py, &sg).map_err(|err| PyValueError::new_err(err.to_string()))
let span = tracing::info_span!("pythonize");
span.in_scope(|| {
Python::with_gil(|py| -> PyResult<PyObject> {
pythonize(py, &sg).map_err(|err| PyValueError::new_err(err.to_string()))
})
})
}

Expand Down Expand Up @@ -1139,6 +1148,12 @@ fn javascript_bundle(snippet: Option<String>, vl_version: Option<&str>) -> PyRes
/// Convert Vega-Lite specifications to other formats
#[pymodule]
fn vl_convert(_py: Python, m: &PyModule) -> PyResult<()> {
// Initialize logging controlled by RUST_LOG environment variable
tracing_subscriber::registry()
.with(fmt::layer().with_span_events(FmtSpan::CLOSE))
.with(EnvFilter::from_default_env())
.init();

m.add_function(wrap_pyfunction!(vegalite_to_vega, m)?)?;
m.add_function(wrap_pyfunction!(vegalite_to_svg, m)?)?;
m.add_function(wrap_pyfunction!(vegalite_to_scenegraph, m)?)?;
Expand Down
Loading
Loading