add support for opencensus http servlet plugin in spring cloud framework #1650
add support for opencensus http servlet plugin in spring cloud framework #1650
Conversation
check the build failure. |
Codecov Report
@@ Coverage Diff @@
## master #1650 +/- ##
========================================
Coverage ? 82.3%
Complexity ? 1987
========================================
Files ? 294
Lines ? 9179
Branches ? 884
========================================
Hits ? 7555
Misses ? 1336
Partials ? 288
Continue to review full report at Codecov.
|
} | ||
|
||
@Test(timeout = 10000) | ||
public void shouldCreateAServerTrace() throws Exception { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename it to shouldCreateServerTrace
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@Order(1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to order to lower value perhaps org.springframework.core.Ordered.HIGHEST_PRECEDENCE + 10
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rghetia if you are interested in timing information about the HttpRequest then Ordered.Highest_Precedence+10 would give incorrect information. Your filter should be the first filter in the filter chain.
This is also necessary should opencensus in future decide to auto collect the exceptions because 500s usually get caught at the very last Spring filter in the Filter chain. .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used +10 to leave some room for other important filter (may be security related) to precede tracing/monitoring. +10 may be too much. do you have a recommendation here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rghetia we had similar problem in Application insights and there was a discussion around it.
You may want to refer microsoft/ApplicationInsights-Java#766 (comment) for more relevant details.
in short there are some default springboot filters which are responsible for setting error codes, and get the correct timing. It would be very hard to get that details if the filter lies below that in the chain. Therefore HIGHEST_PRECEDENCE is needed imo. But, I am open if you find better alternatives
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would recommend the exact same value that Springs Tracing uses for their filter, unless you expect them both to be there, then maybe an additional + 1
static final int TRACING_FILTER_ORDER = Ordered.HIGHEST_PRECEDENCE + 5;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SG. I'll make the change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Component | ||
@Order(OpenCensusAutoConfiguration.TRACE_FILTER_ORDER) | ||
@SuppressFBWarnings("RI_REDUNDANT_INTERFACES") | ||
public class HttpServletFilter extends OcHttpServletFilter implements Filter {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An alternative to using the Servet filter would be to use a Spring MVC interceptor and the WebMvcConfigurer
. We did this for including the trace id in the logs. The same concept applies to this PR. Take a look in our code here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the review. Is Servlet filter approach still ok? The reason I asked is the most of the work for servlet filter is done and usable outside of the spring frame work as well. But if there are advantages of doing it using MVC interceptor i am can certainly change it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, Servlet Filter is more generic.
...ud/core/src/main/java/io/opencensus/contrib/springcloud/autoconfig/OpenCensusProperties.java
Outdated
Show resolved
Hide resolved
all/build.gradle
Outdated
@@ -19,6 +19,7 @@ def subprojects = [ | |||
project(':opencensus-contrib-log-correlation-stackdriver'), | |||
project(':opencensus-contrib-monitored-resource-util'), | |||
project(':opencensus-contrib-spring'), | |||
project(':opencensus-contrib-spring-cloud-core'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be part of the opencensus-contrib-spring?
@EnableConfigurationProperties(OpenCensusProperties.class) | ||
@ExperimentalApi | ||
public class OpenCensusAutoConfiguration { | ||
public static final int TRACE_FILTER_ORDER = Ordered.HIGHEST_PRECEDENCE + 10; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment about what this field represents?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It represents the order in which HttpServletFilter will be invoked. I have added comments as to what it is in the new update.
5af99c5
to
37de0e7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dinooliva and @bogdandrutu PTAL.
@EnableConfigurationProperties(OpenCensusProperties.class) | ||
@ExperimentalApi | ||
public class OpenCensusAutoConfiguration { | ||
public static final int TRACE_FILTER_ORDER = Ordered.HIGHEST_PRECEDENCE + 10; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It represents the order in which HttpServletFilter will be invoked. I have added comments as to what it is in the new update.
*/ | ||
@Configuration | ||
@ComponentScan(basePackages = "io.opencensus") | ||
@ConditionalOnProperty(value = "spring.opencensus.enabled", matchIfMissing = true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should be careful to use the same property namespaces as spring projects. The spring teams did a bunch of work to consolidate their use of properties to mostly be under spring.
so that the community could have other areas. I would suggest you make opencensus
the top level namespace
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll change the name.
What do we need to ship this? |
Need to add ability to specify propagator, extractor and publicEndpoint. |
As discussed irl, agree that we don't need to separate controls for tracing and metrics. |
@dinooliva and @bogdandrutu PTAL. |
No description provided.