-
Notifications
You must be signed in to change notification settings - Fork 61
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): Add basic aws-sdk-php intrumentation #932
Conversation
1) Detects the use of aws-sdk-php 3 library with a magic file 2) Wraps 2 functions to ensure we get the proper library version number. The 2 funcs were chosen because A) `Aws\\AwsClient::__construct` is associated with the current magic file and is the base of all other Clients B) `Aws\\Sdk::__construct` because the Sdk class is where version resides. 3) Sends a supportability metric for the library and package 4) Sends PHP Package info for version 5) Multiverse tests were added in support of this
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #932 +/- ##
==========================================
- Coverage 78.16% 78.12% -0.05%
==========================================
Files 193 194 +1
Lines 26803 26845 +42
==========================================
+ Hits 20950 20972 +22
- Misses 5853 5873 +20
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
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’m still thinking if both constructors Aws\\AwsClient::__construct
and Aws\\Sdk::__construct
need to be instrumented 🤔 Reason why I’m thinking about this is overhead. If only Aws\\Sdk::__construct
was instrumented, then
newrelic-php-agent/agent/lib_aws_sdk_php.c
Lines 25 to 27 in 2c27a8c
/* Use the Aws\Sdk::VERSION to determine the version */ | |
class_entry = nr_php_find_class("aws\\sdk"); | |
zval_version = nr_php_get_class_constant(class_entry, "VERSION"); |
$this
, available through nr_php_scope_get
, would be of Aws\Sdk
type and therefore no class lookup (class_entry = nr_php_find_class("aws\\sdk");
) would be necessary, and VERSION
could be pulled directly from $this
- see how Monolog’s API version is retrieved: newrelic-php-agent/agent/lib_monolog.c
Line 376 in 2c27a8c
api = nr_monolog_version(this_var TSRMLS_CC); |
However, I’m not sure if Aws\\Sdk::__construct
is called when only Aws\\AwsClient::__construct
is used. Either way - I think using a dedicated wrapper for Aws\\Sdk::__construct
to retrieve version without class lookup is warranted.
1. added unit tests 2 created to wrapped functions that a) one creates a supportability metric based off of the class name of the wrapped function b) one generates version info and creates package and version metrics 3. Updated how version info was generated.
Thanks for the comment. After further research, We can wrap the class to get metrics to determine if it is worth investing effort in instrumenting, but as of now, the focus is on For additional commentary on this, please see a36d635
|
1) re-add unknown_version package info when first detecting 2) exclude unit tests from 7.1,7.0 (aws-sdk doesn't work with those)
Co-authored-by: Michal Nowacki <mnowacki@newrelic.com>
…php s3client metricfeat(agent): Add aws-sdk-php s3client metricfeat(agent): Add aws-sdk-php s3client metricfeat(agent): Add aws-sdk-php s3client metricfeat(agent): Add aws-sdk-php s3client metricfeat(agent): Add aws-sdk-php s3client metricfeat(agent): Add aws-sdk-php s3client metricfeat(agent): Add aws-sdk-php s3client metric
NR_PHP_WRAPPER_END | ||
|
||
/* | ||
* AwsClient::parseClass |
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.
Leaving this for posterity: https://github.com/aws/aws-sdk-php/blob/3.316.3/src/AwsClient.php#L373-L387
Co-authored-by: Michal Nowacki <mnowacki@newrelic.com>
Co-authored-by: Michal Nowacki <mnowacki@newrelic.com>
Co-authored-by: Michal Nowacki <mnowacki@newrelic.com>
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.
Nice job!
further updated to:
Then the metric is generated as seen in the associated multiverse tests.
Please see the challenge with instrumenting for PHP 8.2+ and various options that were considered below.
Option 2 is the currently chosen method due to lower risk, complexity, and overhead.
Challenges:
Php8.2+ and composer autoload leads to the main magic file being optimized directly to opcache.
Options considered:
summary:
Magic file =
{"AWS-SDK-PHP", NR_PSTR("aws-sdk-php/src/functions.php"), nr_aws_sdk_php_enable, true},
Requires bool added to library structure:
`
use a file that gets called later and only when AwsClient.php file file is called. It's called later and we'll miss some instrumentation, but if we're only ever going to be interested in
Client
calls anyway, maybe that's ok? Doesn't detect Sdk.php (optimized out) so when customers only use that or when they use it first, we will not instrument it. This only detects when a Client is called to use a service so potentially misses out on other instrumentation and misses out when customers use the aws-sdk-php but use non-SDK way to interact with the service (possibly with redis/memcached). This way is definitely the least complex and lowest overhead and less complexity means lower risk as well.Just directly add the wrappers to the hash map. With potentially 50ish clients to wrap, this will add overhead to every hash map lookup.