Skip to content
This repository has been archived by the owner on Dec 23, 2023. It is now read-only.

add support for opencensus http servlet plugin in spring cloud framework #1650

Merged
merged 7 commits into from May 18, 2019

Conversation

rghetia
Copy link
Contributor

@rghetia rghetia commented Jan 4, 2019

No description provided.

@rghetia
Copy link
Contributor Author

rghetia commented Jan 4, 2019

check the build failure.

@codecov-io
Copy link

codecov-io commented Jan 4, 2019

Codecov Report

❗ No coverage uploaded for pull request base (master@8312f0e). Click here to learn what that means.
The diff coverage is 14.28%.

Impacted file tree graph

@@           Coverage Diff            @@
##             master   #1650   +/-   ##
========================================
  Coverage          ?   82.3%           
  Complexity        ?    1987           
========================================
  Files             ?     294           
  Lines             ?    9179           
  Branches          ?     884           
========================================
  Hits              ?    7555           
  Misses            ?    1336           
  Partials          ?     288
Impacted Files Coverage Δ Complexity Δ
...spring/autoconfig/OpenCensusAutoConfiguration.java 0% <0%> (ø) 0 <0> (?)
...ontrib/spring/autoconfig/OpenCensusProperties.java 0% <0%> (ø) 0 <0> (?)
...ntrib/spring/instrument/web/HttpServletFilter.java 100% <100%> (ø) 1 <1> (?)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8312f0e...e9cc809. Read the comment docs.

}

@Test(timeout = 10000)
public void shouldCreateAServerTrace() throws Exception {
Copy link
Contributor Author

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)
Copy link
Contributor Author

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

Copy link

@dhaval24 dhaval24 Jan 8, 2019

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. .

Copy link
Contributor Author

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?

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

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;

Copy link
Contributor Author

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.

Copy link

@dhaval24 dhaval24 Jan 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@devinsba yes your suggestion looks more apt. @rghetia I would recommend this change.

@Component
@Order(OpenCensusAutoConfiguration.TRACE_FILTER_ORDER)
@SuppressFBWarnings("RI_REDUNDANT_INTERFACES")
public class HttpServletFilter extends OcHttpServletFilter implements Filter {}

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.

Copy link
Contributor Author

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.

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.

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'),
Copy link
Contributor

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;
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

@rghetia rghetia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@EnableConfigurationProperties(OpenCensusProperties.class)
@ExperimentalApi
public class OpenCensusAutoConfiguration {
public static final int TRACE_FILTER_ORDER = Ordered.HIGHEST_PRECEDENCE + 10;
Copy link
Contributor Author

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)

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

Copy link
Contributor Author

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.

@bogdandrutu
Copy link
Contributor

What do we need to ship this?

@rghetia
Copy link
Contributor Author

rghetia commented May 13, 2019

What do we need to ship this?

Need to add ability to specify propagator, extractor and publicEndpoint.
Also needs ability to enable just one tracing or metrics but not both. In the current implementation it does both. This can probably wait.

@dinooliva
Copy link
Contributor

As discussed irl, agree that we don't need to separate controls for tracing and metrics.

@rghetia
Copy link
Contributor Author

rghetia commented May 16, 2019

@dinooliva and @bogdandrutu PTAL.

@rghetia rghetia merged commit a95cc72 into census-instrumentation:master May 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants