Socket
Socket
Sign inDemoInstall

@cosva-lab/aws-xray-sdk-prisma

Package Overview
Dependencies
0
Maintainers
2
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @cosva-lab/aws-xray-sdk-prisma

AWS X-Ray Patcher for prisma (Javascript)


Version published
Maintainers
2
Created

Readme

Source

Prisma-xray

A prisma plugin to log requests and subsegments through AWSXray.

Screenshot of the AWS X-Ray console

Timeline

Screenshot of the AWS X-Ray console

Requirements

  • AWS X-Ray SDK Core
  • Prisma 4 or greater

AWS X-Ray and Prisma

The AWS X-Ray Prisma package automatically records query information and request and response data. Simply patch the Prisma package via capturePrisma as shown below.

The AWS X-Ray SDK Core has two modes - manual and automatic. Automatic mode uses the cls-hooked package and automatically tracks the current segment and subsegment. This is the default mode. Manual mode requires that you pass around the segment reference. See the examples below.

Automatic mode examples

Screenshot of the AWS X-Ray console

import { PrismaClient } from '@prisma/client';
import AWSXRay from 'aws-xray-sdk';
import { capturePrisma } from 'aws-xray-sdk-prisma';

const ns = AWSXRay.getNamespace();

const prisma = new PrismaClient();

const client = capturePrisma(prisma, { namespace: 'remote' });

const segment = new AWSXRay.Segment('prisma-xray-sample-auto');

ns.run(async () => {
  const subSegment = segment.addNewSubsegment('Prisma');
  AWSXRay.setSegment(subSegment);
  await client.company.upsert({
    create: {
      name: 'Prisma',
      createdAt: new Date(),
    },
    update: {},
    where: {
      id: 1,
    },
  });
  const companies = await client.company.findMany();
  console.log(companies);
  subSegment.close();
  // ...
});

Manual mode examples

Screenshot of the AWS X-Ray console

import { PrismaClient } from '@prisma/client';
import AWSXRay from 'aws-xray-sdk-core';
import { capturePrisma } from 'aws-xray-sdk-prisma';

AWSXRay.enableManualMode();

const prisma = new PrismaClient();

const client = capturePrisma(prisma, { namespace: 'remote' });

const segment = new AWSXRay.Segment('prisma-xray-sample');

const run = async () => {
  const subSegment = segment.addNewSubsegment('Prisma');

  await client.company.upsert(
    {
      create: {
        name: 'Prisma',
        createdAt: new Date(),
      },
      update: {},
      where: {
        id: 1,
      },
    },
    // @ts-ignore
    subSegment
  );
  const companies = await client.company.findMany(
    // @ts-ignore
    subSegment
  );
  console.log(companies);
  subSegment.close();
  // ...
};

run();

Contributors

  • Eduard Castellanos eduard@castellanos.dev, eduard@cosva.app

Keywords

FAQs

Last updated on 22 Nov 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc