1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
use crate::acko_segment::Segment;
use crate::nr_init::NR_APP;
use crate::transaction::Transaction;
use std::cell::RefCell;
use crate::nr_init::ENABLE_NEW_RELIC;
use newrelic_sys as ffi;
use std::ptr::null_mut;
thread_local! {
pub static TL_TRANSACTION: RefCell<Transaction> = RefCell::new(NR_APP
.web_transaction("init")
.expect("Could not start transaction"));
}
pub fn nr_start_web_transaction(name: &str) -> () {
if *ENABLE_NEW_RELIC {
TL_TRANSACTION.with(|tr| {
let transaction = NR_APP
.web_transaction(name)
.expect("Could not start transaction");
*tr.borrow_mut() = transaction;
});
}
}
pub fn nr_end_transaction() {
if *ENABLE_NEW_RELIC {
TL_TRANSACTION.with(|tr| {
tr.borrow_mut().end();
});
}
}
pub fn nr_start_custom_segment(name: &str) -> Segment {
if *ENABLE_NEW_RELIC {
let seg = TL_TRANSACTION.with(|tr| {
let t = tr.borrow_mut();
Segment::start_custom_segment(&t, name)
});
seg
} else {
let inner: *mut ffi::newrelic_segment_t = null_mut();
Segment { inner }
}
}
pub fn nr_end_custom_segment(segment: Segment) {
if *ENABLE_NEW_RELIC {
TL_TRANSACTION.with(|tr| {
let t = tr.borrow_mut();
segment.end_segment(&t);
});
}
}