From 99a0493e8b1a80ef3a99a87323c2baff34bdcbda Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Wed, 17 Aug 2022 00:12:42 -0500 Subject: [PATCH 1/4] Make host and port configurable --- pyproject.toml | 6 +++++- src/lib.rs | 25 ++++++++++++++++++++++--- test.py | 2 +- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index ff1ff55..c4d0700 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,4 +3,8 @@ requires = ["maturin>=0.12,<0.13"] build-backend = "maturin" [tool.maturin] -sdist-include = ["Cargo.lock"] \ No newline at end of file +sdist-include = ["Cargo.lock"] + +# Optional Dependencies +# --------------------- +objgraph = { version = ">=3.5.0", optional = true } diff --git a/src/lib.rs b/src/lib.rs index a8e7190..5e85e5e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -67,7 +67,7 @@ impl Stats { /// The main reporter class. #[pyclass] -#[pyo3(text_signature = "()")] +#[pyo3(text_signature = "(config, /)")] struct Reporter { span_sender: Sender, process_sender: Sender, @@ -80,14 +80,33 @@ struct Reporter { #[pymethods] impl Reporter { #[new] - fn new() -> PyResult { + fn new(config: Option<&PyDict>) -> PyResult { + let mut agent_host_name: String = "127.0.0.1".to_string(); + let mut agent_port: i32 = 6831; + + if let Some(config) = config { + agent_host_name = config + .get_item("agent_host_name") + .unwrap() + .extract() + .unwrap_or("127.0.0.1".to_string()); + agent_port = config + .get_item("agent_port") + .unwrap() + .extract() + .unwrap_or(6831); + } + println!( + "config agent_host_name={} config.agent_port={}", + agent_host_name, agent_port + ); // Set up the UDP transport let socket = UdpSocket::bind( &(49152..65535) .map(|port| SocketAddr::from(([127, 0, 0, 1], port))) .collect::>()[..], )?; - socket.connect("127.0.0.1:6831")?; + socket.connect(format!("{}:{}", agent_host_name, agent_port))?; // We never read anything so this can be a no-op input protocol let input_protocol = TCompactInputProtocol::new(empty()); diff --git a/test.py b/test.py index f565111..9e12513 100644 --- a/test.py +++ b/test.py @@ -31,7 +31,7 @@ }, # 'logging': True, }, - service_name="your-app-name", + service_name="rust-jaeger-python-client-test", ) tracer = config.create_tracer(reporter, config.sampler) From 7de204a1102801b407eeb6612b94fb78f42e66a0 Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Wed, 17 Aug 2022 00:15:38 -0500 Subject: [PATCH 2/4] Remove debug logging --- src/lib.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 5e85e5e..35bd1b6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -96,10 +96,6 @@ impl Reporter { .extract() .unwrap_or(6831); } - println!( - "config agent_host_name={} config.agent_port={}", - agent_host_name, agent_port - ); // Set up the UDP transport let socket = UdpSocket::bind( &(49152..65535) From b3688246860d210bdb503a9dc056ef774492b65d Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Wed, 24 Aug 2022 17:19:18 -0500 Subject: [PATCH 3/4] Update docs --- README.md | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/README.md b/README.md index 0bc0179..f29acaa 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ config = Config( ) # Create the rust reporter. -reporter = Reporter() +reporter = Reporter(config={"agent_host_name": "127.0.0.1", "agent_port": 6831}) # Create the tracer and install it as the global tracer. # @@ -38,12 +38,6 @@ opentracing.set_global_tracer(tracer) ``` -Limitations ------------ - -The reporter is not configurable and is hardcoded to report to the local agent -on localhost and the default port. - Building -------- From 0473f49004caee0dc547624d8934fd37e1579d74 Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Thu, 25 Aug 2022 23:29:04 -0500 Subject: [PATCH 4/4] Use more proper way to read from config See https://github.com/erikjohnston/rust-jaeger-python-client/pull/8#discussion_r954739087 --- src/lib.rs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 35bd1b6..f0fb1c4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -85,16 +85,17 @@ impl Reporter { let mut agent_port: i32 = 6831; if let Some(config) = config { - agent_host_name = config - .get_item("agent_host_name") - .unwrap() - .extract() - .unwrap_or("127.0.0.1".to_string()); - agent_port = config - .get_item("agent_port") - .unwrap() - .extract() - .unwrap_or(6831); + if let Some(agent_host_name_arg) = config.get_item("agent_host_name") { + agent_host_name = agent_host_name_arg.extract().map_err(|_| { + pyo3::exceptions::PyTypeError::new_err("'agent_host_name' must be an string") + })?; + } + + if let Some(agent_port_arg) = config.get_item("agent_port") { + agent_port = agent_port_arg.extract().map_err(|_| { + pyo3::exceptions::PyTypeError::new_err("'agent_port' must be an int") + })?; + } } // Set up the UDP transport let socket = UdpSocket::bind(