We have created custom services in Dynatrace to detect @Scheduled methods in our Java application. Given the significant number of @Scheduled methods in our application, is there a way to configure Dynatrace to auto-detect these methods using rules or other configurations?
Yes there’s a way to auto-detect & monitor them. As far as I’m aware custom services can be used for this. And you’ll define the technology as Java and fill out the rest as necessary. I believe this way it’s a lot easier as well since it will all be done through the Dynatrace UI.
I have also attached an image as to where you can find custom services.
That’s what I would do personally, so I hope that helped!
-Habiba Abdelaziz
As I mentioned earlier, we have successfully created custom services for detecting @Scheduled methods, and they are available in Dynatrace. Given the substantial number of schedulers in our application, I’m now exploring options for auto-detecting these methods using rules or other configurations.
Yes, but typically you should instrument the particular abstract class being executed to automatically capture every task scheduled. I do it it for example with Quarz scheduler this way. You can also add request naming rules to better identify the executed task, if necessary.
@sivakumarp For example, for the Quartz scheduler, instrument the org.quartz.Job interface and the execute method (create a custom service which bounds to this class and method execution). You may want to capture additional metadata using request attributes from the execution method’s context argument.
This is just an example for Quartz, if your apps use different schedulers, I’d recommend following the same approach.
@Julius_Loman could you share how to instrument the execute method? I assume DynaTrace SDK needs to be used for this. If you could share a link to documentation how to do this it would be great. Thank you!
@sp72 using the Custom service method. For example, for Quartz scheduler you can use the Find entry point (1). You define a class/interface (2) in this case org.quartz.Job and then the metods, in this case execute (3). I recommend using the Find entry point (1) to define it.
This creates a custom service and executions of your jobs will be traced.
I hope this helps. Using the Dynatrace OneAgent SDK or OpenTelemetry SDK is also possible, but needs changes in the application code.
Could you also point me to OneAgent SDK and OpenTelemetry SDK documentation that describes how to mark methods in the source code? I’m trying to make this configuration automatically. Thank you!
I added OneAgentSdk.traceCustomService() calls to me code but I cannot find any traces of the service name I provide as parameter when calling this method. Where should I see the service in DT UI? Is it possible to troubleshoot that the data is actually submitted?
I’m trying to navigate via Kubernetes cluster → Workload → Apache Process → List of Services and the service list does not contain my custom service. Neither I can find it by name in Services section.
@Julius_Loman could you help with this and point me out where to look for the custom service information in DT?
Also check if the OneAgent SDK is really used and initialized in your deployed process. You mention “Apache” - are you sure you are looking at the right process? Also, you need to look for Dynatrace services, not Kubernetes services.
I checked OneAgent status before calling traceCustomService() and it is set to ACTIVE.
Any idea why Custom Service option might not be available in service search?
Also, is custom service name used as it is provided in the call to traceCustomService(), are there any decorations added to the name? I tried to search by name without selecting service type but search returned nothing as well.
@sp72 no you don’t if you create them using OneAgent SDK.
Are you also calling the tracer start() and end() methods on the tracer the traceCustomService method returns?
oh my. what a blunder on my part. I missed that I needed to call start() to actually start the tracer. Now I can see executions tracked in DT UI. Thank you very much for pointing this out!
The service names do not show up and seem to be replaced by the naming rules set on the DT instance. So now I need to figure out how to fix them