-
Notifications
You must be signed in to change notification settings - Fork 97
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
PDO auto instrumentation #1 #102
PDO auto instrumentation #1 #102
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #102 +/- ##
=========================================
Coverage 64.42% 64.42%
Complexity 399 399
=========================================
Files 42 42
Lines 1380 1380
=========================================
Hits 889 889
Misses 491 491
Flags with carried forward coverage won't be shown. Click here to find out more. Continue to review full report at Codecov.
|
don't forget to add this to |
ok, thank you |
9ff0a27
to
29896a8
Compare
"require": { | ||
"php": "^8.0", | ||
"ext-otel_instrumentation": "*", | ||
"open-telemetry/api": "*", |
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.
"open-telemetry/api": "*", | |
"open-telemetry/api": "^1", |
->setAttribute(TraceAttributes::DB_CONNECTION_STRING, $params[0] ?? 'unknown') | ||
->setAttribute(TraceAttributes::DB_USER, $params[1] ?? 'unknown') | ||
// parse connection string | ||
->setAttribute(TraceAttributes::DB_SYSTEM, 'mysql'); |
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.
can this be implemented to get real value from connection string?
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.
yes, right. I forgot about this gap.
'fetchAll', | ||
pre: static function (\PDOStatement $statement, array $params, string $class, string $function, ?string $filename, ?int $lineno) use ($instrumentation) { | ||
/** @psalm-suppress ArgumentTypeCoercion */ | ||
$builder = self::makeBuilder($instrumentation, 'PDOStatement::fetch', $function, $class, $filename, $lineno) |
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.
$builder = self::makeBuilder($instrumentation, 'PDOStatement::fetch', $function, $class, $filename, $lineno) | |
$builder = self::makeBuilder($instrumentation, 'PDOStatement::fetchAll', $function, $class, $filename, $lineno) |
'execute', | ||
pre: static function (\PDOStatement $statement, array $params, string $class, string $function, ?string $filename, ?int $lineno) use ($instrumentation) { | ||
/** @psalm-suppress ArgumentTypeCoercion */ | ||
$builder = self::makeBuilder($instrumentation, 'PDOStatement::fetch', $function, $class, $filename, $lineno) |
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.
$builder = self::makeBuilder($instrumentation, 'PDOStatement::fetch', $function, $class, $filename, $lineno) | |
$builder = self::makeBuilder($instrumentation, 'PDOStatement::execute', $function, $class, $filename, $lineno) |
319dd6d
to
b3f89ff
Compare
"php": "^8.0", | ||
"ext-otel_instrumentation": "*", | ||
"open-telemetry/api": "^1", | ||
"nyholm/psr7": "^1", |
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 nyholm/* is not required for this instrumentation
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.
Yes, right. Will remove 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.
Approved, merge when you're ready. I've created https://github.com/opentelemetry-php/contrib-auto-pdo so the git-split has a destination...
ok, thank you |
@brettmc For dsn parsing I added additional dependency https://github.com/Nyholm/dsn. If you have something better or you think that we should implement this by ourselves just let me know (will do that in following PR, however for me it would be reinventing the wheel). |
Hmm, I see that sdk contains dsn parser, however it seems that it's not general enough and does not fulfil PDO requirements as I'm getting |
->setSpanKind(SpanKind::KIND_CLIENT) | ||
->setAttribute(TraceAttributes::DB_CONNECTION_STRING, $params[0] ?? 'unknown') | ||
->setAttribute(TraceAttributes::DB_USER, $params[1] ?? 'unknown') | ||
->setAttribute(TraceAttributes::DB_SYSTEM, self::getDB($params[0])); |
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.
You can use $pdo->getAttribute(PDO::ATTR_DRIVER_NAME)
to set db.system
in the post hook.
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
/** @psalm-suppress ArgumentTypeCoercion */ | ||
$builder = self::makeBuilder($instrumentation, 'PDO::__construct', $function, $class, $filename, $lineno) | ||
->setSpanKind(SpanKind::KIND_CLIENT) | ||
->setAttribute(TraceAttributes::DB_CONNECTION_STRING, $params[0] ?? 'unknown') |
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.
Should check that $class === PDO::class
, subclasses might declare different parameters.
|
||
hook( | ||
\PDOStatement::class, | ||
'fetch', |
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.
IMO we shouldn't create a span per ::fetch()
etc.; large result sets will lead to a lot of spans.
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 was thinking about it and plan to change this behaviour in subsequent PR(s). BTW I was thinking about kind of grouping fetch operations mechanism, however don't know yet if that will work
Initial commit of PDO auto instrumentation