-
Notifications
You must be signed in to change notification settings - Fork 69
feat(agent): Add RabbitMQ instrumentation using the php-amqplib library #1009
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
75 commits
Select commit
Hold shift + click to select a range
2df782f
feat(agent): Add RabbitMQ instrumentation using the php-amqplib library
zsistla 0b184ca
feat(agent): Add RabbitMQ instrumentation using the php-amqplib library
zsistla 3e7dc66
Merge branch 'feat/rabbitmq_instrumentation' of github.com:newrelic/n…
zsistla feba725
fix(agent): Typo remove AWS references
zsistla feef4be
fix(agent): typo
zsistla 761de36
feat(agent): Add additional unit test
zsistla 80be7a5
chore(agent): Clarifying comment.
zsistla b50a5d2
feat(axiom): Update message segment to handle rabbitmq
zsistla 075e297
feat(agent): Add php_amqplib basic_publish instrumentation.
zsistla f106a20
fix(axiom): Handle final metrix/txn naming when publish_name exists.
zsistla 631ae54
feat(agent): Add php_libamqp basic_get instrumentation.
zsistla f3502b5
fix(tests): Update tests to understand the precedence of publish_name
zsistla eaac00d
fix(agent): Handle vagaries of different Connection classes
zsistla 095f82d
fix(agent): check long not scalar
zsistla 71e5e02
fix(agent): add an unperist macro
zsistla 2335634
Merge branch 'dev' into feat/rabbitmq_instrumentation
zsistla ead28c2
fix(agent): Only set to 'default' in case of valid but empty string
zsistla 0d708cb
feat(agent): Insert/retrieve DT headers on rabbitmq
zsistla 0009a56
fix(agent): Update docstring
zsistla 88c904d
style(agent): rename variable
zsistla 4aa2522
style(agent): Comment clarification
zsistla b5c7def
style(agent): Comment update
zsistla 0e6ec90
fix(agent): Update comment
zsistla 127e62a
fix(agent): Comment about support.
zsistla a8569a2
Update agent/lib_php_amqplib.c
zsistla d6f40fa
fix(agent): belongs inside the block that checked for valid retval
zsistla e27a78e
fix(agent): Expectations needed to be flipped after a previous refactor
zsistla 23a8a34
fix(agent): unneeded var
zsistla 10858da
fix(agent): Update comments regarding DT vs w3c header behavior
zsistla 89d2937
fix(agent): just bail early from headers if DT isn't on
zsistla 90da3b7
fix(agent): use zval is integer function
zsistla f160b3b
fix(agent): Move dtors closer to where the values are initialized
zsistla 6e05947
fix(agent): add dtor closer to init
zsistla cd431ec
fix(agent): Calling order
zsistla ebb6ff0
feat(agent): Add RabbitMQ instrumentation using the php-amqplib library
zsistla 96f15aa
fix(agent): Typo remove AWS references
zsistla 33765b2
fix(agent): typo
zsistla 90c8aa9
feat(agent): Add additional unit test
zsistla 32a46a1
chore(agent): Clarifying comment.
zsistla ba1ab3f
feat(axiom): Update message segment to handle rabbitmq
zsistla 22f9185
feat(agent): Add php_amqplib basic_publish instrumentation.
zsistla 7453159
fix(axiom): Handle final metrix/txn naming when publish_name exists.
zsistla cdbafd3
feat(agent): Add php_libamqp basic_get instrumentation.
zsistla 98061cd
fix(tests): Update tests to understand the precedence of publish_name
zsistla de70737
fix(agent): Handle vagaries of different Connection classes
zsistla 49f93b3
fix(agent): check long not scalar
zsistla c937d74
fix(agent): add an unperist macro
zsistla 08bf3ff
fix(agent): Only set to 'default' in case of valid but empty string
zsistla a9b7d62
feat(agent): Insert/retrieve DT headers on rabbitmq
zsistla 8a30861
fix(agent): Update docstring
zsistla fc2e880
style(agent): rename variable
zsistla 24d9617
style(agent): Comment clarification
zsistla 2bd6f97
style(agent): Comment update
zsistla b024ce6
fix(agent): Update comment
zsistla e246369
fix(agent): Comment about support.
zsistla a965d83
Update agent/lib_php_amqplib.c
zsistla e2c8e05
fix(agent): belongs inside the block that checked for valid retval
zsistla b814dc4
fix(agent): Expectations needed to be flipped after a previous refactor
zsistla 7a4c0b9
fix(agent): unneeded var
zsistla fc6769d
fix(agent): Update comments regarding DT vs w3c header behavior
zsistla 011a6f7
fix(agent): just bail early from headers if DT isn't on
zsistla d4fc082
fix(agent): use zval is integer function
zsistla 60fd628
fix(agent): Move dtors closer to where the values are initialized
zsistla e623e99
fix(agent): add dtor closer to init
zsistla 839b098
fix(agent): Calling order
zsistla ba45e6c
Update agent/lib_php_amqplib.c
zsistla 87f641e
fix(agent): return null in version check and handle that outcome
zsistla 7eb5a8e
Merge branch 'feat/rabbitmq_instrumentation' of github.com:newrelic/n…
zsistla 3fa60ec
fix(agent): revert rebase error
zsistla 268c28b
fix(agent): It's actually fine if version is null
zsistla 73b47b2
fix(agent): check if Channel class exists before trying to manually l…
zsistla 54f720d
style(agent): rename eval_string last param
zsistla 55383f0
fix(agent): use zend_eval_stringl
zsistla 4461be7
Update agent/lib_php_amqplib.c
zsistla 851bdcd
Merge branch 'dev' into feat/rabbitmq_instrumentation
zsistla File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Copyright 2024 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/* | ||
* Functions relating to instrumenting the AWS-SDK-PHP. | ||
* https://github.com/aws/aws-sdk-php | ||
*/ | ||
#include "php_agent.h" | ||
#include "php_call.h" | ||
#include "php_hash.h" | ||
#include "php_wrapper.h" | ||
#include "fw_hooks.h" | ||
#include "fw_support.h" | ||
#include "util_logging.h" | ||
#include "lib_php_amqplib.h" | ||
|
||
#define PHP_PACKAGE_NAME "php-amqplib/php-amqplib" | ||
|
||
/* | ||
* nr_php_amqplib_handle_version will automatically load the class if it isn't | ||
* loaded yet and then evaluate the string. To avoid the VERY unlikely but not | ||
* impossible fatal error if the file/class isn't loaded yet, we need to wrap | ||
* the call in a try/catch block and make it a lambda so that we avoid fatal | ||
* errors. | ||
*/ | ||
void nr_php_amqplib_handle_version() { | ||
char* version = NULL; | ||
zval retval; | ||
int result = FAILURE; | ||
|
||
result = zend_eval_string( | ||
"(function() {" | ||
" $nr_php_amqplib_version = '';" | ||
" try {" | ||
mfulb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
" $nr_php_amqplib_version = PhpAmqpLib\\Package::VERSION;" | ||
" } catch (Throwable $e) {" | ||
" }" | ||
" return $nr_php_amqplib_version;" | ||
"})();", | ||
&retval, "Get nr_php_amqplib_version"); | ||
|
||
/* See if we got a non-empty/non-null string for version. */ | ||
if (SUCCESS == result) { | ||
mfulb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (nr_php_is_zval_non_empty_string(&retval)) { | ||
version = Z_STRVAL(retval); | ||
} | ||
} | ||
|
||
if (NRINI(vulnerability_management_package_detection_enabled)) { | ||
/* Add php package to transaction */ | ||
nr_txn_add_php_package(NRPRG(txn), PHP_PACKAGE_NAME, version); | ||
} | ||
|
||
nr_txn_suggest_package_supportability_metric(NRPRG(txn), PHP_PACKAGE_NAME, | ||
version); | ||
|
||
zval_dtor(&retval); | ||
} | ||
|
||
/* | ||
* | ||
* Version detection will be called directly from Aws\Sdk.php | ||
*/ | ||
void nr_php_amqplib_enable() { | ||
/* | ||
* Set the UNKNOWN package first, so it doesn't overwrite what we find with | ||
* nr_lib_aws_sdk_php_handle_version. | ||
*/ | ||
if (NRINI(vulnerability_management_package_detection_enabled)) { | ||
nr_txn_add_php_package(NRPRG(txn), PHP_PACKAGE_NAME, | ||
PHP_PACKAGE_VERSION_UNKNOWN); | ||
} | ||
|
||
/* Extract the version for aws-sdk 3+ */ | ||
nr_php_amqplib_handle_version(); | ||
|
||
/* Called when initializing all Clients */ | ||
// nr_php_wrap_user_function(NR_PSTR("Aws\\AwsClient::parseClass"), | ||
mfulb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
// nr_create_aws_service_metric); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* Copyright 2024 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Functions relating to instrumenting AWS-SDK-PHP. | ||
*/ | ||
#ifndef LIB_PHP_AMQPLIB | ||
#define LIB_PHP_AMQPLIB | ||
|
||
extern void nr_aws_php_amqplib_enable(); | ||
extern void nr_php_amqplib_handle_version(); | ||
|
||
#endif /* LIB_PHP_AMQPLIB */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* | ||
* Copyright 2024 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include "tlib_php.h" | ||
|
||
#include "php_agent.h" | ||
#include "lib_php_amqplib.h" | ||
#include "fw_support.h" | ||
|
||
tlib_parallel_info_t parallel_info | ||
= {.suggested_nthreads = -1, .state_size = 0}; | ||
|
||
#if ZEND_MODULE_API_NO > ZEND_7_1_X_API_NO | ||
|
||
static void declare_php_amqplib_package_class(const char* ns, | ||
const char* klass, | ||
const char* sdk_version) { | ||
char* source = nr_formatf( | ||
"namespace %s;" | ||
"class %s{" | ||
"const VERSION = '%s';" | ||
"}", | ||
ns, klass, sdk_version); | ||
|
||
tlib_php_request_eval(source); | ||
|
||
nr_free(source); | ||
} | ||
|
||
static void test_nr_lib_php_amqplib_handle_version(void) { | ||
#define LIBRARY_NAME "php-amqplib/php-amqplib" | ||
const char* library_versions[] | ||
= {"7", "10", "100", "4.23", "55.34", "6123.45", "0.4.5"}; | ||
nr_php_package_t* p = NULL; | ||
#define TEST_DESCRIPTION_FMT \ | ||
"nr_lib_php_amqplib_handle_version with library_versions[%ld]=%s: package " \ | ||
"major version metric - %s" | ||
char* test_description = NULL; | ||
size_t i = 0; | ||
|
||
/* | ||
* If lib_php_amqplib_handle_version function is ever called, we have already | ||
* detected the php-amqplib library. | ||
*/ | ||
|
||
/* | ||
* PhpAmqpLib/Package class exists. Should create php-amqplib package metric | ||
* suggestion with version | ||
*/ | ||
for (i = 0; i < sizeof(library_versions) / sizeof(library_versions[0]); i++) { | ||
tlib_php_request_start(); | ||
|
||
declare_php_amqplib_package_class("PhpAmqpLib", "Package", | ||
library_versions[i]); | ||
nr_lib_php_amqplib_handle_version(); | ||
|
||
p = nr_php_packages_get_package( | ||
NRPRG(txn)->php_package_major_version_metrics_suggestions, | ||
LIBRARY_NAME); | ||
|
||
test_description = nr_formatf(TEST_DESCRIPTION_FMT, i, library_versions[i], | ||
"suggestion created"); | ||
tlib_pass_if_not_null(test_description, p); | ||
nr_free(test_description); | ||
|
||
test_description = nr_formatf(TEST_DESCRIPTION_FMT, i, library_versions[i], | ||
"suggested version set"); | ||
tlib_pass_if_str_equal(test_description, library_versions[i], | ||
p->package_version); | ||
nr_free(test_description); | ||
|
||
tlib_php_request_end(); | ||
} | ||
|
||
/* | ||
* PhpAmqpLib/Package class does not exist, should create package metric | ||
* suggestion with PHP_PACKAGE_VERSION_UNKNOWN version. This case should never | ||
* happen in real situations. | ||
*/ | ||
tlib_php_request_start(); | ||
|
||
nr_lib_php_amqplib_handle_version(); | ||
|
||
p = nr_php_packages_get_package( | ||
NRPRG(txn)->php_package_major_version_metrics_suggestions, LIBRARY_NAME); | ||
|
||
tlib_pass_if_not_null( | ||
"nr_lib_php_amqplib_handle_version when PhpAmqpLib\\Package class is not " | ||
"defined - " | ||
"suggestion created", | ||
p); | ||
tlib_pass_if_str_equal( | ||
"nr_lib_php_amqplib_handle_version when PhpAmqpLib\\Package class is not " | ||
"defined - " | ||
"suggested version set to PHP_PACKAGE_VERSION_UNKNOWN", | ||
PHP_PACKAGE_VERSION_UNKNOWN, p->package_version); | ||
|
||
tlib_php_request_end(); | ||
} | ||
|
||
mfulb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
void test_main(void* p NRUNUSED) { | ||
tlib_php_engine_create(""); | ||
test_nr_lib_php_amqplib_handle_version(); | ||
tlib_php_engine_destroy(); | ||
} | ||
#else | ||
void test_main(void* p NRUNUSED) {} | ||
#endif |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.