dd-trace-java
dd-trace-java copied to clipboard
Wildcard to accept all classes in package
This is a duplicate issue from #1058
Originally posted by @tyrcho in https://github.com/DataDog/dd-trace-java/issues/1058#issuecomment-693524602
Is it possible to add support for wildcard for packages? Is there any way how to setup tracing for huge amount of classes or classes that can't be changed?
Hi @denisdaniliuk-hqo, this should be relatively straightforward to implement - but I wonder if this is really what you want - it sounds similar to our continuous profiling functionality. Could you describe your use case in a bit more detail?
Hi @richardstartin, we have pretty standard MVC project and I would like to enable tracing for all my public methods from all my classes. Maybe I misunderstood how to enabled tracing so my vision and proposal bellow.
Found this page which says that we should specify one of 2 properties: DD_TRACE_ANNOTATIONS or DD_TRACE_METHODS.
DD_TRACE_ANNOTATIONS- a list of method annotations. So my first concern is that I should addcom.datadoghq.trace.Traceannotation to each public methods from project and support it in future during refactoring or implementing new features. In my case it will be much simpler if I can specifycom.datadoghq.trace.Traceannotation on class (this annotation will have@Target({ TYPE, METHOD })), add this annotation toDD_TRACE_ANNOTATIONSand Datadog will know that all methods from this class should be covered with tracing. Also maybe it will be useful ifcom.datadoghq.trace.Traceannotation will have additional optional parameter that will specify what kind of method's access modifier we would like to trace (private, protected, public, default = all). And of course it can be a list of access modifiers. Example:
@Trace(access=public) // access modifier can be (for example) private, protected, public, default = all
@Controller("/api/v1/users")
public class UserController {
public void doSomething() {
// This method should be covered with tracing because Trace access modifier is public and method is public
}
private void doSomething2() {
// This method should not be covered with tracing because Trace access modifier is public but method is privateannotation
}
}
DD_TRACE_METHODS- a list of class/interface and methods to trace. So my second concern is that I should specify all my class names (likepackage.ClassName[*]) and developers should not forget to update this parameter when existing class will be renamed OR new classes will be added. To simplify it we can specifyDD_TRACE_METHODSas list of packages with wildkcard (without name of classes). Example: lets imagine that we have next package structure:
src
main
java
service
feature1
feature2
controller
feature1
feature2
...
and we want to trace only Feature 1. In this case DD_TRACE_METHODS will have next value:
DD_TRACE_METHODS="src.main.java.service.feature1.*,src.main.java.controller.feature1.*"
OR if we want to trace all our project (within all sub packages and classes)
DD_TRACE_METHODS="src.main.java.*"
Hi @denisdaniliuk-hqo
curious to know if you found a solution in the meantime? Refering to
we have pretty standard MVC project and I would like to enable tracing for all my public methods from all my classes.
Hi @denisdaniliuk-hqo / @toplac - could you share which MVC framework you are using? There's a chance the framework you're using is already supported or is on our roadmap
@bm1549 We are using spring-boot and while there is some stuff working out of the box (Controllers, Repositories, Database Connections) we have a lot of blind spots in our classes annotated with @Component or @Service) and we are currently adding Datados @Trace` annotation to most of them