Skip to content

Commit

Permalink
docs: Updated examples to properly use specs (#2422)
Browse files Browse the repository at this point in the history
  • Loading branch information
bizob2828 authored Aug 1, 2024
1 parent 0dfab8c commit f7e8c58
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
24 changes: 12 additions & 12 deletions examples/shim/Datastore-Simple.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions examples/shim/Messaging-Simple.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
})
})
}
```
Expand Down Expand Up @@ -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.
Expand All @@ -196,7 +196,7 @@ function instrumentMyMessageBroker(shim, messageBrokerModule, moduleName) {
headers: headers
}
}
})
}))
}
```

Expand All @@ -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.
Expand All @@ -232,7 +232,7 @@ function instrumentMyMessageBroker(shim, messageBrokerModule, moduleName) {
headers: headers
}
}
})
}))
}
```

Expand Down
8 changes: 4 additions & 4 deletions examples/shim/Webframework-Simple.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
}))
}
})

Expand Down Expand Up @@ -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
})
}))
```

[<img src="./trace-summary-view.png" alt="view segment" style="text-align:center;width:100%" />]
Expand Down

0 comments on commit f7e8c58

Please sign in to comment.