add newrelic attribute for speaker

This commit is contained in:
Brandon Thomas
2020-08-05 00:45:56 -04:00
parent 47f4f75eb5
commit 43599c2a02
2 changed files with 43 additions and 15 deletions
+22 -3
View File
@@ -26,11 +26,30 @@ impl NewRelicLogger {
}
}
pub fn web_transaction(&self, transaction_name: &str) -> Option<Transaction> {
pub fn web_transaction(&self, transaction_name: &str) -> MaybeNewRelicTransaction {
if let Some(ref newrelic_api) = self.newrelic_api {
info!("Logging request to NewRelic");
return newrelic_api.web_transaction(transaction_name).ok();
let maybe_transaction = newrelic_api.web_transaction(transaction_name).ok();
return MaybeNewRelicTransaction::from_optional(maybe_transaction);
}
None
MaybeNewRelicTransaction::from_optional(None)
}
}
pub struct MaybeNewRelicTransaction {
transaction: Option<Transaction>,
}
impl MaybeNewRelicTransaction {
pub fn from_optional(optional: Option<Transaction>) -> Self {
Self {
transaction: optional,
}
}
pub fn add_attribute(&self, name: &str, value: &str) {
if let Some(ref transaction) = self.transaction {
let _result = transaction.add_attribute(name, value);
}
}
}