Skip to content

Commit

Permalink
Track restify request parameters
Browse files Browse the repository at this point in the history
Upgrade to the latest restify package that includes the `requestHook`
config option to report the parameters.

We only track them for the request handler layer type and not all
middlewares that may be present to avoid it being set multiple times and
it overwriting one another.

This relies on the `params` and `query` properties on the request. These
are the parsed request params and query params for the request that are
only available when the restify queryParser plugin is loaded. This
avoids us having to parse it separately, and I assume it will only be
necessary to track parameters if the plugin is added to the app.
  • Loading branch information
tombruijn committed Jan 2, 2023
1 parent dcf78f1 commit e4d8609
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 11 deletions.
6 changes: 6 additions & 0 deletions .changesets/report-request-parameters-for-restify.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
bump: "patch"
type: "add"
---

Report request parameters for restify apps. This is reported automatically. You can disable parameter reporting with the AppSignal `sendParams: false` configuration option.
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@opentelemetry/instrumentation-pg": "^0.33.0",
"@opentelemetry/instrumentation-redis": "^0.34.0",
"@opentelemetry/instrumentation-redis-4": "^0.34.0",
"@opentelemetry/instrumentation-restify": "^0.31.0",
"@opentelemetry/instrumentation-restify": "^0.32.0",
"@opentelemetry/sdk-node": "^0.34.0",
"@opentelemetry/sdk-trace-base": "^1.8.0",
"@prisma/instrumentation": "^4.4.0",
Expand Down
20 changes: 19 additions & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ import { PrismaInstrumentation } from "@prisma/instrumentation"
import { RedisDbStatementSerializer } from "./instrumentation/redis/serializer"
import { RedisInstrumentation as Redis4Instrumentation } from "@opentelemetry/instrumentation-redis-4"
import { RedisInstrumentation } from "@opentelemetry/instrumentation-redis"
import { RestifyInstrumentation } from "@opentelemetry/instrumentation-restify"
import {
RestifyInstrumentation,
LayerType as RestifyLayerType
} from "@opentelemetry/instrumentation-restify"
import { SpanProcessor, TestModeSpanProcessor } from "./span_processor"

const DefaultInstrumentations = {
Expand Down Expand Up @@ -300,6 +303,21 @@ export class Client {
"@opentelemetry/instrumentation-redis-4": {
dbStatementSerializer: RedisDbStatementSerializer
},
"@opentelemetry/instrumentation-restify": {
requestHook: (span, info) => {
if (
sendParams &&
info.layerType === RestifyLayerType.REQUEST_HANDLER
) {
const request = info.request
const params = Object.assign(
request.params || {},
request.query || {}
)
setParams(params, span)
}
}
},
"@prisma/instrumentation": {
middleware: true
},
Expand Down
1 change: 1 addition & 0 deletions test/restify/app/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ function respond(req: any, res: any, next: any) {
}

const server = restify.createServer()
server.use(restify.plugins.queryParser())
server.get("/", function (req: any, res: any, next: any) {
res.send("home")
return next()
Expand Down

0 comments on commit e4d8609

Please sign in to comment.