Skip to content

Commit

Permalink
Merge pull request #4 from ebesirik/main
Browse files Browse the repository at this point in the history
Update service configuration to include server name parameter
  • Loading branch information
twitchax authored Feb 1, 2025
2 parents 84d2909 + 310ae3c commit a4547d3
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
//! // Accepts an optional connection string. If None, then no telemetry is sent.
//! .with_connection_string(None)
//! // Sets the service namespace and name. Default is empty.
//! .with_service_config("namespace", "name")
//! .with_service_config("namespace", "name", "servername")
//! // Sets the HTTP client to use for sending telemetry. Default is reqwest async client.
//! .with_client(reqwest::Client::new())
//! // Sets whether or not live metrics are collected. Default is false.
Expand Down Expand Up @@ -189,7 +189,7 @@ pub mod exports {
///
/// let telemetry_layer = AppInsights::default()
/// .with_connection_string(None)
/// .with_service_config("namespace", "name")
/// .with_service_config("namespace", "name", "servername")
/// .with_error_type::<WebError>()
/// .build_and_set_global_default()
/// .unwrap()
Expand Down Expand Up @@ -328,14 +328,16 @@ impl<C, R, U, P, E> AppInsights<WithConnectionString, C, R, U, P, E> {
///
/// let i: AppInsights<Ready> = AppInsights::default()
/// .with_connection_string(None)
/// .with_service_config("namespace", "name");
/// .with_service_config("namespace", "name", "servername");
/// ```
///
/// This is a convenience method for [`AppInsights::with_trace_config`].
pub fn with_service_config(self, namespace: impl AsRef<str>, name: impl AsRef<str>) -> AppInsights<Ready, C, R, U, P> {
pub fn with_service_config(self, namespace: impl AsRef<str>, name: impl AsRef<str>, servername: impl AsRef<str>) -> AppInsights<Ready, C, R, U, P> {
let config = Config::default().with_resource(opentelemetry_sdk::Resource::new(vec![
KeyValue::new("service.namespace", namespace.as_ref().to_owned()),
KeyValue::new("service.name", name.as_ref().to_owned()),
// KeyValue::new("ai.cloud.roleInstance", server_name.clone()), // Azure-specific resource attribute
KeyValue::new("service.instance.id", servername.as_ref().to_owned()), // General OpenTelemetry attribute
]));

AppInsights {
Expand Down Expand Up @@ -396,7 +398,7 @@ impl<C, R, U, P, E> AppInsights<Ready, C, R, U, P, E> {
///
/// let i: AppInsights<Ready> = AppInsights::default()
/// .with_connection_string(None)
/// .with_service_config("namespace", "name")
/// .with_service_config("namespace", "name", "servername")
/// .with_client(reqwest::Client::new());
/// ```
pub fn with_client(self, client: C) -> AppInsights<Ready, C, R, U, P, E> {
Expand Down Expand Up @@ -426,7 +428,7 @@ impl<C, R, U, P, E> AppInsights<Ready, C, R, U, P, E> {
///
/// let i: AppInsights<Ready> = AppInsights::default()
/// .with_connection_string(None)
/// .with_service_config("namespace", "name")
/// .with_service_config("namespace", "name", "servername")
/// .with_client(reqwest::Client::new())
/// .with_live_metrics(true);
/// ```
Expand Down Expand Up @@ -457,7 +459,7 @@ impl<C, R, U, P, E> AppInsights<Ready, C, R, U, P, E> {
///
/// let i: AppInsights<Ready> = AppInsights::default()
/// .with_connection_string(None)
/// .with_service_config("namespace", "name")
/// .with_service_config("namespace", "name", "servername")
/// .with_sample_rate(1.0);
/// ```
pub fn with_sample_rate(self, sample_rate: f64) -> AppInsights<Ready, C, R, U, P, E> {
Expand Down Expand Up @@ -488,7 +490,7 @@ impl<C, R, U, P, E> AppInsights<Ready, C, R, U, P, E> {
///
/// let i: AppInsights<Ready> = AppInsights::default()
/// .with_connection_string(None)
/// .with_service_config("namespace", "name")
/// .with_service_config("namespace", "name", "servername")
/// .with_minimum_level(LevelFilter::INFO);
/// ```
pub fn with_minimum_level(self, minimum_level: LevelFilter) -> AppInsights<Ready, C, R, U, P, E> {
Expand Down Expand Up @@ -519,7 +521,7 @@ impl<C, R, U, P, E> AppInsights<Ready, C, R, U, P, E> {
///
/// let i = AppInsights::default()
/// .with_connection_string(None)
/// .with_service_config("namespace", "name")
/// .with_service_config("namespace", "name", "servername")
/// .with_subscriber(tracing_subscriber::registry());
/// ```
pub fn with_subscriber<T>(self, subscriber: T) -> AppInsights<Ready, C, R, T, P, E> {
Expand Down Expand Up @@ -550,7 +552,7 @@ impl<C, R, U, P, E> AppInsights<Ready, C, R, U, P, E> {
///
/// let i: AppInsights<Ready> = AppInsights::default()
/// .with_connection_string(None)
/// .with_service_config("namespace", "name")
/// .with_service_config("namespace", "name", "servername")
/// .with_runtime(Tokio);
/// ```
pub fn with_runtime<T>(self, runtime: T) -> AppInsights<Ready, C, T, U, P, E>
Expand Down Expand Up @@ -583,7 +585,7 @@ impl<C, R, U, P, E> AppInsights<Ready, C, R, U, P, E> {
///
/// let i: AppInsights<Ready> = AppInsights::default()
/// .with_connection_string(None)
/// .with_service_config("namespace", "name")
/// .with_service_config("namespace", "name", "servername")
/// .with_catch_panic(true);
/// ```
pub fn with_catch_panic(self, should_catch_panic: bool) -> AppInsights<Ready, C, R, U, P, E> {
Expand Down Expand Up @@ -616,7 +618,7 @@ impl<C, R, U, P, E> AppInsights<Ready, C, R, U, P, E> {
///
/// let i = AppInsights::default()
/// .with_connection_string(None)
/// .with_service_config("namespace", "name")
/// .with_service_config("namespace", "name", "servername")
/// .with_noop(true);
/// ```
pub fn with_noop(self, should_noop: bool) -> AppInsights<Ready, C, R, U, P, E> {
Expand Down Expand Up @@ -647,7 +649,7 @@ impl<C, R, U, P, E> AppInsights<Ready, C, R, U, P, E> {
///
/// let i: AppInsights<Ready> = AppInsights::default()
/// .with_connection_string(None)
/// .with_service_config("namespace", "name")
/// .with_service_config("namespace", "name", "servername")
/// .with_field_mapper(|parts| {
/// let mut map = HashMap::new();
/// map.insert("extra_field".to_owned(), "extra_value".to_owned());
Expand Down Expand Up @@ -688,7 +690,7 @@ impl<C, R, U, P, E> AppInsights<Ready, C, R, U, P, E> {
///
/// let i = AppInsights::default()
/// .with_connection_string(None)
/// .with_service_config("namespace", "name")
/// .with_service_config("namespace", "name", "servername")
/// .with_panic_mapper(|panic| {
/// (500, WebError { message: panic })
/// });
Expand Down Expand Up @@ -727,7 +729,7 @@ impl<C, R, U, P, E> AppInsights<Ready, C, R, U, P, E> {
///
/// let i = AppInsights::default()
/// .with_connection_string(None)
/// .with_service_config("namespace", "name")
/// .with_service_config("namespace", "name", "servername")
/// .with_success_filter(|status| {
/// status.is_success() || status.is_redirection() || status.is_informational() || status == StatusCode::NOT_FOUND
/// });
Expand Down Expand Up @@ -776,7 +778,7 @@ impl<C, R, U, P, E> AppInsights<Ready, C, R, U, P, E> {
///
/// let i = AppInsights::default()
/// .with_connection_string(None)
/// .with_service_config("namespace", "name")
/// .with_service_config("namespace", "name", "servername")
/// .with_error_type::<WebError>();
/// ```
pub fn with_error_type<T>(self) -> AppInsights<Ready, C, R, U, P, T> {
Expand Down Expand Up @@ -806,7 +808,7 @@ impl<C, R, U, P, E> AppInsights<Ready, C, R, U, P, E> {
///
/// let i: AppInsightsComplete<_, _> = AppInsights::default()
/// .with_connection_string(None)
/// .with_service_config("namespace", "name")
/// .with_service_config("namespace", "name", "servername")
/// .build_and_set_global_default()
/// .unwrap();
/// ```
Expand Down Expand Up @@ -908,7 +910,7 @@ impl<P, E> AppInsightsComplete<P, E> {
///
/// let i: AppInsightsComplete<_, _> = AppInsights::default()
/// .with_connection_string(None)
/// .with_service_config("namespace", "name")
/// .with_service_config("namespace", "name", "servername")
/// .build_and_set_global_default()
/// .unwrap();
///
Expand Down Expand Up @@ -1204,7 +1206,7 @@ mod tests {

let i = AppInsights::default()
.with_connection_string(None)
.with_service_config("namespace", "name")
.with_service_config("namespace", "name", "servername")
.with_client(reqwest::Client::new())
.with_sample_rate(1.0)
.with_minimum_level(LevelFilter::INFO)
Expand Down Expand Up @@ -1307,7 +1309,7 @@ mod tests {

let i = AppInsights::default()
.with_connection_string(None)
.with_service_config("namespace", "name")
.with_service_config("namespace", "name", "servername")
.with_subscriber(subscriber)
.with_noop(true)
.build_and_set_global_default()
Expand Down

0 comments on commit a4547d3

Please sign in to comment.