Skip to content

Commit 4772c2d

Browse files
feat: mongodb instrumentation (#127)
1 parent c8daa63 commit 4772c2d

33 files changed

Lines changed: 5825 additions & 1 deletion

.github/workflows/e2e.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,20 @@ jobs:
2121
matrix:
2222
library:
2323
# Exclude upstash-redis-js for now because takes ~15 min. To re-enable when someone needs it.
24-
[fetch, firestore, grpc, http, ioredis, mysql, mysql2, nextjs, pg, postgres, prisma]
24+
[
25+
fetch,
26+
firestore,
27+
grpc,
28+
http,
29+
ioredis,
30+
mysql,
31+
mysql2,
32+
nextjs,
33+
pg,
34+
postgres,
35+
prisma,
36+
mongodb,
37+
]
2538
steps:
2639
- name: Checkout
2740
uses: actions/checkout@v4

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ Tusk Drift currently supports the following packages and versions:
4848
- **Firestore**: `@google-cloud/firestore@7.x-8.x`
4949
- **Postgres**: `postgres@3.x`
5050
- **MySQL**: `mysql2@3.x`, `mysql@2.x`
51+
- **MongoDB**: `mongodb@5.x-7.x`
5152
- **IORedis**: `ioredis@4.x-5.x`
5253
- **Upstash Redis**: `@upstash/redis@1.x`
5354
- **GraphQL**: `graphql@15.x-16.x`

src/core/TuskDrift.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
NextjsInstrumentation,
2121
PrismaInstrumentation,
2222
MysqlInstrumentation,
23+
MongodbInstrumentation,
2324
} from "../instrumentation/libraries";
2425
import { TdSpanExporter } from "./tracing/TdSpanExporter";
2526
import { trace, Tracer, SpanKind, SpanStatusCode } from "@opentelemetry/api";
@@ -325,6 +326,11 @@ export class TuskDriftCore {
325326
enabled: true,
326327
mode: this.mode,
327328
});
329+
330+
new MongodbInstrumentation({
331+
enabled: true,
332+
mode: this.mode,
333+
});
328334
}
329335

330336
private initializeTracing({ baseDirectory }: { baseDirectory: string }): void {

src/instrumentation/libraries/date/Instrumentation.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,14 @@ export class DateInstrumentation extends TdInstrumentationBase {
147147

148148
return self._handleDateCall(args, isConstructorCall);
149149
}
150+
// Preserve the original constructor name so that libraries which validate
151+
// types by checking constructor.name (e.g. Mongoose schema type validation)
152+
// still see "Date" instead of "_TdDate". Without this, any Mongoose schema
153+
// using { type: Date } throws:
154+
// TypeError: Invalid schema configuration: `_TdDate` is not a valid type
155+
// This only changes the name metadata — all instrumentation logic is unaffected.
156+
Object.defineProperty(_TdDate, "name", { value: "Date" });
157+
150158
return _TdDate;
151159
};
152160
}

src/instrumentation/libraries/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ export * from "./grpc";
1515
export * from "./firestore";
1616
export * from "./nextjs";
1717
export * from "./prisma";
18+
export * from "./mongodb";

0 commit comments

Comments
 (0)