npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

prisma-axiom

v0.2.1

Published

Axiom observability middleware for Prisma

Downloads

38

Readme

prisma-axiom CI

Axiom observability middleware for Prisma.

Quickstart

  1. Install prisma-axiom
npm install --save prisma-axiom
  1. Wrap your main functions in withAxiom to automatically set up telemetry and flush traces before exit.
import withAxiom from 'prisma-axiom';
const prisma = new PrismaClient();

async function main() {
  // do something with prisma
}

withAxiom(main)() // wrap function 

Note: This will configure Axiom from the AXIOM_TOKEN and other environment variables. Check out the Kitchen Sink Full Configuration for more advanced configuration.

  1. Enable the prisma tracing preview feature in schema.prisma like this:
generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["tracing"]
}

Kitchen Sink Full Configuration

Import and use withAxiom to automatically setup & configure OpenTelemetry with the Prisma instrumentation sending traces to Axiom.

You can configure prisma-axiom by passing an options object as the second parameter to withAxiom.

This snippet shows all available options:

const myFn = withAxiom(myFn, {
  axiomToken:                 "xaat-xxxxx",
  axiomUrl:                   "https://my-axiom.example.org",
  additionalInstrumentations: [new HttpInstrumentation()] // add more instrumentations to the tracing setup
});

Custom Configuration

When you have your OpenTelemetry setup you can use the Axiom's exporter, and attach it to the provider. See the extend-otel example for more details.

The exporter can automatically retreive the Axiom token and url variables from AXIOM_URL and AXIOM_TOKEN respectively, but they can also be passed as parameters.

This is what it could look like:

import { axiomTraceExporter } from 'prisma-axiom';

const provider = new NodeTracerProvider({
  resource: new Resource({
    [SemanticResourceAttributes.SERVICE_NAME]: process.env.npm_package_name,
    [SemanticResourceAttributes.SERVICE_VERSION]: process.env.npm_package_version,
  }),
})

// create axiom's exporter object and add a new span processor:
const exporter = axiomTraceExporter();
provider.addSpanProcessor(new BatchSpanProcessor(exporter));
provider.register()

registerInstrumentations({
  instrumentations: [new PrismaInstrumentation(), new HttpInstrumentation()],
});

function main () {
  // ...
}

// shutdown the provider to ensure delivery
main().finally(async () => {
  await provider.shutdown()
})

FAQ & Troubleshooting

I don't get any traces

Enable tracing preview in Prisma

As tracing support for Prisma is in preview, you need to explicitly enable it. See Quickstart step 3, schema.prisma has to be altered like this:

generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["tracing"]
}

Also note that this preview feature is only available starting with Prisma v4.2.0.

License

© Axiom, Inc., 2022

Distributed under MIT License (The MIT License).

See LICENSE for more information.