dd-trace-java icon indicating copy to clipboard operation
dd-trace-java copied to clipboard

Wildcard to accept all classes in package

Open denisdaniliuk-hqo opened this issue 4 years ago • 5 comments

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?

denisdaniliuk-hqo avatar Feb 15 '21 17:02 denisdaniliuk-hqo

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?

richardstartin avatar Feb 15 '21 19:02 richardstartin

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.

  1. DD_TRACE_ANNOTATIONS - a list of method annotations. So my first concern is that I should add com.datadoghq.trace.Trace annotation 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 specify com.datadoghq.trace.Trace annotation on class (this annotation will have @Target({ TYPE, METHOD })), add this annotation to DD_TRACE_ANNOTATIONS and Datadog will know that all methods from this class should be covered with tracing. Also maybe it will be useful if com.datadoghq.trace.Trace annotation 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
    }
}
  1. 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 (like package.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 specify DD_TRACE_METHODS as 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.*" 

denisdaniliuk-hqo avatar Feb 16 '21 09:02 denisdaniliuk-hqo

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.

toplac avatar Feb 07 '24 12:02 toplac

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 avatar Feb 12 '24 14:02 bm1549

@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

toplac avatar Feb 13 '24 12:02 toplac