-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNewRelic-Infrastructure-Example.c
48 lines (38 loc) · 1.31 KB
/
NewRelic-Infrastructure-Example.c
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
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
/*
* A standalone example that demonstrates to users how to
* configure logging, configure an app, connect an app,
* start a transaction and a segment, and cleanly destroy
* everything.
*/
#include "libnewrelic.h"
int main(void) {
newrelic_app_t* app;
newrelic_txn_t* txn;
newrelic_app_config_t* config;
newrelic_segment_t* seg;
config = newrelic_create_app_config("COSINE-MUD-BOX-Unity-Infrastructure", "076331d54eac003434ef74dc8287cf71e074NRAL");
if (!newrelic_configure_log("./c_sdk.log", NEWRELIC_LOG_INFO)) {
printf("Error configuring logging.\n");
return -1;
}
if (!newrelic_init(NULL, 0)) {
printf("Error connecting to daemon.\n");
return -1;
}
/* Wait up to 10 seconds for the SDK to connect to the daemon */
app = newrelic_create_app(config, 10000);
newrelic_destroy_app_config(&config);
/* Start a web transaction and a segment */
txn = newrelic_start_web_transaction(app, "Transaction name");
seg = newrelic_start_segment(txn, "Segment name", "Custom");
/* Interesting application code happens here */
sleep(2);
/* End the segment and web transaction */
newrelic_end_segment(txn, &seg);
newrelic_end_transaction(&txn);
newrelic_destroy_app(&app);
return 0;
}