-
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 27785 +72
==========================================
+ Hits 21599 21669 +70
- Misses 6114 6116 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
bc18e12
to
df096d7
Compare
"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.
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.
df096d7
to
c9bea37
Compare
Co-authored-by: Michal Nowacki <[email protected]>
agent/php_txn.c
Outdated
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.
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.
__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.
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.
If the exclude rule is empty we need to copy all the labels into the log labels structure so I don't see how we could exit early.
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.
Why do we need to copy all the log labels if there are no excludes?
We know that we want to include everything, so if the exclude list is the an empty string, couldn't we just could exit early here and return labels
?
agent/php_txn.c
Outdated
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); | ||
const char* value = nro_get_hash_string(labels, key, 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.
The value is not needed until it is certain the label has not been filtered out. If it is filtered out, there's no need to retrieve it.
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.
Thank you for this observation - I've incorporated this into 90955f0
const nr_attribute_config_t* attribute_config, | ||
const nrobj_t* log_forwarding_labels); |
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.
These two arguments are not documented by doc string. I don't know if this is something we care about or not.
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.
Good point - I addressed this omission with 7a02270
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.
Looks good considering all limitations of agent<->daemon/integration_runner design.
Takes advantage of return value from nrp_get_hash_boolean() being -1 if the key lookup did not suceed to simplify this section of code. Also is smarter about retrieving data until it is known it is needed.
Checks if log forwarding is disabled then log forwarding labels is also disabled, even if the log forwarding labels config is set to true.
I think commit 65f9ba2 will address your points 1 and 3 above. I did run the integration tests (no multiverse tests for log labels (yet)) with valgrind. A couple of CLM related tests passed valgrind but failed because an additional span ("name": "Custom/Monolog\Logger::pushHandler") was detected. I'm suspecting this is because it ran slower with valgrind than w/o so it was included whereas it is not when valgrind is not used? |
Awesome, thank you! |
This PR adds the ability for labels to be forwarded with any log messages forwarded by the PHP agent.