Skip to content

Commit

Permalink
feat: Add new package dependency for AWS X-Ray integration
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
EduardMcfly committed Oct 19, 2023
1 parent 4510a0c commit 4384f9b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
1 change: 1 addition & 0 deletions package-lock.json

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

5 changes: 5 additions & 0 deletions sdk_contrib/prisma/src/capturePrisma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ export function capturePrisma<T extends PrismaClient>(
});
});
}

if (!segment) {
console.error('No segment provided when is manual mode');
}

return new Proxy(prisma, {
get(obj, modelKey): any {
const attr = obj[modelKey as keyof T];
Expand Down
24 changes: 16 additions & 8 deletions sdk_contrib/prisma/test/unit/prisma.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,14 @@ describe('Prisma', function () {
});

describe('capturePrisma', function () {
var client, sandbox;
var client, sandbox, segment;
beforeEach(function () {
xray.enableManualMode();
client = capturePrisma(prisma);

segment = new Segment('test');
client = capturePrisma(prisma, {
segment,
});
sandbox = sinon.createSandbox();
});

Expand Down Expand Up @@ -80,10 +84,12 @@ describe('Prisma', function () {

it('Segment should not be set', function () {
const ns = xray.getNamespace();
assert.Throw(() => {
ns.run(() => {
client.company.create();
});
const error = sinon.stub();
const logger = xray.getLogger();
logger.error = error;
ns.run(async () => {
client.company.create();
assert.isTrue(error.calledOnce);
});
});

Expand Down Expand Up @@ -130,8 +136,10 @@ describe('Prisma', function () {
var client, segment, sandbox;
beforeEach(function () {
xray.enableManualMode();
client = capturePrisma(prisma);
segment = new Segment('test');
client = capturePrisma(prisma, {
segment,
});
sandbox = sinon.createSandbox();
});

Expand Down Expand Up @@ -180,8 +188,8 @@ describe('Prisma', function () {
var client, segment, subsegment, sandbox;
beforeEach(function () {
xray.enableManualMode();
client = capturePrisma(prisma);
segment = new Segment('test');
client = capturePrisma(prisma, { segment });
subsegment = segment.addNewSubsegment('test');
sandbox = sinon.createSandbox();
});
Expand Down

0 comments on commit 4384f9b

Please sign in to comment.