Skip to content

Commit 4384f9b

Browse files
committed
feat: Add new package dependency for AWS X-Ray integration
This commit adds a new package dependency for integrating AWS X-Ray with Prisma. Specifically, it adds the package "aws-xray-sdk-prisma" and sets its version to 3.5.0 in the package-lock.json file. Additionally, in the "capturePrisma" function in the "sdk_contrib/prisma/src/capturePrisma.ts" file, an error message is logged if no segment is provided in manual mode. In the unit tests for the "capturePrisma" function in the "sdk_contrib/prisma/test/unit/prisma.test.js" file, the Prisma client is now initialized with a segment, and the absence of a segment is properly handled and logged as an error. These changes ensure proper integration of AWS X-Ray with Prisma and improve error handling when manual mode is used without a segment.
1 parent 4510a0c commit 4384f9b

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk_contrib/prisma/src/capturePrisma.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ export function capturePrisma<T extends PrismaClient>(
4040
});
4141
});
4242
}
43+
44+
if (!segment) {
45+
console.error('No segment provided when is manual mode');
46+
}
47+
4348
return new Proxy(prisma, {
4449
get(obj, modelKey): any {
4550
const attr = obj[modelKey as keyof T];

sdk_contrib/prisma/test/unit/prisma.test.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,14 @@ describe('Prisma', function () {
3333
});
3434

3535
describe('capturePrisma', function () {
36-
var client, sandbox;
36+
var client, sandbox, segment;
3737
beforeEach(function () {
3838
xray.enableManualMode();
39-
client = capturePrisma(prisma);
39+
40+
segment = new Segment('test');
41+
client = capturePrisma(prisma, {
42+
segment,
43+
});
4044
sandbox = sinon.createSandbox();
4145
});
4246

@@ -80,10 +84,12 @@ describe('Prisma', function () {
8084

8185
it('Segment should not be set', function () {
8286
const ns = xray.getNamespace();
83-
assert.Throw(() => {
84-
ns.run(() => {
85-
client.company.create();
86-
});
87+
const error = sinon.stub();
88+
const logger = xray.getLogger();
89+
logger.error = error;
90+
ns.run(async () => {
91+
client.company.create();
92+
assert.isTrue(error.calledOnce);
8793
});
8894
});
8995

@@ -130,8 +136,10 @@ describe('Prisma', function () {
130136
var client, segment, sandbox;
131137
beforeEach(function () {
132138
xray.enableManualMode();
133-
client = capturePrisma(prisma);
134139
segment = new Segment('test');
140+
client = capturePrisma(prisma, {
141+
segment,
142+
});
135143
sandbox = sinon.createSandbox();
136144
});
137145

@@ -180,8 +188,8 @@ describe('Prisma', function () {
180188
var client, segment, subsegment, sandbox;
181189
beforeEach(function () {
182190
xray.enableManualMode();
183-
client = capturePrisma(prisma);
184191
segment = new Segment('test');
192+
client = capturePrisma(prisma, { segment });
185193
subsegment = segment.addNewSubsegment('test');
186194
sandbox = sinon.createSandbox();
187195
});

0 commit comments

Comments
 (0)