getsentry / getsentry/sentry-javascript

Expand SentryTracingInterceptor to ws context

Đang mở
#13,810 2 bình luận 0 reaction 0 người được giao Xem trên GitHub
Improvement Meta: Good First Issue Nest.js
Ngôn ngữ chính
TypeScript
Star
8.7k
Fork
1.8k
Merge trung bình
1 ngày 17 giờ
Pull request đã merge (30 ngày)
523

Mô tả

### Problem Statement

Nestjs supports [websocket gateway](https://docs.nestjs.com/websockets/gateways). It would be nice to have built in tracing interceptor like sentry has for http requests

### Solution Brainstorm

This is implementation which we wrote in our project

```typescript
import { CallHandler, ExecutionContext, NestInterceptor } from '@nestjs/common';
import * as Sentry from '@sentry/core';
import { Observable } from 'rxjs';
import { tap } from 'rxjs';

export class SentryWsTracingInterceptor implements NestInterceptor {
/**
* Intercepts WS requests to set the transaction name for Sentry tracing.
*/
public intercept(
context: ExecutionContext,
next: CallHandler,
): Observable {
if (context.getType() === 'ws') {
const client = context.switchToWs().getClient();
const pattern = context.switchToWs().getPattern();
Sentry.getIsolationScope().setTransactionName(
`WS ${client.nsp.name} ${pattern}`,
);

return Sentry.startSpanManual(
{
op: 'ws',
name: `WS ${client.nsp.name} ${pattern}`,
},
(span) => {
return next.handle().pipe(
tap({
finalize: () => span.end(),
}),
);
},
);
}

return next.handle();
}
}
```

### Product Area

Profiling

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.