-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SELC-4749] feat: added interceptor for log request and response, add…
…ed custom log in methods (#120)
- Loading branch information
1 parent
c270c9c
commit 6eeea9f
Showing
10 changed files
with
86 additions
and
6 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
...ser-ms/src/main/java/it/pagopa/selfcare/user/filter/CustomClientRequestLoggingFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package it.pagopa.selfcare.user.filter; | ||
|
||
|
||
import jakarta.ws.rs.client.ClientRequestContext; | ||
import jakarta.ws.rs.ext.Provider; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.jboss.resteasy.reactive.client.spi.ResteasyReactiveClientRequestContext; | ||
import org.jboss.resteasy.reactive.client.spi.ResteasyReactiveClientRequestFilter; | ||
|
||
import java.io.IOException; | ||
|
||
@Provider | ||
@Slf4j | ||
public class CustomClientRequestLoggingFilter implements ResteasyReactiveClientRequestFilter { | ||
|
||
@Override | ||
public void filter(ClientRequestContext requestContext) throws IOException { | ||
ResteasyReactiveClientRequestFilter.super.filter(requestContext); | ||
} | ||
|
||
@Override | ||
public void filter(ResteasyReactiveClientRequestContext requestContext) { | ||
String endpoint = requestContext.getUri().getPath(); | ||
String query = requestContext.getUri().getQuery(); | ||
String method = requestContext.getMethod(); | ||
MDCUtils.addOperationIdAndParameters(method); | ||
log.info("Request: method: {}, endpoint: {}, query: {}", method, endpoint, query); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...er-ms/src/main/java/it/pagopa/selfcare/user/filter/CustomClientResponseLoggingFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package it.pagopa.selfcare.user.filter; | ||
|
||
|
||
import jakarta.ws.rs.client.ClientRequestContext; | ||
import jakarta.ws.rs.client.ClientResponseContext; | ||
import jakarta.ws.rs.ext.Provider; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.jboss.resteasy.reactive.client.spi.ResteasyReactiveClientRequestContext; | ||
import org.jboss.resteasy.reactive.client.spi.ResteasyReactiveClientResponseFilter; | ||
import org.slf4j.MDC; | ||
|
||
@Provider | ||
@Slf4j | ||
public class CustomClientResponseLoggingFilter implements ResteasyReactiveClientResponseFilter { | ||
|
||
@Override | ||
public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) { | ||
ResteasyReactiveClientResponseFilter.super.filter(requestContext, responseContext); | ||
} | ||
|
||
@Override | ||
public void filter(ResteasyReactiveClientRequestContext requestContext, ClientResponseContext responseContext) { | ||
String endpoint = requestContext.getUri().getPath(); | ||
String query = requestContext.getUri().getQuery(); | ||
String method = requestContext.getMethod(); | ||
int status = responseContext.getStatus(); | ||
log.info("Response: method: {}, endpoint: {}, query: {}, status [{}]", method, endpoint, query, status); | ||
MDC.clear(); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
apps/user-ms/src/main/java/it/pagopa/selfcare/user/filter/MDCUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package it.pagopa.selfcare.user.filter; | ||
|
||
import org.slf4j.MDC; | ||
|
||
public class MDCUtils { | ||
|
||
public static void addOperationIdAndParameters(String operationId) { | ||
MDC.put("sc_operation_id", operationId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters