Skip to content

Commit

Permalink
chore: Update la gestion du scope pour sentry v8
Browse files Browse the repository at this point in the history
  • Loading branch information
Mintoo200 committed May 16, 2024
1 parent 5e4cbdd commit dc8c02d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/client/services/bff.httpClient.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export class BffHttpClientService implements HttpClientService {
(request: InternalAxiosRequestConfig) => {
const transactionId = uuid4();
request.headers['x-transaction-id'] = transactionId;
// FIXME (GAFI 16-05-2024): On est d'accord que là, si j'ai 2 requêtes qui partent coup sur coup, le transactionId
// de la première est écrasé par la seconde ?
this.logger.setTransactionId(transactionId);
return request;
},
Expand Down
4 changes: 1 addition & 3 deletions src/client/services/logger.service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ const SentryMock = jest.mocked(Sentry, { shallow: true });
const SentryScopeMock = {
setTag: jest.fn(),
} as unknown as Sentry.Scope;
SentryMock.configureScope.mockImplementation((callback) => {
callback(SentryScopeMock);
});
SentryMock.getCurrentScope.mockReturnValue(SentryScopeMock);

describe('LoggerService', () => {
const sessionId = 'ma-session-id';
Expand Down
10 changes: 4 additions & 6 deletions src/client/services/logger.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import * as Sentry from '@sentry/nextjs';

export class LoggerService {
constructor(sessionId?: string) {
Sentry.configureScope((scope: Sentry.Scope) => {
scope.setTag('session_id', sessionId);
});
const scope = Sentry.getCurrentScope();
scope.setTag('session_id', sessionId);
}

private static log(
Expand All @@ -27,8 +26,7 @@ export class LoggerService {
}

setTransactionId(transactionId: string): void {
Sentry.configureScope((scope) => {
scope.setTag('transaction_id', transactionId);
});
const scope = Sentry.getCurrentScope();
scope.setTag('transaction_id', transactionId);
}
}

0 comments on commit dc8c02d

Please sign in to comment.