I'm trying to integrate sleuth into a Spring Boot application so that it will talk to a zipkin server for tracing, but I'm not having much luck.
I've followed a few tutorials (link to tutorial) and have no problems getting them to talk to zipkin, but it's not translating well to my application, and I'm not sure where to look.
essentially, in the build.gradle file, to the dependencies section, I added:
compile('org.springframework.cloud:spring-cloud-starter-sleuth')
compile("org.springframework.cloud:spring-cloud-sleuth-zipkin")
In the controller, I added these two beans:
#Bean
public RestTemplate getRestTemplate() {
return new RestTemplate();
}
#Bean
public AlwaysSampler defaultSampler() {
return new AlwaysSampler();
}
and, I added these to the application.properties file:
spring.application.name=pie2-lcp-endpoints
logging.level.org.springframework.web.servlet.DispatcherServlet=DEBUG
When I do all that in the demos, they send traces to my Zipkin host at localhost:4911 just fine (For the time being, I'm just running the quickstart jar file).
When I do all that in my application, I see that I have sleuth log entries with strings like:
[pie2-partner-integration,768070516213fc75,768070516213fc75,true]
so, I know that Sleuth is working.
When I run a demo app with the zipkin server application shut off, the application looks like it's working fine, but, reasonably enough, the log files show a big old ConnectionRefused stack trace.
When I try the same experiment with my application, I see no stack trace in my application logs, and the application also ran just fine.
Outside of my larger application, I can't reproduce my problem, and I don't know what else to share with you. Anyone have any suggestions about where to start?
*sigh, so it turns out, that someone had turned off zipking tracing in a properties file, for no good reason.
*sigh
Related
I have configured the following in my application but i cant seem to get some metrics from http.servlet.request published to datadog.
Spring 2.7.1
implementation("com.datadoghq:dd-trace-ot:0.98.1")
implementation("com.datadoghq:dd-trace-api:0.98.1")
implementation("io.micrometer:micrometer-core:1.9.2")
implementation("io.micrometer:micrometer-registry-statsd:1.9.2")
My props is as follows
management.endpoint.health.probes.enabled=true
management.metrics.export.datadog.step=1m
management.metrics.distribution.percentiles-histogram.http.server.requests=true
management.metrics.export.datadog.descriptions=true
management.metrics.web.server.request.autotime.enabled=true
management.endpoint.metrics.enabled=true
management.metrics.enable.logback=true
management.metrics.tags.application=my-app
management.metrics.export.statsd.enabled=true
management.metrics.export.statsd.host=${DD_HOST}
management.metrics.export.statsd.flavor=datadog
management.metrics.export.statsd.port=8125
So i can see http.servlet.request, but i cant seem to get http.servlet.request.max or http.servlet.request.count.. i really wanted latency is that even possible?
im using tomcat with spring as per standard, Anyone got any ideas why this would be the case why im not seeing
Building a new project downloaded using https://start.spring.io/ does not run on browser.
I have seen some solutions on stackoverflow which require to make some changes or add, but default/out-of-the-box application does not run.
I asked this in Github https://github.com/spring-projects/spring-boot/issues/20603 but was told that i need to add request mappings or something else. There's no default mapping for the root. That's indeed the default error page showing you a 404.
Is there a documentation to "add request mappings or something else" ? It will help if the application run showing some text instead of an error message. This maybe a simple obvious thing for Spring developers but for learners, takes a lot of effort.
http://localhost:8080/
STEPS TO REPRODUCE:
Download new project at https://start.spring.io/
mvn clean package
mvn spring-boot:run
That is the expected behavior right after creating a fresh Spring Boot project. The initializer does not register any endpoint for you, it just gives you the project skeleton you can start working with.
If you want to see something on localhost:8080/ consider adding the following Java class to your project:
#RestController
public class HelloWorldController {
#GetMapping
public String helloWorld() {
return "Hello World!";
}
}
If you are new to Spring/Spring Boot, I can recommend the following resources:
Official Spring Web documentation
Spring Boot Guides
Developing a CRUD API with Spring Boot YouTube course
We are setting up microservice framework.
We use following stack for distributed tracing.
Spring boot
Kafka
Zipkin
Following is how the configuration is done
In gradle.build (or pom.xml) following starter dependencies added
compile 'org.springframework.cloud:spring-cloud-starter-sleuth'
compile 'org.springframework.cloud:spring-cloud-sleuth-zipkin'
compile 'org.springframework.cloud:spring-cloud-starter-bus-kafka'
Add one AlwaysSampler bean
#Bean
public Sampler defaultSampler() {
return Sampler.ALWAYS_SAMPLE;
}
If we have kafka running, things work automatically.
But if kafka is not running, server does not start - this is mostly the case for development environment.
If I want to stop this, I have to comment out all the code mentioned here (as we use starter dependency with spring boot, it automatically configures as I understand).
Can we just make some changes in properties (or yaml) files so that I don't need to go and comment out all these code?
Or probably another way to disable this without doing some commenting, etc.
You can add the following setting on your properties key to disable zipkin, source.
spring.zipkin.enabled=false
Better yet, create separate development properties (like application-dev.properties) to avoid changing above setting everytime you want to run in your machine: https://stackoverflow.com/a/34846351/4504053
I am working on a spring boot application.
I wanted to know what happens when the application started running and before it becomes ready for user interaction.
I tried going through the console logs but I am still unsure as to what happens when.
I believe you should elaborate a bit more your question. That's because you can build different types of applications using Spring Boot. In a nutshell, during the start up the application will basically try to load the "beans" defined in the related context(s), pre-configured components, define the active profile, properties files, etc. Also some Spring and application events are generated during the start up.
A good way to understand what's going on behind the scenes is running the application in DEBUG mode. By default, the log level of the application is set as INFO.
Have a look at this link for further details:
http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-features-spring-application
I hope this can help you as start point.
I created a simple app using Spring boot and the spring cloud starter hystrix library.
In my build.gradle:
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.cloud:spring-cloud-starter-hystrix-dashboard:1.0.0.RC2")
compile("org.springframework.cloud:spring-cloud-starter-hystrix:1.0.0.RC2")
}
I deployed one app as a hystrix dashboard using the above libraries and #EnableHystrixDashboard
I then deployed another app which was annotated with #EnableHystrix
I added a component that has a command that I invoke through a controller, just to test things out:
#HystrixCommand(fallbackMethod = "onFailedToSayHello")
public String sayHello(Map<String, String> parameters) {
if (parameters.get("fail") != null && parameters.get("fail").equals("yes")) {
throw new RuntimeException("I failed because you told me to");
}
return "Hello";
}
private String onFailedToSayHello(Map<String, String> parameters) {
return "Bye";
}
The hystrix app runs fine. When I hit the URL I see the stream, the ouptut of which I put in a gist here.
I just see that repeating over and over.
My dashboard is up and running and when I enter the URL of my running hystrix sample app I get a loading screen:
Then, when I check my hystrix app again I see this:
λ curl http://myappurl/hystrix.stream
{"timestamp":1423748238280,"status":503,"error":"Service Unavailable","message":"MaxConcurrentConnections reached: 5","path":"/hystrix.stream"}
I am not sure where to go from here. I tried deploying the hystrix dashboard war instead of building it myself which I downloaded from here but got the same result.
I also noticed some JavaScript error outputs in the browser console which I put here in case they are any use.
And in the server logs I see this repeated over and over:
2015-02-15 20:03:55.324 INFO 9360 --- [nio-8080-exec-9]
ashboardConfiguration$ProxyStreamServlet :
Proxy opening connection to: http://myappurl/hystrix.stream
I am now going to try and get turbine running and see if using that somehow magically fixes things. Thought I would post here too though on the off chance someone can spot an error on my part based on what I've done so far.
EDIT:
An important point I didn't mention is that I have both the app and the dashboard deployed on PCF. This seems to be important since this issue doesn't happen when I deploy locally. Still no idea what's causing it though.
Problem goes away if you build hystrix-dashboard from the latest source, or use the most recently released war (version 1.4.3 on 27th March at time of writing).
Several things can probably lead to MaxConcurrentConnections, and one of them is no any metrics data generated by the application. The servlets (Hystrix.stream servlets) will keep looping to wait data, then it will consumes all the connections. There are very good discussion on the Hystrix github wiki. For example:
hystrix.stream holds connection open if no metrics #85