Skip to content

Commit b48d46a

Browse files
committed
Use vendored types.
1 parent 3dddac1 commit b48d46a

File tree

2 files changed

+255
-62
lines changed

2 files changed

+255
-62
lines changed

packages/node/src/integrations/hapi/index.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,13 @@ function sendErrorToSentry(errorData: object): void {
3636
export const hapiErrorPlugin = {
3737
name: 'SentryHapiErrorPlugin',
3838
version: '0.0.1',
39-
register: async function (server: Server) {
39+
register: async function (serverArg: Record<any, any>) {
40+
const server = serverArg as unknown as Server;
41+
4042
server.events.on('request', (request, event) => {
4143
const transaction = getActiveTransaction();
4244

43-
if (isBoomObject(request.response)) {
45+
if (request.response && isBoomObject(request.response)) {
4446
sendErrorToSentry(request.response);
4547
} else if (isErrorEvent(event)) {
4648
sendErrorToSentry(event.error);
@@ -57,7 +59,9 @@ export const hapiErrorPlugin = {
5759
export const hapiTracingPlugin = {
5860
name: 'SentryHapiTracingPlugin',
5961
version: '0.0.1',
60-
register: async function (server: Server) {
62+
register: async function (serverArg: Record<any, any>) {
63+
const server = serverArg as unknown as Server;
64+
6165
server.ext('onPreHandler', (request, h) => {
6266
const transaction = continueTrace(
6367
{
@@ -68,8 +72,8 @@ export const hapiTracingPlugin = {
6872
return startTransaction({
6973
...transactionContext,
7074
op: 'hapi.request',
71-
name: request.path,
72-
description: request.route ? request.route.path : '',
75+
name: request.route.path,
76+
description: `${request.route.method} ${request.path}`,
7377
});
7478
},
7579
);
@@ -84,7 +88,7 @@ export const hapiTracingPlugin = {
8488
server.ext('onPreResponse', (request, h) => {
8589
const transaction = getActiveTransaction();
8690

87-
if (isResponseObject(request.response) && transaction) {
91+
if (request.response && isResponseObject(request.response) && transaction) {
8892
const response = request.response as ResponseObject;
8993
response.header('sentry-trace', transaction.toTraceparent());
9094

@@ -93,7 +97,7 @@ export const hapiTracingPlugin = {
9397
);
9498

9599
if (dynamicSamplingContext) {
96-
response.header('sentry-baggage', dynamicSamplingContext);
100+
response.header('baggage', dynamicSamplingContext);
97101
}
98102
}
99103

@@ -103,7 +107,7 @@ export const hapiTracingPlugin = {
103107
server.ext('onPostHandler', (request, h) => {
104108
const transaction = getActiveTransaction();
105109

106-
if (isResponseObject(request.response) && transaction) {
110+
if (request.response && isResponseObject(request.response) && transaction) {
107111
transaction.setHttpStatus(request.response.statusCode);
108112
}
109113

@@ -118,7 +122,7 @@ export const hapiTracingPlugin = {
118122

119123
export type HapiOptions = {
120124
/** Hapi server instance */
121-
server?: Server;
125+
server?: Record<any, any>;
122126
};
123127

124128
/**
@@ -139,7 +143,9 @@ export class Hapi implements Integration {
139143

140144
public constructor(options?: HapiOptions) {
141145
if (options?.server) {
142-
this._hapiServer = options.server;
146+
const server = options.server as unknown as Server;
147+
148+
this._hapiServer = server;
143149
}
144150

145151
this.name = Hapi.id;

0 commit comments

Comments
 (0)