Skip to content

Commit 7e92385

Browse files
authored
Merge pull request #8 from MadLittleMods/madlittlemods/configurable-host-port
Make host and port configurable
2 parents 27754b5 + 0473f49 commit 7e92385

File tree

4 files changed

+26
-12
lines changed

4 files changed

+26
-12
lines changed

README.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ config = Config(
2828
)
2929

3030
# Create the rust reporter.
31-
reporter = Reporter()
31+
reporter = Reporter(config={"agent_host_name": "127.0.0.1", "agent_port": 6831})
3232

3333
# Create the tracer and install it as the global tracer.
3434
#
@@ -38,12 +38,6 @@ opentracing.set_global_tracer(tracer)
3838

3939
```
4040

41-
Limitations
42-
-----------
43-
44-
The reporter is not configurable and is hardcoded to report to the local agent
45-
on localhost and the default port.
46-
4741

4842
Building
4943
--------

pyproject.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,8 @@ requires = ["maturin>=0.12,<0.13"]
33
build-backend = "maturin"
44

55
[tool.maturin]
6-
sdist-include = ["Cargo.lock"]
6+
sdist-include = ["Cargo.lock"]
7+
8+
# Optional Dependencies
9+
# ---------------------
10+
objgraph = { version = ">=3.5.0", optional = true }

src/lib.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl Stats {
6767

6868
/// The main reporter class.
6969
#[pyclass]
70-
#[pyo3(text_signature = "()")]
70+
#[pyo3(text_signature = "(config, /)")]
7171
struct Reporter {
7272
span_sender: Sender<thrift_gen::jaeger::Span>,
7373
process_sender: Sender<thrift_gen::jaeger::Process>,
@@ -80,14 +80,30 @@ struct Reporter {
8080
#[pymethods]
8181
impl Reporter {
8282
#[new]
83-
fn new() -> PyResult<Reporter> {
83+
fn new(config: Option<&PyDict>) -> PyResult<Reporter> {
84+
let mut agent_host_name: String = "127.0.0.1".to_string();
85+
let mut agent_port: i32 = 6831;
86+
87+
if let Some(config) = config {
88+
if let Some(agent_host_name_arg) = config.get_item("agent_host_name") {
89+
agent_host_name = agent_host_name_arg.extract().map_err(|_| {
90+
pyo3::exceptions::PyTypeError::new_err("'agent_host_name' must be an string")
91+
})?;
92+
}
93+
94+
if let Some(agent_port_arg) = config.get_item("agent_port") {
95+
agent_port = agent_port_arg.extract().map_err(|_| {
96+
pyo3::exceptions::PyTypeError::new_err("'agent_port' must be an int")
97+
})?;
98+
}
99+
}
84100
// Set up the UDP transport
85101
let socket = UdpSocket::bind(
86102
&(49152..65535)
87103
.map(|port| SocketAddr::from(([127, 0, 0, 1], port)))
88104
.collect::<Vec<_>>()[..],
89105
)?;
90-
socket.connect("127.0.0.1:6831")?;
106+
socket.connect(format!("{}:{}", agent_host_name, agent_port))?;
91107

92108
// We never read anything so this can be a no-op input protocol
93109
let input_protocol = TCompactInputProtocol::new(empty());

test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
},
3232
# 'logging': True,
3333
},
34-
service_name="your-app-name",
34+
service_name="rust-jaeger-python-client-test",
3535
)
3636

3737
tracer = config.create_tracer(reporter, config.sampler)

0 commit comments

Comments
 (0)