Skip to content

Commit

Permalink
Merge pull request #8 from MadLittleMods/madlittlemods/configurable-h…
Browse files Browse the repository at this point in the history
…ost-port

Make host and port configurable
  • Loading branch information
erikjohnston authored Sep 1, 2022
2 parents 27754b5 + 0473f49 commit 7e92385
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#
Expand All @@ -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
--------
Expand Down
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ requires = ["maturin>=0.12,<0.13"]
build-backend = "maturin"

[tool.maturin]
sdist-include = ["Cargo.lock"]
sdist-include = ["Cargo.lock"]

# Optional Dependencies
# ---------------------
objgraph = { version = ">=3.5.0", optional = true }
22 changes: 19 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl Stats {

/// The main reporter class.
#[pyclass]
#[pyo3(text_signature = "()")]
#[pyo3(text_signature = "(config, /)")]
struct Reporter {
span_sender: Sender<thrift_gen::jaeger::Span>,
process_sender: Sender<thrift_gen::jaeger::Process>,
Expand All @@ -80,14 +80,30 @@ struct Reporter {
#[pymethods]
impl Reporter {
#[new]
fn new() -> PyResult<Reporter> {
fn new(config: Option<&PyDict>) -> PyResult<Reporter> {
let mut agent_host_name: String = "127.0.0.1".to_string();
let mut agent_port: i32 = 6831;

if let Some(config) = config {
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(
&(49152..65535)
.map(|port| SocketAddr::from(([127, 0, 0, 1], port)))
.collect::<Vec<_>>()[..],
)?;
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());
Expand Down
2 changes: 1 addition & 1 deletion test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 7e92385

Please sign in to comment.