question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Web skip patterns don't consider server.servlet.context-path

See original GitHub issue

The SkipPatternProvider made in auto-configuration considers when management.server.servlet.context-path is set, but it does not consider when just server.sevlet.context-path is set.

https://github.com/spring-cloud/spring-cloud-sleuth/blob/434e06c3ce4c6471cb77e88ee317390dfc22c4bf/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/web/TraceWebAutoConfiguration.java#L49-L96

The following test demonstrates this issue and will fail with current snapshots:

@RunWith(SpringRunner.class)
@SpringBootTest(classes = DemoSleuthSkipApplicationTests.Config.class,
		webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
		properties = {"spring.sleuth.sampler.probability:1",
				"management.endpoints.web.exposure.include:*",
				"server.servlet.context-path:/context-path"})
public class DemoSleuthSkipApplicationTests {

	@Autowired
	ArrayListSpanReporter accumulator;

	@LocalServerPort
	int port;

	@Test
	public void should_not_sample_skipped_endpoint_with_context_path() {
		new RestTemplate().getForObject("http://localhost:" + port + "/context-path/actuator/health", String.class);
		then(Tracing.current().tracer().currentSpan()).isNull();
		then(this.accumulator.getSpans()).hasSize(0); // this fails
	}

	@EnableAutoConfiguration
	@Configuration
	public static class Config {

		@Bean ArrayListSpanReporter reporter() {
			return new ArrayListSpanReporter();
		}
	}
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
shakuzencommented, Nov 26, 2018

Looks like there is still a problem with the fix. Now I’m seeing all endpoints get skipped when a server.servlet.context-path is set (because it is appended to the end of the pattern like |context-path.*). Below is a patch for the integration test that demonstrates the issue.

Index: spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/web/issues/issue971/DemoSleuthSkipApplicationTests.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/web/issues/issue971/DemoSleuthSkipApplicationTests.java	(revision 26417a27079bf353cacdfd25eed8e29b741d1893)
+++ spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/web/issues/issue971/DemoSleuthSkipApplicationTests.java	(date 1543217273000)
@@ -30,6 +30,8 @@
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.client.RestTemplate;
 
 import static org.assertj.core.api.BDDAssertions.then;
@@ -60,11 +62,26 @@
 		then(this.accumulator.getSpans()).hasSize(0);
 	}
 
+	@Test
+	public void should_sample_non_actuator_endpoint_with_context_path() {
+		new RestTemplate().getForObject(
+				"http://localhost:" + this.port + "/context-path/something",
+				String.class);
+
+		then(this.tracer.currentSpan()).isNull();
+		then(this.accumulator.getSpans()).hasSize(1);
+	}
+
 	@EnableAutoConfiguration(exclude = RabbitAutoConfiguration.class)
 	@Configuration
 	@DisableSecurity
+	@RestController
 	public static class Config {
 
+		@GetMapping("something")
+		void doNothing() {
+		}
+
 		@Bean
 		ArrayListSpanReporter reporter() {
 			return new ArrayListSpanReporter();
0reactions
mellowarecommented, Nov 27, 2018

I opened a new issue: https://github.com/spring-cloud/spring-cloud-sleuth/issues/1146

In there I posted my “hack” workaround.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Context Path vs. Servlet Path in Spring - Baeldung
Simply put, the context path is a name with which a web application is accessed. It is the root of the application. By...
Read more >
Web on Servlet Stack - Spring
Spring Web MVC is the original web framework built on the Servlet API and has ... is designed around the front controller pattern...
Read more >
Spring Boot not serving static content - Stack Overflow
The class that is responsible for resolving the path, as of Spring 4.1, is org.springframework.web.servlet.resource.PathResourceResolver . Suffix pattern ...
Read more >
Defining Tomcat context paths - Octopus Deploy
The context path of a web application defines the URL that end users will ... that is recognised by Java application servers like...
Read more >
Apache Tomcat 9 Configuration Reference (9.0.70)
The Context element represents a web application, which is run within a ... all requests that do not match any other Context's context...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found