Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Distributed tracing (spans) support, scope propagation and `SlackClie…
…nt.run_in_session` implementation (#151) * Auxiliary SlackClient.run_in_session implementation with docs and examples * Docs updates * Span/context propagation
- Loading branch information
Showing
9 changed files
with
274 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Observability and tracing | ||
|
||
The library uses popular `tracing` crate for logs and distributed traces (spans). | ||
To improve observability for your specific cases, additionally to the fields provided by library, you can inject your own trace fields: | ||
|
||
```rust,noplaypen | ||
use slack_morphism::prelude::*; | ||
use tracing::*; | ||
// While Team ID is optional but still useful for tracing and rate control purposes | ||
let token: SlackApiToken = | ||
SlackApiToken::new(token_value).with_team_id(config_env_var("SLACK_TEST_TEAM_ID")?.into()); | ||
// Sessions are lightweight and basically just a reference to client and token | ||
let my_custom_span = span!(Level::DEBUG, "My scope", my_scope_attr = "my-scope-value"); | ||
debug!("Testing tracing abilities"); | ||
client | ||
.run_in_session(&token, |session| async move { | ||
let test: SlackApiTestResponse = session | ||
.api_test(&SlackApiTestRequest::new().with_foo("Test".into())) | ||
.await?; | ||
println!("{:#?}", test); | ||
let auth_test = session.auth_test().await?; | ||
println!("{:#?}", auth_test); | ||
Ok(()) | ||
}) | ||
.instrument(my_custom_span.or_current()) | ||
.await | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use slack_morphism::prelude::*; | ||
use tracing::*; | ||
|
||
async fn test_simple_api_calls_as_predicate() -> Result<(), Box<dyn std::error::Error + Send + Sync>> | ||
{ | ||
let client = SlackClient::new(SlackClientHyperConnector::new()); | ||
let token_value: SlackApiTokenValue = config_env_var("SLACK_TEST_TOKEN")?.into(); | ||
let token: SlackApiToken = | ||
SlackApiToken::new(token_value).with_team_id(config_env_var("SLACK_TEST_TEAM_ID")?.into()); // While Team ID is optional but still useful for tracing and rate control purposes | ||
|
||
// Sessions are lightweight and basically just a reference to client and token | ||
let my_custom_span = span!(Level::DEBUG, "My scope", my_scope_attr = "my-scope-value"); | ||
debug!("Testing tracing abilities"); | ||
|
||
client | ||
.run_in_session(&token, |session| async move { | ||
let test: SlackApiTestResponse = session | ||
.api_test(&SlackApiTestRequest::new().with_foo("Test".into())) | ||
.await?; | ||
println!("{:#?}", test); | ||
|
||
let auth_test = session.auth_test().await?; | ||
println!("{:#?}", auth_test); | ||
|
||
Ok(()) | ||
}) | ||
.instrument(my_custom_span.or_current()) | ||
.await | ||
} | ||
|
||
pub fn config_env_var(name: &str) -> Result<String, String> { | ||
std::env::var(name).map_err(|e| format!("{}: {}", name, e)) | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> { | ||
let subscriber = tracing_subscriber::fmt() | ||
.with_env_filter("client_with_tracing=debug,slack_morphism=debug") | ||
.finish(); | ||
tracing::subscriber::set_global_default(subscriber)?; | ||
|
||
test_simple_api_calls_as_predicate().await?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.