From 2bea12ca0fe599ed6104f3c67b59560833c7cc86 Mon Sep 17 00:00:00 2001 From: Bob Evans Date: Thu, 1 Aug 2024 12:41:05 -0400 Subject: [PATCH] docs: Updated examples to properly use specs --- examples/shim/Datastore-Simple.md | 24 ++++++++++++------------ examples/shim/Messaging-Simple.md | 16 ++++++++-------- examples/shim/Webframework-Simple.md | 8 ++++---- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/examples/shim/Datastore-Simple.md b/examples/shim/Datastore-Simple.md index 9c5e184b16..4413d30895 100644 --- a/examples/shim/Datastore-Simple.md +++ b/examples/shim/Datastore-Simple.md @@ -16,12 +16,12 @@ function instrumentCassandra(shim, cassandra, moduleName) { shim.setDatastore(shim.CASSANDRA) var proto = cassandra.Client.prototype - shim.recordOperation(proto, ['connect', 'shutdown'], {callback: shim.LAST}) - shim.recordQuery(proto, '_execute', {query: shim.FIRST, callback: shim.LAST}) - shim.recordBatchQuery(proto, 'batch', { + shim.recordOperation(proto, ['connect', 'shutdown'], new shim.specs.OperationSpec({callback: shim.LAST}) + shim.recordQuery(proto, '_execute', new shim.specs.QuerySpec({query: shim.FIRST, callback: shim.LAST})) + shim.recordBatchQuery(proto, 'batch', new shim.specs.QuerySpec({ query: findBatchQueryArg, callback: shim.LAST - }) + })) } function findBatchQueryArg(shim, batch, fnName, args) { @@ -106,7 +106,7 @@ will show up on the [New Relic APM Databases page][2] like this: ```js var proto = cassandra.Client.prototype - shim.recordOperation(proto, ['connect', 'shutdown'], {callback: shim.LAST}) + shim.recordOperation(proto, ['connect', 'shutdown'], new shim.specs.OperationSpec({callback: shim.LAST})) ``` Now on to the actual instrumentation. In `cassandra-driver`, all of the @@ -136,8 +136,8 @@ If we didn't like the names of the methods, we could supply an alternate name to `shim.recordOperation` in the last parameter like this: ```js - shim.recordOperation(proto, 'connect', {name: 'Connect', callback: shim.LAST}) - shim.recordOperation(proto, 'shutdown', {name: 'Shutdown', callback: shim.LAST}) + shim.recordOperation(proto, 'connect', new shim.specs.OperationSpec({name: 'Connect', callback: shim.LAST})) + shim.recordOperation(proto, 'shutdown', new shim.specs.OperationSpec({name: 'Shutdown', callback: shim.LAST})) ``` Note that since we want these operations named differently, if we specify the @@ -149,12 +149,12 @@ supplied instead. This function will receive the arguments and the segment, and is responsible for connecting the two. Here's how that might look in our case: ```js - shim.recordOperation(proto, ['connect', 'shutdown'], { + shim.recordOperation(proto, ['connect', 'shutdown'], new shim.specs.OperationSpec({ callback: function operationCallbackBinder(shim, opFunc, opName, segment, args) { var cb = args[args.length - 1] args[args.length - 1] = shim.bindSegment(cb, segment, true) } - }) + })) ``` Note that the `args` parameter is a proper [`Array`][5], so you can assign back @@ -164,7 +164,7 @@ into it and use any other array manipulation that you want. ### Recording Queries ```js - shim.recordQuery(proto, '_execute', {query: shim.FIRST, callback: shim.LAST}) + shim.recordQuery(proto, '_execute', new shim.specs.QuerySpec({query: shim.FIRST, callback: shim.LAST})) ``` The `cassandra.Client` class has three different methods for performing queries: @@ -193,10 +193,10 @@ the collection queried (`test.testFamily`) as well as the query operation ### Recording Batch Queries ```js - shim.recordBatchQuery(proto, 'batch', { + shim.recordBatchQuery(proto, 'batch', new shim.specs.QuerySpec({ query: findBatchQueryArg, callback: shim.LAST - }) + })) ``` Recording batches of queries is just like recording a single one, except we need diff --git a/examples/shim/Messaging-Simple.md b/examples/shim/Messaging-Simple.md index 3dff8bd0e2..d815901163 100644 --- a/examples/shim/Messaging-Simple.md +++ b/examples/shim/Messaging-Simple.md @@ -128,13 +128,13 @@ function instrumentMyMessageBroker(shim, messageBrokerModule, moduleName) { // misc key/value parameters can be recorded as a part of the trace segment var params = {} - return { + return new shim.specs.MessageSpec({ callback: shim.LAST, destinationName: queueName, destinationType: shim.QUEUE, headers: headers, parameters: params - } + }) }) } ``` @@ -177,10 +177,10 @@ instrumentation of this method would look like this: function instrumentMyMessageBroker(shim, messageBrokerModule, moduleName) { var Client = myMessageBrokerModule.Client - shim.recordConsume(Client.prototype, 'getMessage', { + shim.recordConsume(Client.prototype, 'getMessage', new shim.specs.MessageSpec({ destinationName: shim.FIRST, callback: shim.LAST, - messageHandler: function(shim, fn, name, args) { + after: function({ shim, args }) { var message = args[1] // These headers are used to set up cross-application tracing. @@ -196,7 +196,7 @@ function instrumentMyMessageBroker(shim, messageBrokerModule, moduleName) { headers: headers } } - }) + })) } ``` @@ -218,9 +218,9 @@ they are received. The instrumentation in this case would look like this: function instrumentMyMessageBroker(shim, messageBrokerModule, moduleName) { var Client = myMessageBrokerModule.Client - shim.recordSubcribedConsume(Client.prototype, 'subscribe', { + shim.recordSubcribedConsume(Client.prototype, 'subscribe', new shim.specs.MessageSubscribeSpec({ consumer: shim.LAST, - messageHandler: function(shim, consumer, name, args) { + messageHandler: function(shim, args) { var message = args[0] // These headers are used to set up cross-application tracing. @@ -232,7 +232,7 @@ function instrumentMyMessageBroker(shim, messageBrokerModule, moduleName) { headers: headers } } - }) + })) } ``` diff --git a/examples/shim/Webframework-Simple.md b/examples/shim/Webframework-Simple.md index 1540dcb1d8..6308cee73e 100644 --- a/examples/shim/Webframework-Simple.md +++ b/examples/shim/Webframework-Simple.md @@ -141,13 +141,13 @@ let Server = myWebFramework.Server shim.wrapMiddlewareMounter(Server.prototype, ['all', 'get'], { route: shim.FIRST, wrapper: function wrapMiddleware(shim, fn, name, route) { - return shim.recordMiddleware(fn, { + return shim.recordMiddleware(fn, new shim.specs.MiddlewareSpec({ route: route, type: shim.MIDDLEWARE, req: shim.FIRST, res: shim.SECOND, next: shim.THIRD - }) + })) } }) @@ -217,10 +217,10 @@ do the following in our instrumentation: ```js let Server = myWebFramework.Server -shim.recordRender(Server.prototype, 'render', { +shim.recordRender(Server.prototype, 'render', new shim.specs.RenderSpec({ view: shim.FIRST, callback: shim.LAST -}) +})) ``` [view segment]