12
12
#include "util_sql.h"
13
13
#include "util_logging.h"
14
14
15
- static nr_status_t create_instance_metric (nr_segment_t * segment ,
16
- const char * product ,
17
- nr_segment_datastore_t * datastore ,
18
- const nr_datastore_instance_t * instance ) {
19
- /*
20
- * If a datastore instance was provided, we need to add the relevant data to
21
- * the segment and the relavant metrics.
22
- */
23
- nrtxn_t * txn = segment -> txn ;
24
- char * instance_metric = NULL ;
25
- if (NULL == instance || 0 == txn -> options .instance_reporting_enabled ) {
26
- return NR_FAILURE ;
27
- }
28
-
29
- if (txn -> options .database_name_reporting_enabled ) {
30
- nr_datastore_instance_set_database_name (& datastore -> instance ,
31
- instance -> database_name );
32
- }
33
-
34
- instance_metric = nr_formatf ("Datastore/instance/%s/%s/%s" , product ,
35
- instance -> host , instance -> port_path_or_id );
36
- nr_segment_add_metric (segment , instance_metric , false);
37
-
38
- nr_free (instance_metric );
39
- return NR_SUCCESS ;
40
- }
41
-
42
15
static char * create_metrics (nr_segment_t * segment ,
43
16
nrtime_t duration ,
44
17
const char * product ,
@@ -51,6 +24,7 @@ static char* create_metrics(nr_segment_t* segment,
51
24
char * rollup_metric = NULL ;
52
25
char * scoped_metric = NULL ;
53
26
char * statement_metric = NULL ;
27
+ char * instance_metric = NULL ;
54
28
55
29
nrm_force_add (txn -> unscoped_metrics , "Datastore/all" , duration );
56
30
@@ -76,12 +50,28 @@ static char* create_metrics(nr_segment_t* segment,
76
50
nr_free (operation_metric );
77
51
nr_free (statement_metric );
78
52
79
- create_instance_metric (segment , product , datastore , instance );
80
- if (NULL != instance && 0 != txn -> options .instance_reporting_enabled ) {
81
- nr_datastore_instance_set_host (& datastore -> instance , instance -> host );
82
- nr_datastore_instance_set_port_path_or_id (& datastore -> instance ,
83
- instance -> port_path_or_id );
53
+ /*
54
+ * If a datastore instance was provided, we need to add the relevant data to
55
+ * the segment and the relavant metrics.
56
+ */
57
+ if (NULL == instance || 0 == txn -> options .instance_reporting_enabled ) {
58
+ return scoped_metric ;
59
+ }
60
+
61
+ if (txn -> options .database_name_reporting_enabled ) {
62
+ nr_datastore_instance_set_database_name (& datastore -> instance ,
63
+ instance -> database_name );
84
64
}
65
+
66
+ instance_metric = nr_formatf ("Datastore/instance/%s/%s/%s" , product ,
67
+ instance -> host , instance -> port_path_or_id );
68
+ nr_segment_add_metric (segment , instance_metric , false);
69
+ nr_datastore_instance_set_host (& datastore -> instance , instance -> host );
70
+ nr_datastore_instance_set_port_path_or_id (& datastore -> instance ,
71
+ instance -> port_path_or_id );
72
+
73
+ nr_free (instance_metric );
74
+
85
75
return scoped_metric ;
86
76
}
87
77
@@ -218,14 +208,10 @@ bool nr_segment_datastore_end(nr_segment_t** segment_ptr,
218
208
* The allWeb and allOther rollup metrics are created at the end of the
219
209
* transaction since the background status may change.
220
210
*/
221
- if (!params -> instance_only ) {
222
- scoped_metric
223
- = create_metrics (segment , duration , datastore_string , collection ,
224
- operation , & datastore , params -> instance );
225
- nr_segment_set_name (segment , scoped_metric );
226
- } else {
227
- create_instance_metric (segment , datastore_string , & datastore , params -> instance );
228
- }
211
+ scoped_metric
212
+ = create_metrics (segment , duration , datastore_string , collection ,
213
+ operation , & datastore , params -> instance );
214
+ nr_segment_set_name (segment , scoped_metric );
229
215
230
216
/*
231
217
* Add the explain plan, if we have one.
0 commit comments