-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(agent): Adds label forwarding to log events #1027
base: dev
Are you sure you want to change the base?
Conversation
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #1027 +/- ##
==========================================
+ Coverage 77.93% 77.98% +0.04%
==========================================
Files 198 198
Lines 27713 27784 +71
==========================================
+ Hits 21599 21667 +68
- Misses 6114 6117 +3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
bc18e12
to
df096d7
Compare
agent/scripts/newrelic.ini.template
Outdated
; Scope : per-directory | ||
; Default: "" | ||
; Info : A list of labels to NOT add as attributes to logs which are forwarded | ||
; to New Relic. This list can be separated by commas. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update description to state that label matching is case insensitive and multiple list elements MUST be separated by commas.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated in commit 277d034.
"common": { | ||
"attributes": { } | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For other reviewers - sending "common"
object with empty "attributes"
is an existing functionality.
axiom/tests/.gitignore
Outdated
@@ -95,7 +95,6 @@ test_segment | |||
test_segment_children | |||
test_segment_datastore | |||
test_segment_external | |||
test_segment_message |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this has been removed by a mistake during rebase.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had it in this PR, removed it, put it in #1026 and then rebased. Weird it didn't complain about a conflict - I'll look into it.
Thanks for adding the new tests_monolog_label* tests.
|
The function nr_txn_begin() now accepts a nrobj_t *log_labels parameter which contains the logging labels to be associated with log events.
- added PHP5 tests - these are not for PHP 5 but are intended to run on PHP5+!
df096d7
to
c9bea37
Compare
Co-authored-by: Michal Nowacki <[email protected]>
bool exclude = false; | ||
nr_status_t rv; | ||
|
||
exclude = nro_get_hash_boolean(exclude_labels_hash, lower_key, &rv); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exclude
is set as a bool, but nro_get_hash_boolean
returns an int
, not a bool.
int nro_get_hash_boolean(const nrobj_t* obj,
const char* key,
nr_status_t* errp)
It returns -1 on failure/error cases and 0/1 to indicate a setting of false/true.
Consider saving some steps/checks and removing the need for a rv by taking advantage of the int return value.
It could then be simplified a bit, so that instead of:
bool exclude = false;
nr_status_t rv;
exclude = nro_get_hash_boolean(exclude_labels_hash, lower_key, &rv);
if (NR_SUCCESS != rv) {
exclude = false;
}
if (!exclude) {
nro_set_hash_string(log_labels, key, value);
} else {
nrl_verbosedebug(NRL_TXN, "%s: Excluding label %s", __FUNCTION__, key);
}
It could simplified to be:
if (nro_get_hash_boolean(exclude_labels_hash, lower_key, NULL) != 1) {
nro_set_hash_string(log_labels, key, value);
} else {
nrl_verbosedebug(NRL_TXN, "%s: Excluding label %s", __FUNCTION__, NRSAFESTR(key));
}
if (!exclude) { | ||
nro_set_hash_string(log_labels, key, value); | ||
} else { | ||
nrl_verbosedebug(NRL_TXN, "%s: Excluding label %s", __FUNCTION__, key); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Key was not checked for NULL, this could generate a segfault. Check for NULL earlier, and/or wrap in NRSAFESTR.
*/ | ||
log_labels = nro_new(NR_OBJECT_HASH); | ||
for (int i = 0; i < nro_getsize(label_keys); i++) { | ||
const char* key = nro_get_array_string(label_keys, i + 1, NULL); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A NULL check for the key could help skip this round of the loop.
exclude = false; | ||
} | ||
if (!exclude) { | ||
nro_set_hash_string(log_labels, key, value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also would be a useless call if passing in a NULL key.
__FUNCTION__); | ||
return NULL; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A check if log_forwarding_labels_exclude
is an empty string (most common case) would allow an early exit from the function.
events := NewLogEvents(10) | ||
id := AgentRunID(`12345`) | ||
log_data := []byte(`{"message":"test log event"}`) | ||
label_data := []byte(`[{"label_type":"type1","label_value":"value1"},{"label_type":"type2","label_value":"value2"}]`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add a test where label name has spaces?
@@ -118,7 +118,8 @@ table Transaction { | |||
sampling_priority: double; // added in the 8.2 PHP agent release | |||
span_events: [Event]; | |||
log_events: [Event]; // added in the 10.1 PHP agent release | |||
php_packages: Event; // added in the ??? PHP agent release | |||
php_packages: Event; // added in the 10.17 PHP agent release | |||
log_forwarding_labels: Event; // added in the ??? PHP agent release |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can go ahead and put 11.7 in there instead of ???
This PR adds the ability for labels to be forwarded with any log messages forwarded by the PHP agent.