Skip to content

Commit

Permalink
Add Knex.js instrumentation (#803)
Browse files Browse the repository at this point in the history
- Add the Knex.js instrumentation package as a dependency.
- Load it by default.
- Add an integration test app for Knex.js.

Part of #762
  • Loading branch information
tombruijn authored Nov 23, 2022
1 parent 686d318 commit c1354f0
Show file tree
Hide file tree
Showing 23 changed files with 4,799 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .changesets/add-knex-js-instrumentation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
bump: "patch"
type: "add"
---

Add Knex.js instrumentation. We will now auto instrument database queries made with Knex.js.
3 changes: 3 additions & 0 deletions .semaphore/semaphore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ blocks:
- name: Express + Redis
commands:
- script/integration_test_app express-redis
- name: Express + Knex.js
commands:
- script/integration_test_app express-knex
- name: Koa + MySQL
commands:
- script/integration_test_app koa-mysql
Expand Down
3 changes: 3 additions & 0 deletions build_matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ semaphore: # Default `.semaphore/semaphore.yml` contents
- name: Express + Redis
commands:
- script/integration_test_app express-redis
- name: Express + Knex.js
commands:
- script/integration_test_app express-knex
- name: Koa + MySQL
commands:
- script/integration_test_app koa-mysql
Expand Down
25 changes: 25 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"@opentelemetry/instrumentation-graphql": "^0.33.0",
"@opentelemetry/instrumentation-http": "^0.34.0",
"@opentelemetry/instrumentation-ioredis": "^0.33.0",
"@opentelemetry/instrumentation-knex": "^0.31.0",
"@opentelemetry/instrumentation-koa": "^0.34.0",
"@opentelemetry/instrumentation-mongodb": "0.33.0",
"@opentelemetry/instrumentation-mongoose": "^0.32.0",
Expand Down
2 changes: 2 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { FsInstrumentation } from "@opentelemetry/instrumentation-fs"
import { GraphQLInstrumentation } from "@opentelemetry/instrumentation-graphql"
import { HttpInstrumentation } from "@opentelemetry/instrumentation-http"
import { IORedisInstrumentation } from "@opentelemetry/instrumentation-ioredis"
import { KnexInstrumentation } from "@opentelemetry/instrumentation-knex"
import { KoaInstrumentation } from "@opentelemetry/instrumentation-koa"
import { MongoDBInstrumentation } from "@opentelemetry/instrumentation-mongodb"
import { MongooseInstrumentation } from "@opentelemetry/instrumentation-mongoose"
Expand All @@ -42,6 +43,7 @@ const DefaultInstrumentations = {
"@opentelemetry/instrumentation-graphql": GraphQLInstrumentation,
"@opentelemetry/instrumentation-http": HttpInstrumentation,
"@opentelemetry/instrumentation-ioredis": IORedisInstrumentation,
"@opentelemetry/instrumentation-knex": KnexInstrumentation,
"@opentelemetry/instrumentation-koa": KoaInstrumentation,
"@opentelemetry/instrumentation-mongodb": MongoDBInstrumentation,
"@opentelemetry/instrumentation-mongoose": MongooseInstrumentation,
Expand Down
1 change: 1 addition & 0 deletions test/express-knex/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist/
5 changes: 5 additions & 0 deletions test/express-knex/app/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM node:16

COPY run.sh /

ENTRYPOINT ["sh", "/run.sh"]
30 changes: 30 additions & 0 deletions test/express-knex/app/knexfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Update with your config settings.

/**
* @type { Object.<string, import("knex").Knex.Config> }
*/
module.exports = {
development: {
client: "postgresql",
connection: process.env.DATABASE_URL,
pool: {
min: 2,
max: 10
},
migrations: {
tableName: "knex_migrations"
}
},

production: {
client: "postgresql",
connection: process.env.DATABASE_URL,
pool: {
min: 2,
max: 10
},
migrations: {
tableName: "knex_migrations"
}
}
}
19 changes: 19 additions & 0 deletions test/express-knex/app/migrations/20221121143401_create_posts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.up = function (knex) {
return knex.schema.createTable("posts", function (table) {
table.increments("id")
table.string("title", 255).notNullable()
table.string("body", 255).notNullable()
})
}

/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.down = function (knex) {
return knex.schema.dropTable("posts")
}
Loading

0 comments on commit c1354f0

Please sign in to comment.