66 type CallHandler ,
77 Logger ,
88} from '@nestjs/common' ;
9+ import * as Sentry from '@sentry/nestjs' ;
910import { trace } from '@opentelemetry/api' ;
1011import type { Response } from 'express' ;
1112import { ClsService } from 'nestjs-cls' ;
@@ -17,6 +18,36 @@ export const X_TEABLE_V2_HEADER = 'x-teable-v2';
1718export const X_TEABLE_V2_REASON_HEADER = 'x-teable-v2-reason' ;
1819export const X_TEABLE_V2_FEATURE_HEADER = 'x-teable-v2-feature' ;
1920
21+ type SentryScopeLike = {
22+ setTag ( key : string , value : string ) : void ;
23+ } ;
24+
25+ const getSentryScopes = ( ) : SentryScopeLike [ ] => {
26+ const sentryApi = Sentry as unknown as {
27+ getCurrentScope ?: ( ) => SentryScopeLike | undefined ;
28+ getIsolationScope ?: ( ) => SentryScopeLike | undefined ;
29+ getCurrentHub ?: ( ) => { getScope ?: ( ) => SentryScopeLike | undefined } ;
30+ } ;
31+
32+ const scopes = [
33+ sentryApi . getCurrentScope ?.( ) ,
34+ sentryApi . getIsolationScope ?.( ) ,
35+ sentryApi . getCurrentHub ?.( ) ?. getScope ?.( ) ,
36+ ] . filter ( ( scope ) : scope is SentryScopeLike => Boolean ( scope ) ) ;
37+
38+ return [ ...new Set ( scopes ) ] ;
39+ } ;
40+
41+ const setSentryTag = ( key : string , value : string | undefined ) => {
42+ if ( value == null ) {
43+ return ;
44+ }
45+
46+ for ( const scope of getSentryScopes ( ) ) {
47+ scope . setTag ( key , value ) ;
48+ }
49+ } ;
50+
2051/**
2152 * Interceptor that adds V2 indicator to response headers and logs.
2253 * When a request uses V2 implementation (determined by V2FeatureGuard),
@@ -51,6 +82,12 @@ export class V2IndicatorInterceptor implements NestInterceptor {
5182 response . setHeader ( X_TEABLE_V2_FEATURE_HEADER , v2Feature ) ;
5283 }
5384
85+ // Mirror V2 indicators into Sentry tags so issue search can distinguish v1/v2 requests.
86+ setSentryTag ( 'teable.version' , useV2 ? 'v2' : 'v1' ) ;
87+ setSentryTag ( 'teable.v2.enabled' , useV2 ? 'true' : 'false' ) ;
88+ setSentryTag ( 'teable.v2.reason' , v2Reason ) ;
89+ setSentryTag ( 'teable.v2.feature' , v2Feature ) ;
90+
5491 // Add span attributes for tracing
5592 const span = trace . getActiveSpan ( ) ;
5693 if ( span ) {
0 commit comments