From 952e6d71797c4a8860bc506a91983c962d3f785d Mon Sep 17 00:00:00 2001 From: Daniel Dyla Date: Sat, 14 Aug 2021 03:53:55 -0400 Subject: [PATCH 1/4] chore: ignore renovate-bot for component owners (#612) --- .github/component_owners.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/component_owners.yml b/.github/component_owners.yml index d1e4069c1e..e6d8e3bd37 100644 --- a/.github/component_owners.yml +++ b/.github/component_owners.yml @@ -13,3 +13,6 @@ components: - willarmiros detectors/node/opentelemetry-resource-detector-alibaba-cloud: - legendecas + +ignored-authors: + - renovate-bot From 72b78e62181ac778f635f9e67a3f315fd9ef49af Mon Sep 17 00:00:00 2001 From: Jessica Kerr Date: Sat, 14 Aug 2021 03:20:12 -0500 Subject: [PATCH 2/4] docs: correct the build instructions (#615) Co-authored-by: Valentin Marchaud --- .../README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/opentelemetry-browser-extension-autoinjection/README.md b/packages/opentelemetry-browser-extension-autoinjection/README.md index 6386d9853f..eb4ab7627e 100644 --- a/packages/opentelemetry-browser-extension-autoinjection/README.md +++ b/packages/opentelemetry-browser-extension-autoinjection/README.md @@ -24,13 +24,13 @@ This browser extension allows you to inject [OpenTelemetry](https://opentelemetr Run the following in your shell to download and build the extension from source: ```shell -git clone https://github.com/svrnm/opentelemetry-browser-extension -cd opentelemetry-browser-extension +git clone https://github.com/open-telemetry/opentelemetry-js-contrib.git +cd opentelemetry-js-contrib/packages/opentelemetry-browser-extension-autoinjection npm install -npm run compile +npm run build ``` -This will create a so called unpacked extension into the `build/` folder you now can load into your browser: +This will create a so-called unpacked extension into the `build/` folder you now can load into your browser: * Open a new browser window and go to chrome://extensions * Turn on "Developer Mode" @@ -58,4 +58,4 @@ Click on `Save & Reload`, check the developer toolbar to see how spans being are 3. Firefox support is unstable, sometimes it works, sometimes not. If you have experience building extensions for firefox, please reach out. -4. The website you are targeting with this extension might have a [Content Security Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy) (CSP) in place and block the extension from injecting javascript or block the exporters from sending spans to a collector. To work around this limitation, you need another browser extension, that allows you to disable CSP for a website. \ No newline at end of file +4. The website you are targeting with this extension might have a [Content Security Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy) (CSP) in place and block the extension from injecting javascript or block the exporters from sending spans to a collector. To work around this limitation, you need another browser extension, that allows you to disable CSP for a website. From 90d4e78ec090d3f34c3bf24729009a3dcce91f2b Mon Sep 17 00:00:00 2001 From: Simon Stone Date: Sat, 14 Aug 2021 09:41:13 +0100 Subject: [PATCH 3/4] fix(mysql): bind get connection callback to active context (#562) Co-authored-by: Valentin Marchaud --- .../src/instrumentation.ts | 41 ++++++++++++++----- .../test/index.test.ts | 38 +++++++++++++++++ 2 files changed, 68 insertions(+), 11 deletions(-) diff --git a/plugins/node/opentelemetry-instrumentation-mysql/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-mysql/src/instrumentation.ts index 82ea9770d4..8a0652d503 100644 --- a/plugins/node/opentelemetry-instrumentation-mysql/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-mysql/src/instrumentation.ts @@ -14,7 +14,13 @@ * limitations under the License. */ -import { diag, Span, SpanKind, SpanStatusCode } from '@opentelemetry/api'; +import { + context, + diag, + Span, + SpanKind, + SpanStatusCode, +} from '@opentelemetry/api'; import { InstrumentationBase, InstrumentationNodeModuleDefinition, @@ -28,6 +34,11 @@ import { VERSION } from './version'; type formatType = typeof mysqlTypes.format; +type getConnectionCallbackType = ( + err: mysqlTypes.MysqlError, + connection: mysqlTypes.PoolConnection +) => void; + export class MySQLInstrumentation extends InstrumentationBase< typeof mysqlTypes > { @@ -176,21 +187,21 @@ export class MySQLInstrumentation extends InstrumentationBase< if (arguments.length === 1 && typeof arg1 === 'function') { const patchFn = thisPlugin._getConnectionCallbackPatchFn( - arg1, + arg1 as getConnectionCallbackType, format ); return originalGetConnection.call(pool, patchFn); } if (arguments.length === 2 && typeof arg2 === 'function') { const patchFn = thisPlugin._getConnectionCallbackPatchFn( - arg2, + arg2 as getConnectionCallbackType, format ); return originalGetConnection.call(pool, arg1, patchFn); } if (arguments.length === 3 && typeof arg3 === 'function') { const patchFn = thisPlugin._getConnectionCallbackPatchFn( - arg3, + arg3 as getConnectionCallbackType, format ); return originalGetConnection.call(pool, arg1, arg2, patchFn); @@ -201,22 +212,30 @@ export class MySQLInstrumentation extends InstrumentationBase< }; } - private _getConnectionCallbackPatchFn(cb: Function, format: formatType) { + private _getConnectionCallbackPatchFn( + cb: getConnectionCallbackType, + format: formatType + ) { const thisPlugin = this; - return function () { - if (arguments[1]) { + const activeContext = context.active(); + return function ( + this: any, + err: mysqlTypes.MysqlError, + connection: mysqlTypes.PoolConnection + ) { + if (connection) { // this is the callback passed into a query // no need to unwrap - if (!isWrapped(arguments[1].query)) { + if (!isWrapped(connection.query)) { thisPlugin._wrap( - arguments[1], + connection, 'query', - thisPlugin._patchQuery(arguments[1], format) + thisPlugin._patchQuery(connection, format) ); } } if (typeof cb === 'function') { - cb(...arguments); + context.with(activeContext, cb, this, err, connection); } }; } diff --git a/plugins/node/opentelemetry-instrumentation-mysql/test/index.test.ts b/plugins/node/opentelemetry-instrumentation-mysql/test/index.test.ts index fbf726281b..060b56e0cf 100644 --- a/plugins/node/opentelemetry-instrumentation-mysql/test/index.test.ts +++ b/plugins/node/opentelemetry-instrumentation-mysql/test/index.test.ts @@ -426,6 +426,25 @@ describe('mysql@2.x', () => { }); }); }); + + it('should propagate active context to callback', done => { + const parentSpan = provider.getTracer('default').startSpan('test span'); + context.with(trace.setSpan(context.active(), parentSpan), () => { + pool.getConnection((err, connection) => { + assert.ifError(err); + assert.ok(connection); + const sql = 'SELECT ? as solution'; + connection.query(sql, 1, (err, res) => { + assert.ifError(err); + assert.ok(res); + assert.strictEqual(res[0].solution, 1); + const actualSpan = trace.getSpan(context.active()); + assert.strictEqual(actualSpan, parentSpan); + done(); + }); + }); + }); + }); }); describe('#PoolCluster', () => { @@ -600,6 +619,25 @@ describe('mysql@2.x', () => { } ); }); + + it('should propagate active context to callback', done => { + const parentSpan = provider.getTracer('default').startSpan('test span'); + context.with(trace.setSpan(context.active(), parentSpan), () => { + poolCluster.getConnection((err, connection) => { + assert.ifError(err); + assert.ok(connection); + const sql = 'SELECT ? as solution'; + connection.query(sql, 1, (err, res) => { + assert.ifError(err); + assert.ok(res); + assert.strictEqual(res[0].solution, 1); + const actualSpan = trace.getSpan(context.active()); + assert.strictEqual(actualSpan, parentSpan); + done(); + }); + }); + }); + }); }); }); From 6a99dc22ab5604925c737481514bdf98052479e3 Mon Sep 17 00:00:00 2001 From: Rauno Viskus Date: Sat, 14 Aug 2021 11:53:24 +0300 Subject: [PATCH 4/4] chore: add Rauno56 as the component owner of authored instrumentations (#613) Co-authored-by: Valentin Marchaud --- .github/component_owners.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/component_owners.yml b/.github/component_owners.yml index e6d8e3bd37..f906881b00 100644 --- a/.github/component_owners.yml +++ b/.github/component_owners.yml @@ -5,6 +5,16 @@ components: plugins/node/opentelemetry-instrumentation-aws-lambda: - NathanielRN - willarmiros + plugins/node/opentelemetry-instrumentation-restify: + - rauno56 + plugins/node/opentelemetry-instrumentation-router: + - rauno56 + plugins/node/opentelemetry-instrumentation-memcached: + - rauno56 + plugins/node/opentelemetry-instrumentation-knex: + - rauno56 + plugins/node/opentelemetry-instrumentation-generic-pool: + - rauno56 propagators/opentelemetry-propagator-aws-xray: - NathanielRN - willarmiros