# Is it feasible to configure Dynatrace for automatic detection of @Scheduled methods in a Java application?

**URL:** <https://community.dynatrace.com/t/is-it-feasible-to-configure-dynatrace-for-automatic-detection-of-scheduled-methods-in-a-java-application/49537>\
**Category:** Open Q&A\
**Tags:** services, java\
**Created:** [January 2, 2025, 9:19am UTC](https://community.dynatrace.com/t/is-it-feasible-to-configure-dynatrace-for-automatic-detection-of-scheduled-methods-in-a-java-application/49537 "2025-01-02T09:19:12Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![sivakumarp](https://avatars.discourse-cdn.com/v4/letter/s/7ea924/32.png) [@sivakumarp](https://community.dynatrace.com/u/sivakumarp)\
**Post date:** [January 2, 2025, 9:19am UTC](https://community.dynatrace.com/t/is-it-feasible-to-configure-dynatrace-for-automatic-detection-of-scheduled-methods-in-a-java-application/49537/1 "2025-01-02T09:19:12Z")

</div>

Hello,

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?

Thanks in advance.

Regards,

Siva Kumar

---

<div class="post-metadata">

**Author:** ![Habiba\_A](https://avatars.discourse-cdn.com/v4/letter/h/df705f/32.png) [@Habiba\_A](https://community.dynatrace.com/u/Habiba_A)\
**Post date:** [January 2, 2025, 10:04am UTC](https://community.dynatrace.com/t/is-it-feasible-to-configure-dynatrace-for-automatic-detection-of-scheduled-methods-in-a-java-application/49537/2 "2025-01-02T10:04:09Z")

</div>

Hello&nbsp;[@sivakumarp](https://community.dynatrace.com/user/84796)&nbsp;,

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.

![Habiba_A_0-1735812221796.png](https://global.discourse-cdn.com/dynatrace/original/2X/2/266b5fb7bb43652dcc35d06a440fbbeff5662661.png)

That’s what I would do personally, so I hope that helped!  
-Habiba Abdelaziz

---

<div class="post-metadata">

**Author:** ![sivakumarp](https://avatars.discourse-cdn.com/v4/letter/s/7ea924/32.png) [@sivakumarp](https://community.dynatrace.com/u/sivakumarp)\
**Post date:** [January 2, 2025, 10:15am UTC](https://community.dynatrace.com/t/is-it-feasible-to-configure-dynatrace-for-automatic-detection-of-scheduled-methods-in-a-java-application/49537/3 "2025-01-02T10:15:42Z")

</div>

Hi Habiba\_A,

Thanks for the response.

As I mentioned earlier, we have successfully created custom services for detecting @Scheduled&nbsp;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.

---

<div class="post-metadata">

**Author:** ![AntonioSousa](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/antoniosousa/32/50_2.png) [@AntonioSousa](https://community.dynatrace.com/u/AntonioSousa)\
**Post date:** [January 2, 2025, 10:30am UTC](https://community.dynatrace.com/t/is-it-feasible-to-configure-dynatrace-for-automatic-detection-of-scheduled-methods-in-a-java-application/49537/4 "2025-01-02T10:30:42Z")

</div>

[@sivakumarp](https://community.dynatrace.com/user/84796),

In a recent case, I have done that configuration via API. That certainly helps when leading with large number of Custom Services.

The link [is here](https://docs.dynatrace.com/docs/discover-dynatrace/references/dynatrace-api/configuration-api/service-api/custom-services-api/post-rule). If you have doubts, use the same API to get an existing config, and then replicate it with this one…

---

<div class="post-metadata">

**Author:** ![Julius\_Loman](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/julius_loman/32/51_2.png) [@Julius\_Loman](https://community.dynatrace.com/u/Julius_Loman)\
**Post date:** [January 6, 2025, 10:06am UTC](https://community.dynatrace.com/t/is-it-feasible-to-configure-dynatrace-for-automatic-detection-of-scheduled-methods-in-a-java-application/49537/5 "2025-01-06T10:06:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sivakumarp](https://avatars.discourse-cdn.com/v4/letter/s/7ea924/32.png) [@sivakumarp](https://community.dynatrace.com/u/sivakumarp)\
**Post date:** [January 6, 2025, 10:46am UTC](https://community.dynatrace.com/t/is-it-feasible-to-configure-dynatrace-for-automatic-detection-of-scheduled-methods-in-a-java-application/49537/6 "2025-01-06T10:46:29Z")

</div>

Hi&nbsp;[@Julius\_Loman](https://community.dynatrace.com/user/3364),

Thanks for the information. Do you have any sample to refer ?

---

<div class="post-metadata">

**Author:** ![Julius\_Loman](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/julius_loman/32/51_2.png) [@Julius\_Loman](https://community.dynatrace.com/u/Julius_Loman)\
**Post date:** [January 6, 2025, 12:27pm UTC](https://community.dynatrace.com/t/is-it-feasible-to-configure-dynatrace-for-automatic-detection-of-scheduled-methods-in-a-java-application/49537/7 "2025-01-06T12:27:03Z")

</div>

[@sivakumarp](https://community.dynatrace.com/user/84796)&nbsp;For example, for the Quartz scheduler, instrument the&nbsp;[org.quartz.Job](https://www.quartz-scheduler.org/api/2.3.0/org/quartz/Job.html) 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.

---

<div class="post-metadata">

**Author:** ![sp72](https://avatars.discourse-cdn.com/v4/letter/s/7cd45c/32.png) [@sp72](https://community.dynatrace.com/u/sp72)\
**Post date:** [January 11, 2025, 4:33am UTC](https://community.dynatrace.com/t/is-it-feasible-to-configure-dynatrace-for-automatic-detection-of-scheduled-methods-in-a-java-application/49537/8 "2025-01-11T04:33:02Z")

</div>

[@Julius\_Loman](https://community.dynatrace.com/user/3364)&nbsp;could you share how to instrument the execute method? I assume DynaTrace SDK &nbsp;needs to be used for this. If you could share a link to documentation how to do this it would be great. Thank you!

---

<div class="post-metadata">

**Author:** ![Julius\_Loman](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/julius_loman/32/51_2.png) [@Julius\_Loman](https://community.dynatrace.com/u/Julius_Loman)\
**Post date:** [January 15, 2025, 7:49pm UTC](https://community.dynatrace.com/t/is-it-feasible-to-configure-dynatrace-for-automatic-detection-of-scheduled-methods-in-a-java-application/49537/9 "2025-01-15T19:49:14Z")

</div>

[@sp72](https://community.dynatrace.com/user/85236)&nbsp;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.

 ![Julius_Loman_0-1736970333672.png](https://global.discourse-cdn.com/dynatrace/original/3X/1/d/1df6610263ff584469a21943d142589e2581db15.png)

This creates a custom service and executions of your jobs will be traced.&nbsp;  
I hope this helps. Using the Dynatrace OneAgent SDK or OpenTelemetry SDK is also possible, but needs changes in the application code.

---

<div class="post-metadata">

**Author:** ![sp72](https://avatars.discourse-cdn.com/v4/letter/s/7cd45c/32.png) [@sp72](https://community.dynatrace.com/u/sp72)\
**Post date:** [January 15, 2025, 8:01pm UTC](https://community.dynatrace.com/t/is-it-feasible-to-configure-dynatrace-for-automatic-detection-of-scheduled-methods-in-a-java-application/49537/10 "2025-01-15T20:01:39Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![sp72](https://avatars.discourse-cdn.com/v4/letter/s/7cd45c/32.png) [@sp72](https://community.dynatrace.com/u/sp72)\
**Post date:** [January 23, 2025, 1:55am UTC](https://community.dynatrace.com/t/is-it-feasible-to-configure-dynatrace-for-automatic-detection-of-scheduled-methods-in-a-java-application/49537/11 "2025-01-23T01:55:23Z")

</div>

ok, I found it in the SDK documentation. I can use&nbsp;_**oneAgentSDK.traceCustomService()**_ method to mark custom services within source code. Thank you.

---

<div class="post-metadata">

**Author:** ![sp72](https://avatars.discourse-cdn.com/v4/letter/s/7cd45c/32.png) [@sp72](https://community.dynatrace.com/u/sp72)\
**Post date:** [March 8, 2025, 6:09pm UTC](https://community.dynatrace.com/t/is-it-feasible-to-configure-dynatrace-for-automatic-detection-of-scheduled-methods-in-a-java-application/49537/12 "2025-03-08T18:09:37Z")

</div>

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](https://community.dynatrace.com/user/3364)&nbsp;could you help with this and point me out where to look for the custom service information in DT?

---

<div class="post-metadata">

**Author:** ![Julius\_Loman](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/julius_loman/32/51_2.png) [@Julius\_Loman](https://community.dynatrace.com/u/Julius_Loman)\
**Post date:** [March 9, 2025, 9:38am UTC](https://community.dynatrace.com/t/is-it-feasible-to-configure-dynatrace-for-automatic-detection-of-scheduled-methods-in-a-java-application/49537/13 "2025-03-09T09:38:14Z")

</div>

[@sp72](https://community.dynatrace.com/user/85236)&nbsp;look for custom services in your environment:

 ![Julius_Loman_0-1741512342647.png](https://global.discourse-cdn.com/dynatrace/original/2X/3/30c761d59d64c4a73b7c88390ae4822b7202e198.png)

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.

---

<div class="post-metadata">

**Author:** ![sp72](https://avatars.discourse-cdn.com/v4/letter/s/7cd45c/32.png) [@sp72](https://community.dynatrace.com/u/sp72)\
**Post date:** [March 10, 2025, 9:37pm UTC](https://community.dynatrace.com/t/is-it-feasible-to-configure-dynatrace-for-automatic-detection-of-scheduled-methods-in-a-java-application/49537/14 "2025-03-10T21:37:31Z")

</div>

Somehow I don’t see Custom Service option in the service type list. These are all the options I see:

 ![sp72_0-1741642512474.png](https://global.discourse-cdn.com/dynatrace/original/3X/8/3/8368fb7b0bbd90068ec7abc0441318ea8cfffdaa.png)

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&nbsp;_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.

---

<div class="post-metadata">

**Author:** ![Julius\_Loman](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/julius_loman/32/51_2.png) [@Julius\_Loman](https://community.dynatrace.com/u/Julius_Loman)\
**Post date:** [March 11, 2025, 6:06am UTC](https://community.dynatrace.com/t/is-it-feasible-to-configure-dynatrace-for-automatic-detection-of-scheduled-methods-in-a-java-application/49537/15 "2025-03-11T06:06:22Z")

</div>

[@sp72](https://community.dynatrace.com/user/85236)&nbsp;in this case

- It has not been called in the timeframe you are looking at - most likely
- The oneagent feature flag is disabled
- The agent is not connected to the environment you are looking at

Also please check the oneagent log for the process. There is information about enabled sensors such as custom service.

---

<div class="post-metadata">

**Author:** ![sp72](https://avatars.discourse-cdn.com/v4/letter/s/7cd45c/32.png) [@sp72](https://community.dynatrace.com/u/sp72)\
**Post date:** [March 11, 2025, 4:33pm UTC](https://community.dynatrace.com/t/is-it-feasible-to-configure-dynatrace-for-automatic-detection-of-scheduled-methods-in-a-java-application/49537/16 "2025-03-11T16:33:59Z")

</div>

I tried searching for past several days (which is longer than the moment I started my tests), nothing can be found.

It seems like the feature is enabled, if I’m looking in the right place (this is from Manage → Settings → Preferences → OneAgent features):

 ![sp72_0-1741710659499.png](https://global.discourse-cdn.com/dynatrace/original/2X/1/1eb3fdba22b71ca92970a78cb696c9951e7efa0e.png)

I don’t see anything mentioning features enabled in the OneAgent sidecar logs.

Banging my head against the wall where else to look 🙂

Do I need to create custom service rules for this approach to work?

---

<div class="post-metadata">

**Author:** ![Julius\_Loman](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/julius_loman/32/51_2.png) [@Julius\_Loman](https://community.dynatrace.com/u/Julius_Loman)\
**Post date:** [March 11, 2025, 9:38pm UTC](https://community.dynatrace.com/t/is-it-feasible-to-configure-dynatrace-for-automatic-detection-of-scheduled-methods-in-a-java-application/49537/17 "2025-03-11T21:38:07Z")

</div>

[@sp72](https://community.dynatrace.com/user/85236)&nbsp;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?

```markup
String serviceMethod = "onTimer";
String serviceName = "PeriodicCleanupTask";
CustomServiceTracer tracer = oneAgentSDK.traceCustomService(serviceMethod, serviceName);
tracer.start();
try {
	doMyCleanup();
} catch (Exception e) {
	tracer.error(e.getMessage());
	throw e;
} finally {
	tracer.end();
}

```

The traceCustomService call itself is not enough, you need to start and end the tracer.

---

<div class="post-metadata">

**Author:** ![sp72](https://avatars.discourse-cdn.com/v4/letter/s/7cd45c/32.png) [@sp72](https://community.dynatrace.com/u/sp72)\
**Post date:** [March 11, 2025, 10:56pm UTC](https://community.dynatrace.com/t/is-it-feasible-to-configure-dynatrace-for-automatic-detection-of-scheduled-methods-in-a-java-application/49537/18 "2025-03-11T22:56:41Z")

</div>

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 🙂
