getsentry / getsentry/sentry-javascript

Expand SentryTracingInterceptor to ws context

オープン
#13,810 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る
Improvement Meta: Good First Issue Nest.js
主要言語
TypeScript
スター
8.7k
フォーク
1.8k
平均マージ
1日 17時間
マージ済み PR(30日)
515

説明

### 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

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。