polkadot_node_jaeger/
config.rs

1// Copyright (C) Parity Technologies (UK) Ltd.
2// This file is part of Polkadot.
3
4// Polkadot is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// Polkadot is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with Polkadot.  If not, see <http://www.gnu.org/licenses/>.
16
17//! Polkadot Jaeger configuration.
18
19/// Configuration for the jaeger tracing.
20#[derive(Clone)]
21pub struct JaegerConfig {
22	pub(crate) node_name: String,
23	pub(crate) agent_addr: std::net::SocketAddr,
24}
25
26impl std::default::Default for JaegerConfig {
27	fn default() -> Self {
28		Self {
29			node_name: "unknown_".to_owned(),
30			agent_addr: "127.0.0.1:6831"
31				.parse()
32				.expect(r#"Static "127.0.0.1:6831" is a valid socket address string. qed"#),
33		}
34	}
35}
36
37impl JaegerConfig {
38	/// Use the builder pattern to construct a configuration.
39	pub fn builder() -> JaegerConfigBuilder {
40		JaegerConfigBuilder::default()
41	}
42}
43
44/// Jaeger configuration builder.
45#[derive(Default)]
46pub struct JaegerConfigBuilder {
47	inner: JaegerConfig,
48}
49
50impl JaegerConfigBuilder {
51	/// Set the name for this node.
52	pub fn named<S>(mut self, name: S) -> Self
53	where
54		S: AsRef<str>,
55	{
56		self.inner.node_name = name.as_ref().to_owned();
57		self
58	}
59
60	/// Set the agent address to send the collected spans to.
61	pub fn agent<U>(mut self, addr: U) -> Self
62	where
63		U: Into<std::net::SocketAddr>,
64	{
65		self.inner.agent_addr = addr.into();
66		self
67	}
68
69	/// Construct the configuration.
70	pub fn build(self) -> JaegerConfig {
71		self.inner
72	}
73}