Skip to content

Supportability of the Hapi Framework Integration #9344

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Angelodaniel opened this issue Oct 24, 2023 · 2 comments · Fixed by #9539
Closed

Supportability of the Hapi Framework Integration #9344

Angelodaniel opened this issue Oct 24, 2023 · 2 comments · Fixed by #9539
Assignees
Labels
Sync: Jira apply to auto-create a Jira shadow ticket Type: Improvement

Comments

@Angelodaniel
Copy link
Member

Angelodaniel commented Oct 24, 2023

Problem Statement

We are using Hapi as framework in our backends. From what I understand there is no official plugin for integrating Hapi with Sentry (on the same level as there is for Express compatible frameworks).

I want to be able to have a distributed trace between my frontends and backend that is using Hapi which is not supported right now.

The main goal is to be able to identify problems that occur in the backends and also to be able to track any related problems in the frontends to the corresponding backend problem.

Solution Brainstorm

It could be possible to have this with the help of the node-opentelemetry for hapi -> https://www.npmjs.com/package/@opentelemetry/instrumentation-hapi

┆Issue is synchronized with this Jira Improvement by Unito

@mydea
Copy link
Member

mydea commented Oct 24, 2023

We can add this to node-experimental (soon to be node-opentelemetry), via a new Hapi integration that wraps @opentelemetry/instrumentation-hapi similar to the other integrations we have there. this should give you tracing OOTB.

@getsantry getsantry bot removed the status in GitHub Issues with 👀 Oct 24, 2023
@Angelodaniel Angelodaniel added the Sync: Jira apply to auto-create a Jira shadow ticket label Oct 25, 2023
mydea pushed a commit that referenced this issue Dec 18, 2023
Resolves: #9344 

Adds a new node integration for Hapi framework.

Also exports a Hapi plugin to capture errors when the tracing
instrumentation from `node-experimental` is used.

Can be used with `node-experimental` ([Sample Error
Event](https://sentry-sdks.sentry.io/issues/4624554372/?project=4506162118983680&query=is%3Aunresolved&referrer=issue-stream&statsPeriod=1h&stream_index=0))
like:

```typescript
const Sentry = require('@sentry/node-experimental');

Sentry.init({
  dsn: '__DSN__',
  tracesSampleRate: 1.0,
});

const Hapi = require('@hapi/hapi');

const init = async () => {
    const server = Hapi.server({
        port: 3000,
        host: 'localhost'
    });

    await server.register(Sentry.hapiErrorPlugin)

    server.route({
        method: 'GET',
        path: '/',
        handler: (request, h) => {
            throw new Error('My Hapi Sentry error!');
        }
    });

    await server.start();
};
```

Also can be used from `@sentry/node` with tracing ([Errored
Transaction](https://sentry-sdks.sentry.io/performance/node-hapi:8a633340fc724472bb44aae4c7572827/?project=4506162118983680&query=&referrer=performance-transaction-summary&statsPeriod=1h&transaction=%2F&unselectedSeries=p100%28%29&unselectedSeries=avg%28%29),
[Successful
Transaction](https://sentry-sdks.sentry.io/performance/node-hapi:deeb79f0c6bf41c68c776833c4629e6e/?project=4506162118983680&query=&referrer=performance-transaction-summary&statsPeriod=1h&transaction=%2F&unselectedSeries=p100%28%29&unselectedSeries=avg%28%29))
and error tracking
([Event](https://sentry-sdks.sentry.io/issues/4626919129/?project=4506162118983680&query=is%3Aunresolved&referrer=issue-stream&statsPeriod=1h&stream_index=0))
like:

```typescript
'use strict';

const Sentry = require('@sentry/node');
const Hapi = require('@hapi/hapi');


const init = async () => {
    const server = Hapi.server({
        port: 3000,
        host: 'localhost'
    });

    Sentry.init({
      dsn: '__DSN__',
      tracesSampleRate: 1.0,
      integrations: [
        new Sentry.Integrations.Hapi({server}),
      ],
      debug: true,
    });

    server.route({
        method: 'GET',
        path: '/',
        handler: (request, h) => {
            return 'Hello World!';
        }
    });

    await server.start();
};
```
@AbhiPrasad
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Sync: Jira apply to auto-create a Jira shadow ticket Type: Improvement
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants