Skip to content

Commit

Permalink
Customize the order of main filter
Browse files Browse the repository at this point in the history
  • Loading branch information
IvoMajic committed Feb 28, 2024
1 parent ad7c5ea commit 4940910
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
.idea/**/dictionaries
.idea/**/shelf

.DS_Store

# AWS User-specific
.idea/**/aws.xml

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ Configure the following properties in your `application.properties` file:
treblle.endpoint=<OPTIONAL_ENDPOINT_URL> # Default is https://rocknrolla.treblle.com
treblle.apiKey=<API_KEY>
treblle.projectId=<PROJECT_ID>
treblle.filter-order=<ORDER_OF_TREBLLE_FILTER> # Default Ordered.LOWEST_PRECEDENCE - 10, similar to Springs HttpTraceFilter
```

In case you are using the `application.yml` file:
Expand All @@ -128,6 +129,7 @@ treblle:
endpoint: <OPTIONAL_ENDPOINT_URL> # Default is https://rocknrolla.treblle.com
api-key: <API_KEY>
project-id: <PROJECT_ID>
treblle.filter-order: <ORDER_OF_TREBLLE_FILTER> # Default Ordered.LOWEST_PRECEDENCE - 10, similar to Springs HttpTraceFilter
```
That's it. Your API requests and responses are now being sent to your Treblle project.
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.treblle</groupId>
<artifactId>treblle-spring-boot-starter</artifactId>
<version>2.0.1</version>
<version>2.0.2</version>
<name>treblle-spring-boot-starter</name>
<description>Official Treblle Starter for Spring Boot</description>
<url>https://github.com/Treblle/treblle-spring</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,19 @@
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.scheduling.annotation.EnableAsync;

@Configuration
@EnableAsync
@EnableConfigurationProperties(TreblleProperties.class)
public class TreblleAutoConfiguration {

private final TreblleProperties treblleProperties;

public TreblleAutoConfiguration(TreblleProperties treblleProperties) {
this.treblleProperties = treblleProperties;
}

@Bean
public TreblleService treblleService() {
return new TreblleServiceImpl();
Expand All @@ -31,7 +36,7 @@ public JsonMasker jsonMasker() {
public FilterRegistrationBean<TreblleFilter> filterRegistration(TreblleProperties properties, TreblleService treblleService) {
final FilterRegistrationBean<TreblleFilter> registrationBean = new FilterRegistrationBean<>();
registrationBean.setFilter(new TreblleFilter(treblleService));
registrationBean.setOrder(Ordered.LOWEST_PRECEDENCE - 10); // Similar to HttpTraceFilter
registrationBean.setOrder(treblleProperties.getFilterOrder());
if (!properties.getUrlPatterns().isEmpty()) {
registrationBean.setUrlPatterns(properties.getUrlPatterns());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import java.util.Collections;
import java.util.List;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.core.Ordered;

@ConfigurationProperties(prefix = "treblle")
public class TreblleProperties {

private String endpoint;
private String apiKey;
private String projectId;
private Integer filterOrder = Ordered.LOWEST_PRECEDENCE - 10; // Similar to HttpTraceFilter
private List<String> urlPatterns = Collections.emptyList();
private List<String> maskingKeywords = Collections.emptyList();

Expand Down Expand Up @@ -37,6 +39,14 @@ public void setProjectId(String projectId) {
this.projectId = projectId;
}

public Integer getFilterOrder() {
return filterOrder;
}

public void setFilterOrder(Integer filterOrder) {
this.filterOrder = filterOrder;
}

public List<String> getUrlPatterns() {
return urlPatterns;
}
Expand Down

0 comments on commit 4940910

Please sign in to comment.