Skip to content

Commit 9e20b93

Browse files
committed
feat(axiom): Update datastore handling to support DynamoDb
* add db.system * modify datastore to allow for datastore that don't have concept of database name
1 parent 0e666b9 commit 9e20b93

10 files changed

+51
-7
lines changed

axiom/nr_datastore.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ typedef enum {
3232
NR_DATASTORE_SYBASE,
3333
NR_DATASTORE_INFORMIX,
3434
NR_DATASTORE_PDO,
35+
NR_DATASTORE_DYNAMODB,
3536
NR_DATASTORE_MUST_BE_LAST
3637
} nr_datastore_t;
3738

axiom/nr_datastore_private.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ static const nr_datastore_mapping_t datastore_mappings[] = {
3232
{NR_DATASTORE_SYBASE, "Sybase", "sybase", 1},
3333
{NR_DATASTORE_INFORMIX, "Informix", "informix", 1},
3434
{NR_DATASTORE_PDO, "PDO", "pdo", 0},
35+
{NR_DATASTORE_DYNAMODB, "DynamoDB", "dynamodb", 0},
3536
{NR_DATASTORE_MUST_BE_LAST, NULL, NULL, 0},
3637
};
3738
static size_t datastore_mappings_len

axiom/nr_segment.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,9 @@ static void nr_populate_datastore_spans(nr_span_event_t* span_event,
262262
nr_span_event_set_datastore(span_event, NR_SPAN_DATASTORE_COMPONENT,
263263
component);
264264

265+
nr_span_event_set_datastore(span_event, NR_SPAN_DATASTORE_DB_SYSTEM,
266+
segment->typed_attributes->datastore.db_system);
267+
265268
host = segment->typed_attributes->datastore.instance.host;
266269
nr_span_event_set_datastore(span_event, NR_SPAN_DATASTORE_PEER_HOSTNAME,
267270
host);
@@ -595,6 +598,7 @@ bool nr_segment_set_datastore(nr_segment_t* segment,
595598
.input_query_json = datastore->input_query_json ? nr_strdup(datastore->input_query_json) : NULL,
596599
.backtrace_json = datastore->backtrace_json ? nr_strdup(datastore->backtrace_json) : NULL,
597600
.explain_plan_json = datastore->explain_plan_json ? nr_strdup(datastore->explain_plan_json) : NULL,
601+
.db_system = datastore->db_system ? nr_strdup(datastore->db_system) : NULL,
598602
};
599603

600604
segment->typed_attributes->datastore.instance = (nr_datastore_instance_t){

axiom/nr_segment.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ typedef struct _nr_segment_datastore_t {
9999
char* input_query_json;
100100
char* backtrace_json;
101101
char* explain_plan_json;
102+
char* db_system;
102103
nr_datastore_instance_t instance;
103104
} nr_segment_datastore_t;
104105

axiom/nr_segment_datastore.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
static char* create_metrics(nr_segment_t* segment,
1616
nrtime_t duration,
1717
const char* product,
18+
nr_datastore_t type,
1819
const char* collection,
1920
const char* operation,
2021
nr_segment_datastore_t* datastore,
@@ -59,12 +60,23 @@ static char* create_metrics(nr_segment_t* segment,
5960
}
6061

6162
if (txn->options.database_name_reporting_enabled) {
62-
nr_datastore_instance_set_database_name(&datastore->instance,
63-
instance->database_name);
63+
/*
64+
* According the agent-specs Datastore-Metrics-PORTED.md:
65+
* There are datastores that do not have the notion of a database name and
66+
* they are exempt from collecting it. The following list recognizes
67+
* datastores for which a database name is not applicable. DynamoDb is one
68+
* such case and as such the db.instance attribute should not be set.
69+
*/
70+
71+
if (NR_DATASTORE_DYNAMODB != type) {
72+
nr_datastore_instance_set_database_name(&datastore->instance,
73+
instance->database_name);
74+
}
6475
}
6576

6677
instance_metric = nr_formatf("Datastore/instance/%s/%s/%s", product,
6778
instance->host, instance->port_path_or_id);
79+
6880
nr_segment_add_metric(segment, instance_metric, false);
6981
nr_datastore_instance_set_host(&datastore->instance, instance->host);
7082
nr_datastore_instance_set_port_path_or_id(&datastore->instance,
@@ -208,9 +220,9 @@ bool nr_segment_datastore_end(nr_segment_t** segment_ptr,
208220
* The allWeb and allOther rollup metrics are created at the end of the
209221
* transaction since the background status may change.
210222
*/
211-
scoped_metric
212-
= create_metrics(segment, duration, datastore_string, collection,
213-
operation, &datastore, params->instance);
223+
scoped_metric = create_metrics(segment, duration, datastore_string,
224+
params->datastore.type, collection, operation,
225+
&datastore, params->instance);
214226

215227
nr_segment_set_name(segment, scoped_metric);
216228

@@ -256,8 +268,8 @@ bool nr_segment_datastore_end(nr_segment_t** segment_ptr,
256268
break;
257269
}
258270
}
259-
260271
datastore.component = nr_strdup(datastore_string);
272+
datastore.db_system = params->db_system;
261273

262274
if (input_query) {
263275
nrobj_t* obj = nro_new_hash();

axiom/nr_segment_datastore.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ typedef struct _nr_segment_datastore_params_t {
2222
extracted from the SQL for SQL segments. */
2323
char* operation; /* The null-terminated operation; if NULL, this will be
2424
extracted from the SQL for SQL segments. */
25+
char* db_system; /* Database management system (DBMS) product being used.*/
2526
nr_datastore_instance_t*
2627
instance; /* Any instance information that was collected. */
2728

axiom/nr_segment_private.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ void nr_segment_datastore_destroy_fields(nr_segment_datastore_t* datastore) {
2323
nr_free(datastore->input_query_json);
2424
nr_free(datastore->backtrace_json);
2525
nr_free(datastore->explain_plan_json);
26+
nr_free(datastore->db_system);
2627
nr_free(datastore->instance.host);
2728
nr_free(datastore->instance.port_path_or_id);
2829
nr_free(datastore->instance.database_name);

axiom/nr_span_event.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,9 @@ void nr_span_event_set_datastore(nr_span_event_t* event,
312312
case NR_SPAN_DATASTORE_COMPONENT:
313313
nro_set_hash_string(event->intrinsics, "component", new_value);
314314
break;
315+
case NR_SPAN_DATASTORE_DB_SYSTEM:
316+
nro_set_hash_string(event->agent_attributes, "db.system", new_value);
317+
break;
315318
case NR_SPAN_DATASTORE_DB_STATEMENT:
316319
nro_set_hash_string(event->agent_attributes, "db.statement", new_value);
317320
break;
@@ -525,6 +528,8 @@ const char* nr_span_event_get_datastore(
525528
switch (member) {
526529
case NR_SPAN_DATASTORE_COMPONENT:
527530
return nro_get_hash_string(event->intrinsics, "component", NULL);
531+
case NR_SPAN_DATASTORE_DB_SYSTEM:
532+
return nro_get_hash_string(event->agent_attributes, "db.system", NULL);
528533
case NR_SPAN_DATASTORE_DB_STATEMENT:
529534
return nro_get_hash_string(event->agent_attributes, "db.statement", NULL);
530535
case NR_SPAN_DATASTORE_DB_INSTANCE:

axiom/nr_span_event.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ typedef enum {
6767
NR_SPAN_DATASTORE_DB_STATEMENT,
6868
NR_SPAN_DATASTORE_DB_INSTANCE,
6969
NR_SPAN_DATASTORE_PEER_ADDRESS,
70-
NR_SPAN_DATASTORE_PEER_HOSTNAME
70+
NR_SPAN_DATASTORE_PEER_HOSTNAME,
71+
NR_SPAN_DATASTORE_DB_SYSTEM
7172
} nr_span_event_datastore_member_t;
7273

7374
/*

axiom/tests/test_span_event.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,23 @@ static void test_span_event_datastore_string_get_and_set(void) {
432432
"set db_statement to rabbit", "rabbit",
433433
nr_span_event_get_datastore(event, NR_SPAN_DATASTORE_PEER_HOSTNAME));
434434

435+
// Test : setting and getting db.system
436+
tlib_pass_if_null(
437+
"if unset, the db.system should be NULL",
438+
nr_span_event_get_datastore(event, NR_SPAN_DATASTORE_DB_SYSTEM));
439+
nr_span_event_set_datastore(event, NR_SPAN_DATASTORE_DB_SYSTEM, NULL);
440+
tlib_pass_if_null(
441+
"if passed NULL, the db.system should be NULL",
442+
nr_span_event_get_datastore(event, NR_SPAN_DATASTORE_DB_SYSTEM));
443+
nr_span_event_set_datastore(event, NR_SPAN_DATASTORE_DB_SYSTEM, "wombat");
444+
tlib_pass_if_str_equal(
445+
"set db.system to wombat", "wombat",
446+
nr_span_event_get_datastore(event, NR_SPAN_DATASTORE_DB_SYSTEM));
447+
nr_span_event_set_datastore(event, NR_SPAN_DATASTORE_DB_SYSTEM, "rabbit");
448+
tlib_pass_if_str_equal(
449+
"set db.system to rabbit", "rabbit",
450+
nr_span_event_get_datastore(event, NR_SPAN_DATASTORE_DB_SYSTEM));
451+
435452
nr_span_event_destroy(&event);
436453
}
437454

0 commit comments

Comments
 (0)