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

@rlanz/sentry

v0.1.0

Published

A wrapper around the Sentry SDK to make it easier to use in a AdonisJS application

Downloads

2,731

Readme

typescript-image gh-workflow-image npm-image npm-download-image license-image

@rlanz/sentry is a simple wrapper around the Sentry SDK to make it easier to use in a AdonisJS application.

Installation

node ace add @rlanz/sentry

Usage

The package will automatically register a middleware, configure the Sentry SDK and add an instance of the SDK to the IoC Container and the HttpContext.

import type { HttpContext } from '@adonisjs/core/http'

export default class HelloController {
  greet({ params, sentry, response}: HttpContext) {
    sentry.captureMessage(`Hello, ${params.name}!`)

    return response.ok({ message: `Hello, ${params.name}!` })
  }
}

Since the SDK is also added to the IoC Container, you can also use it in your services. If you are inside a request context, the SDK injected will be scoped to it.

import { inject } from '@adonisjs/core'
import { Sentry } from '@rlanz/sentry'

@inject()
export class GreetingService {
  constructor(private sentry: Sentry) {}
  
  greet(name: string) {
    this.sentry.captureMessage(`Hello, ${name}!`)
    
    return `Hello, ${name}!`
  }
}

Capturing Errors

You can capture errors by calling the captureException method on the SDK instance inside your exception handler.

export default class HttpExceptionHandler extends ExceptionHandler {
  // ...

  async report(error: unknown, ctx: HttpContext) {
    if (this.shouldReport(error as any)) {
      ctx.sentry.captureException(error)
    }

    return super.report(error, ctx)
  }
}

Assigning User Context

You can assign user context to the Sentry SDK by calling the setUser method on the SDK instance once you are logged in.

export default class SilentAuthMiddleware {
  async handle(ctx: HttpContext, next: NextFn) {
    // We are authenticating the user
    await ctx.auth.check()

    // If the user is authenticated, we assign the user context to Sentry
    if (ctx.auth.isAuthenticated) {
      const user = ctx.auth.getUserOrFail()
      
      ctx.sentry.setUser({
        id: user.id, 
        email: user.email, 
        username: user.username,
      });
    }
    
    return await next();
  }
}

Adding Integrations

Sentry provides multiple integrations to enhance the data captured by the SDK. You can add integrations by changing the integrations array inside the configuration config/sentry.ts.

For example, if you want to add profiling to your application, you can add the Profiler integration.

npm install @sentry/profiling-node
// config/sentry.ts

import { nodeProfilingIntegration } from '@sentry/profiling-node';

export default defineConfig({
  // ...
  integrations: [nodeProfilingIntegration()],
  profilesSampleRate: 0.2,
})