Configuring Tracing for Datadog in Spring Boot application - java

I have a Spring Boot application and want to configure HTTP request tracing via dependency management without having to deal with setting up the java agent. Can anyone suggest the best way to do this?
I have the micrometer-registry-datadog dependency added to my pom and can see that there are a lot of undocumented com.datadoghq dependencies, but am unsure if any of these will solve my problem. I'm getting all of the JVM metrics, but want some more APM-type metrics now. Ideally I'd like to use the #Timed annotation and various others to get detailed metrics around API calls.

Related

How to connect Kafka to legacy Spring

I am working on PoC of connecting legacy Spring application to Kafka. It is war application to be deployed in Tomcat, Spring version 4.3.12. Is there some library to make communication with Kafka almost as easy as with Spring Boot? I need just fundamental operations: sending message, listening for confirmation, receiving.
I have some experience with Spring Boot support as is provided in org.springframework.kafka:spring-kafka library. I am not sure how to efficiently adopt Kafka for legacy Spring - I'm thinking of using Kafka Java client which looks promising but as I am used to working at Spring Boot abstraction level I don't have clue how much code should I supply myself.
Web search is not much helpful in this case since it tends to show Spring Boot-related solutions. Migration of legacy application is considered too, I just need to have some idea how difficult each way is.
kafka-clients is all you need (from Maven Central, not Confluent). You could go a step further and look into Log4j2 Kafka bridge, then property files for that.
If you want to externalize config into regular Java .properties file, you can, or you can pull values from environment variables, if you follow 12-factor principles.
But if you don't already have Spring Boot dependencies, then I do not think adding them is worth it for only Kafka.
Also, the Spring-Kafka documentation covers how to configure your app without Boot.

Spring boot actuator in console application

I have a console application using Spring. My application is connecting on a database and a JMS server.
I would like to know at the start up of my application, if it is well connected to the databse and the JMS.
I know that spring-boot-actuator do that efficiently and esealy, but it expose rest endpoints. I would like to know if it's possible to get Spring actuator's beans to get status informations, database and JMS status.
Is it possible ?
Thank you.
About your second question: Yes, springs actuators provide autoconfigured health indicators when they are found on classpath, see this list for more details (datasource and JMS is provided).
But you can also easily implement your own status informations by just implementing HealthIndicator and adding it as a #Component, more details can be found here.
You can expose them either with REST or with JMX, the exposure can be configured via application.properties, details can be found in the docs.
According to the documentation, endpoints can be exposed through HTTP or JMX. By default, Spring will expose actuator endpoints over JMX unless you configure it not to do so.
There is a table showing which endpoints are enabled in JMX and HTTP by default. If you want to enable them on HTTP, there are several security settings you should be aware of before exposing them (see docs link above).
In order to expose actuator endpoints over HTTP, you'll need to include the spring-starter-web start in your build.
Gradle:
compile('org.springframework.boot:spring-boot-starter-web')
Maven:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
Again, check the security settings before doing this. Newer versions of boot should give you a good safe set of defaults.

Monitor Endpoint using Spring Framework

I'm trying to find an out-of-the-box health check for my spring app. However, I can only find support for Spring Actuator. I'm not able to use Spring Actuator because my application is a Spring application and not a Spring boot app. Is there another library that I could make use of without having to write my own? I would ideally want an endpoint that could possibly give me data about whether my DB is up and possibly some of the java opts passed into that particular node

Spring Integration + Spring Boot Actuator Endpoints not showing up

I have been trying to learn more about Spring Boot and I would like to add the Actuator endpoints to my test Spring integration/Spring Boot project. However, it is a plain, CLI Spring integration project--there are no current REST or web services. I'd ideally like to add the ability to view the endpoints with a browser while the jar is running from the command line.
I have been looking through the tutorials and I'm not finding a lot on adding it to a regular project, rather than a web project.
I've added the dependencies (spring-boot-actuator), and can see the endpoints from the jconsole, but I never see a connection to a port on my system (using netstat) and never can navigate there.
Is there a tutorial or something that can show me how to have REST endpoints with a CLI project?
Thank you
newbo
You can monitor and manage your application using JMX instead. See the documentation here.
If you use IntelliJ IDEA, hit CTRL+Space in an application.properties file to see a lot of JMX properties ready for you, one of them being:
endpoints.jmx.enabled=true (true is the default value)
According to Spring Docs, in order to show the endpoint user need to have ACTUATOR role.If you need to access without having the role you need to add the following value to application.properties:
management.security.enabled=false
I think if it isn't a web project, no tomcat servlet will be embedded, therefor you wont be able to browse the actuator endpoints over http
Insert dependency spring-boot-starter-web into your project and it will probably work.

OSGi and legacy applications

I would like to use the Config Admin service to manage configuration for my services. Since I'm just starting to use OSGi, I would like to introduce it step by step. So, I would like to keep some of my applications as they are now, without executing them inside an OSGi framework. But, I would also like to be able to use the Config Admin service from these legacy applications, so they can also get configuration information as other OSGi services.
Is it possible to do with OSGi? By looking at the specs, I've found a specification for Foreign Applications Access. I don't know if it's related to my problem. If it is possible, where I can find resources about how to make my legacy applications interact with the Config Admin service.
I precise that I'm using Apache Felix in the case it's implementation specific.
Thanks
Basically what you want to have is code the can run inside as well as outside OSGi. When in OSGi you want to leverage the config admin service. Is that correct?
So a good solution for this is following the principle of dependency injection. You code should not load configs, instead it should expect the config to be injected. For example use a setter where you need a config attribute. Outside of OSGi you can use spring or hand code injections to set the configs. Inside OSGi you could use an Activator or a blueprint context. Both will be inactive when you do not run in OSGi so it does not hurt to always have them.
See my first Apache Karaf Tutorial for how this works. The tutorial only shows the setup for OSGi but it is easy to see what you would need to do outside OSGi to configure the example.
Karaf Tutorial Part 1 - Installation and First application

Categories