@@ -28,7 +28,7 @@ const LOG_TAG: &str = "Pyroscope::Agent";
2828/// use pyroscope::pyroscope::PyroscopeConfig;
2929/// let config = PyroscopeConfig::new("http://localhost:8080", "my-app");
3030/// ```
31- #[ derive( Clone , Debug ) ]
31+ #[ derive( Clone , Debug , Default ) ]
3232pub struct PyroscopeConfig {
3333 /// Pyroscope Server Address
3434 pub url : String ,
@@ -40,6 +40,8 @@ pub struct PyroscopeConfig {
4040 pub sample_rate : u32 ,
4141 /// Spy Name
4242 pub spy_name : String ,
43+ /// Authentication Token
44+ pub auth_token : Option < String > ,
4345}
4446
4547impl PyroscopeConfig {
@@ -57,6 +59,7 @@ impl PyroscopeConfig {
5759 tags : HashMap :: new ( ) , // Empty tags
5860 sample_rate : 100u32 , // Default sample rate
5961 spy_name : String :: from ( "undefined" ) , // Spy Name should be set by the backend
62+ auth_token : None , // No authentication token
6063 }
6164 }
6265
@@ -73,6 +76,14 @@ impl PyroscopeConfig {
7376 Self { spy_name, ..self }
7477 }
7578
79+ /// Set the Authentication Token.
80+ pub fn auth_token ( self , auth_token : String ) -> Self {
81+ Self {
82+ auth_token : Some ( auth_token) ,
83+ ..self
84+ }
85+ }
86+
7687 /// Set the tags.
7788 ///
7889 /// # Example
@@ -143,6 +154,23 @@ impl PyroscopeAgentBuilder {
143154 Self { backend, ..self }
144155 }
145156
157+ /// Set JWT authentication token.
158+ /// This is optional. If not set, the agent will not send any authentication token.
159+ ///
160+ /// #Example
161+ /// ```ignore
162+ /// let builder = PyroscopeAgentBuilder::new("http://localhost:8080", "my-app")
163+ /// .auth_token("my-token")
164+ /// .build()
165+ /// ?;
166+ /// ```
167+ pub fn auth_token ( self , auth_token : impl AsRef < str > ) -> Self {
168+ Self {
169+ config : self . config . auth_token ( auth_token. as_ref ( ) . to_owned ( ) ) ,
170+ ..self
171+ }
172+ }
173+
146174 /// Set tags. Default is empty.
147175 ///
148176 /// # Example
0 commit comments