Skip to content
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

improv: opencensus mysql #227

Merged
merged 4 commits into from
Feb 13, 2019
Merged

improv: opencensus mysql #227

merged 4 commits into from
Feb 13, 2019

Conversation

f-hj
Copy link
Contributor

@f-hj f-hj commented Feb 13, 2019

Adding mysql for oc tracing

@f-hj f-hj added the enhancement New feature or request label Feb 13, 2019
@f-hj f-hj requested a review from vmarchaud February 13, 2019 14:13
Copy link
Contributor

@vmarchaud vmarchaud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to patch the lib/Pool too so we can support ppl using the connection pool


if (this.internalFilesExports.Connection) {
this.logger.debug('patching mysql.Connection.createQuery')
shimmer.wrap(this.internalFilesExports.Connection, 'createQuery', this.getPatchCreateQuery())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to patch the prototype here too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


/** Unpatches all Mysql patched functions. */
applyUnpatch (): void {
shimmer.unwrap(this.internalFilesExports.Connection, 'createQuery')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and unwrap the prototype

return function (...args: any[]) {
var span = plugin.tracer.startChildSpan('mysql-query', plugin.SPAN_MYSQL_QUERY_TYPE)
if (span === null) return original.apply(this, arguments)
var query = original.apply(this, arguments)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace with const

}
}

private getPatchGetConnection() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should more something like this :

private getPatchGetConnection() {
  const plugin = this
  return (original: Function) => {
    return function (cb: Function) {
      return original.call(this, plugin.tracer.wrap(cb))
    }
  }
}

private getPatchGetConnection() {
return (original: Function) => {
return function (...args: any[]) {
return original.call(this, this.tracer.wrap(arguments))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the call to this.tracer will be undefined cause this refer to the function scope.
arguments will not work too cause .wrap accept function and not array

@@ -0,0 +1,145 @@
import { CoreTracer, RootSpan, SpanEventListener, logger } from '@pm2/opencensus-core'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need test for the connection pool patchs

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vmarchaud vmarchaud merged commit 0eef4a2 into feat/opencensus Feb 13, 2019
@vmarchaud vmarchaud deleted the feat/opencensus-mysql branch February 13, 2019 19:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants