Skip to content
This repository was archived by the owner on Oct 31, 2024. It is now read-only.

Commit dc10948

Browse files
authored
feat: Instrument typeorm query builder (#131)
* add query builder instrumentation * trace SelectQueryBuilder execute methods * rename to response * remove `setConfig` * add tav * clean up * remove component * remove commented out code * fix enableInternalInstrumentation * - `enableInternalInstrumentation` - `suppressInternalInstrumentation` * fix suppress * fix tests * refactor tests * add postgres to github tests * refactor * prettier * use mocking for querybuilder tests * fix conflict * pr comments * use in memory sqlite for tests * add table name assertion to all test * chore: prettier * add tests * added Supported Versions * PR fixes
1 parent 6301599 commit dc10948

16 files changed

+597
-289
lines changed

.github/workflows/test.yml

-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ on:
55
branches: [master]
66

77
jobs:
8-
98
prettier:
109
runs-on: ubuntu-latest
1110

@@ -18,7 +17,6 @@ jobs:
1817
test:
1918
runs-on: ubuntu-latest
2019
services:
21-
2220
mongo:
2321
image: mongo
2422
ports:
@@ -36,7 +34,6 @@ jobs:
3634
image: rabbitmq:3
3735
ports:
3836
- 22221:5672
39-
4037

4138
steps:
4239
- uses: actions/checkout@v2

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,7 @@ aspecto.json
2626
aspecto.log
2727

2828
# created from sequelize unit tests
29-
memory
29+
memory
30+
31+
#local database files
32+
*.db
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
'typeorm':
2+
versions: ">0.2.28"
3+
commands:
4+
- yarn test

packages/instrumentation-typeorm/README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ This module provides automatic instrumentation for [`TypeORM`](https://typeorm.i
99
npm install --save opentelemetry-instrumentation-typeorm
1010
```
1111

12+
## Supported Versions
13+
This instrumentation supports `>0.2.28`:
14+
1215
## Usage
1316
For further automatic instrumentation instruction see the [@opentelemetry/instrumentation](https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-instrumentation) package.
1417

@@ -42,7 +45,8 @@ TypeORM instrumentation has few options available to choose from. You can set th
4245
| -------------- | -------------------------------------- | ----------------------------------------------------------------------------------------------- |
4346
| `responseHook` | `TypeormResponseCustomAttributesFunction` | Hook called before response is returned, which allows to add custom attributes to span. |
4447
| `moduleVersionAttributeName` | `string` | If passed, a span attribute will be added to all spans with key of the provided `moduleVersionAttributeName` and value of the patched module version |
45-
48+
| `suppressInternalInstrumentation` | boolean | Typeorm operation use mongodb/postgres/mysql/mariadb/etc. under the hood. If, for example, postgres instrumentation is enabled, a postgres operation will also create a postgres span describing the communication. Setting the `suppressInternalInstrumentation` config value to `true` will cause the instrumentation to suppress instrumentation of underlying operations. |
49+
| `enableInternalInstrumentation` | boolean | Some methods such as `getManyAndCount` can generate internally multiple spans. To instrument those set this to `true`
4650

4751
---
4852

packages/instrumentation-typeorm/package.json

+7-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@
2424
"build": "tsc",
2525
"prepare": "yarn run build",
2626
"test": "mocha --require opentelemetry-instrumentation-testing-utils",
27+
"test-all-versions": "tav",
2728
"test:jaeger": "OTEL_EXPORTER_JAEGER_AGENT_HOST=localhost mocha --require opentelemetry-instrumentation-testing-utils",
28-
"test:ci": "yarn test",
29+
"test:ci": "yarn test-all-versions",
2930
"watch": "tsc -w",
3031
"version:update": "node ../../scripts/version-update.js",
3132
"version": "yarn run version:update"
@@ -35,8 +36,10 @@
3536
},
3637
"dependencies": {
3738
"@opentelemetry/api": "^0.20.0",
39+
"@opentelemetry/core": "^0.20.0",
3840
"@opentelemetry/instrumentation": "^0.20.0",
39-
"@opentelemetry/semantic-conventions": "^0.20.0"
41+
"@opentelemetry/semantic-conventions": "^0.20.0",
42+
"is-promise": "^4.0.0"
4043
},
4144
"devDependencies": {
4245
"@opentelemetry/tracing": "^0.20.0",
@@ -46,6 +49,8 @@
4649
"opentelemetry-instrumentation-mocha": "^0.0.1-rc.1",
4750
"opentelemetry-instrumentation-testing-utils": "^0.5.1",
4851
"reflect-metadata": "^0.1.13",
52+
"sqlite3": "^5.0.2",
53+
"test-all-versions": "^5.0.1",
4954
"ts-node": "^9.1.1",
5055
"typeorm": "^0.2.26",
5156
"typescript": "^4.0.3"

0 commit comments

Comments
 (0)