<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>article Instrumentation Scheduled Tasks in Spring Framework in Troubleshooting</title>
    <link>https://community.dynatrace.com/t5/Troubleshooting/Instrumentation-Scheduled-Tasks-in-Spring-Framework/ta-p/263862</link>
    <description>&lt;DIV class="lia-message-template-content-zone"&gt;
&lt;H1&gt;&lt;SPAN&gt;Abstract&lt;/SPAN&gt;&lt;/H1&gt;
&lt;P&gt;&lt;SPAN&gt;Distributed traces generally begin at entry points where user interactions or external requests enter your application. These entry points are often incoming HTTP requests or messages, as they signify user actions or external service calls that initiate a transaction.&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;Database calls don't initiate traces because they're part of the broader business logic. In the trace view in UI, these calls are displayed within the context of the entire transaction flow, enabling you to identify which part of the application executed the call. Additionally, the execution of business logic does not start a trace unless a custom service is specified for a method call within the class or an entry point is defined using &lt;A href="https://docs.dynatrace.com/docs/ingest-from/extend-dynatrace/extend-tracing/oneagent-sdk" target="_blank" rel="noopener"&gt;OneAgent SDK&lt;/A&gt; or &lt;A href="https://docs.dynatrace.com/docs/shortlink/opentelemetry" target="_blank" rel="noopener"&gt;OpenTelemetry&lt;/A&gt;.&lt;/SPAN&gt;&lt;/P&gt;
&lt;H1&gt;&lt;SPAN&gt;Resolution&lt;/SPAN&gt;&lt;/H1&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;A href="https://docs.spring.io/spring-framework/reference/integration/scheduling.html" target="_blank" rel="noopener"&gt;Spring Scheduled Tasks&lt;/A&gt;&amp;nbsp;allow you to automate the execution of tasks at specific intervals or times using the Spring Framework. This is achieved primarily through the&amp;nbsp;&lt;CODE&gt;@Scheduled&lt;/CODE&gt;&amp;nbsp;annotation, which can be applied to methods that you want to run periodically. Let's look at the following example, which executes the mentioned actions:&lt;/SPAN&gt;&lt;/P&gt;
&lt;LI-CODE lang="java"&gt;@Component
public class FetchUsersTask {
    private final GetUserOverHttpService getUserOverHttpService;
    private final UserService userService;

    private int counter = 0;

    public FetchUsersTask(GetUserOverHttpService getUserOverHttpService, UserService userService) {
        this.getUserOverHttpService = getUserOverHttpService;
        this.userService = userService;
    }

    @Scheduled(fixedDelay = 5, initialDelay = 5, timeUnit = TimeUnit.SECONDS)
    public void getUserAndSave() {
        User user = getUserOverHttpService.getUserById(++counter);
        userService.storeUser(user);
    }
}&lt;/LI-CODE&gt;
&lt;P&gt;As the application doesn't receive any incoming HTTP requests, only the &lt;A href="https://docs.dynatrace.com/docs/observe/applications-and-microservices/services/service-detection-and-naming/service-types#background-activity-services" target="_blank" rel="noopener"&gt;Background activity service&lt;/A&gt; is detected, which shows outgoing calls to a backend:&lt;/P&gt;
&lt;/DIV&gt;
&lt;DIV class="lia-message-template-content-zone"&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="anton_konikov_0-1732803914582.png" style="width: 999px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/24929i0FA2F3DCAA5D3BA3/image-size/large?v=v2&amp;amp;px=999" role="button" title="anton_konikov_0-1732803914582.png" alt="anton_konikov_0-1732803914582.png" /&gt;&lt;/span&gt;&lt;/DIV&gt;
&lt;DIV class="lia-message-template-content-zone"&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2024-11-28 at 15.27.31.png" style="width: 999px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/25115i6BCF13DF2E12165E/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2024-11-28 at 15.27.31.png" alt="Screenshot 2024-11-28 at 15.27.31.png" /&gt;&lt;/span&gt;&lt;/DIV&gt;
&lt;DIV class="lia-message-template-content-zone"&gt;
&lt;P&gt;To represent the full logic would be required to create a custom service that will start a trace from the desired method as an entry point. In this particular case, it would be necessary to use the fully qualified class name &lt;CODE&gt;com.dynatrace.scheduling.tasks.FetchUsersTask&lt;/CODE&gt; and the annotated method &lt;CODE&gt;getUserAndSave&lt;/CODE&gt; and using the embedded wizard, create a custom service for Java:&amp;nbsp;&lt;/P&gt;
&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="anton_konikov_0-1732804590942.png" style="width: 999px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/24931iB0367F308E325813/image-size/large?v=v2&amp;amp;px=999" role="button" title="anton_konikov_0-1732804590942.png" alt="anton_konikov_0-1732804590942.png" /&gt;&lt;/span&gt;
&lt;P&gt;&lt;SPAN&gt;After enabling the custom service, it will soon be visible in the process group instance view. The database service is displayed only because the example uses an embedded H2 database.&lt;/SPAN&gt;&lt;/P&gt;
&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2024-12-06 at 10.58.50.png" style="width: 999px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/25117i228B0ECD6E15F344/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2024-12-06 at 10.58.50.png" alt="Screenshot 2024-12-06 at 10.58.50.png" /&gt;&lt;/span&gt;
&lt;P&gt;Navigating to a trace view, you can see details about an outgoing HTTP request and a request to DB:&lt;/P&gt;
&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2024-12-06 at 11.24.29.png" style="width: 999px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/25067iE8635D15F3D29517/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2024-12-06 at 11.24.29.png" alt="Screenshot 2024-12-06 at 11.24.29.png" /&gt;&lt;/span&gt;
&lt;P&gt; &lt;/P&gt;
&lt;P&gt;If you don't have access to the source code and are looking for a way to find and then instrument a proper method, a method hotspot view should be used to analyze stack traces.&lt;/P&gt;
&lt;/DIV&gt;</description>
    <pubDate>Fri, 20 Dec 2024 10:25:57 GMT</pubDate>
    <dc:creator>anton_konikov</dc:creator>
    <dc:date>2024-12-20T10:25:57Z</dc:date>
    <item>
      <title>Instrumentation Scheduled Tasks in Spring Framework</title>
      <link>https://community.dynatrace.com/t5/Troubleshooting/Instrumentation-Scheduled-Tasks-in-Spring-Framework/ta-p/263862</link>
      <description>&lt;DIV class="lia-message-template-content-zone"&gt;
&lt;H1&gt;&lt;SPAN&gt;Abstract&lt;/SPAN&gt;&lt;/H1&gt;
&lt;P&gt;&lt;SPAN&gt;Distributed traces generally begin at entry points where user interactions or external requests enter your application. These entry points are often incoming HTTP requests or messages, as they signify user actions or external service calls that initiate a transaction.&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;Database calls don't initiate traces because they're part of the broader business logic. In the trace view in UI, these calls are displayed within the context of the entire transaction flow, enabling you to identify which part of the application executed the call. Additionally, the execution of business logic does not start a trace unless a custom service is specified for a method call within the class or an entry point is defined using &lt;A href="https://docs.dynatrace.com/docs/ingest-from/extend-dynatrace/extend-tracing/oneagent-sdk" target="_blank" rel="noopener"&gt;OneAgent SDK&lt;/A&gt; or &lt;A href="https://docs.dynatrace.com/docs/shortlink/opentelemetry" target="_blank" rel="noopener"&gt;OpenTelemetry&lt;/A&gt;.&lt;/SPAN&gt;&lt;/P&gt;
&lt;H1&gt;&lt;SPAN&gt;Resolution&lt;/SPAN&gt;&lt;/H1&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;A href="https://docs.spring.io/spring-framework/reference/integration/scheduling.html" target="_blank" rel="noopener"&gt;Spring Scheduled Tasks&lt;/A&gt;&amp;nbsp;allow you to automate the execution of tasks at specific intervals or times using the Spring Framework. This is achieved primarily through the&amp;nbsp;&lt;CODE&gt;@Scheduled&lt;/CODE&gt;&amp;nbsp;annotation, which can be applied to methods that you want to run periodically. Let's look at the following example, which executes the mentioned actions:&lt;/SPAN&gt;&lt;/P&gt;
&lt;LI-CODE lang="java"&gt;@Component
public class FetchUsersTask {
    private final GetUserOverHttpService getUserOverHttpService;
    private final UserService userService;

    private int counter = 0;

    public FetchUsersTask(GetUserOverHttpService getUserOverHttpService, UserService userService) {
        this.getUserOverHttpService = getUserOverHttpService;
        this.userService = userService;
    }

    @Scheduled(fixedDelay = 5, initialDelay = 5, timeUnit = TimeUnit.SECONDS)
    public void getUserAndSave() {
        User user = getUserOverHttpService.getUserById(++counter);
        userService.storeUser(user);
    }
}&lt;/LI-CODE&gt;
&lt;P&gt;As the application doesn't receive any incoming HTTP requests, only the &lt;A href="https://docs.dynatrace.com/docs/observe/applications-and-microservices/services/service-detection-and-naming/service-types#background-activity-services" target="_blank" rel="noopener"&gt;Background activity service&lt;/A&gt; is detected, which shows outgoing calls to a backend:&lt;/P&gt;
&lt;/DIV&gt;
&lt;DIV class="lia-message-template-content-zone"&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="anton_konikov_0-1732803914582.png" style="width: 999px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/24929i0FA2F3DCAA5D3BA3/image-size/large?v=v2&amp;amp;px=999" role="button" title="anton_konikov_0-1732803914582.png" alt="anton_konikov_0-1732803914582.png" /&gt;&lt;/span&gt;&lt;/DIV&gt;
&lt;DIV class="lia-message-template-content-zone"&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2024-11-28 at 15.27.31.png" style="width: 999px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/25115i6BCF13DF2E12165E/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2024-11-28 at 15.27.31.png" alt="Screenshot 2024-11-28 at 15.27.31.png" /&gt;&lt;/span&gt;&lt;/DIV&gt;
&lt;DIV class="lia-message-template-content-zone"&gt;
&lt;P&gt;To represent the full logic would be required to create a custom service that will start a trace from the desired method as an entry point. In this particular case, it would be necessary to use the fully qualified class name &lt;CODE&gt;com.dynatrace.scheduling.tasks.FetchUsersTask&lt;/CODE&gt; and the annotated method &lt;CODE&gt;getUserAndSave&lt;/CODE&gt; and using the embedded wizard, create a custom service for Java:&amp;nbsp;&lt;/P&gt;
&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="anton_konikov_0-1732804590942.png" style="width: 999px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/24931iB0367F308E325813/image-size/large?v=v2&amp;amp;px=999" role="button" title="anton_konikov_0-1732804590942.png" alt="anton_konikov_0-1732804590942.png" /&gt;&lt;/span&gt;
&lt;P&gt;&lt;SPAN&gt;After enabling the custom service, it will soon be visible in the process group instance view. The database service is displayed only because the example uses an embedded H2 database.&lt;/SPAN&gt;&lt;/P&gt;
&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2024-12-06 at 10.58.50.png" style="width: 999px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/25117i228B0ECD6E15F344/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2024-12-06 at 10.58.50.png" alt="Screenshot 2024-12-06 at 10.58.50.png" /&gt;&lt;/span&gt;
&lt;P&gt;Navigating to a trace view, you can see details about an outgoing HTTP request and a request to DB:&lt;/P&gt;
&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2024-12-06 at 11.24.29.png" style="width: 999px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/25067iE8635D15F3D29517/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2024-12-06 at 11.24.29.png" alt="Screenshot 2024-12-06 at 11.24.29.png" /&gt;&lt;/span&gt;
&lt;P&gt; &lt;/P&gt;
&lt;P&gt;If you don't have access to the source code and are looking for a way to find and then instrument a proper method, a method hotspot view should be used to analyze stack traces.&lt;/P&gt;
&lt;/DIV&gt;</description>
      <pubDate>Fri, 20 Dec 2024 10:25:57 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Troubleshooting/Instrumentation-Scheduled-Tasks-in-Spring-Framework/ta-p/263862</guid>
      <dc:creator>anton_konikov</dc:creator>
      <dc:date>2024-12-20T10:25:57Z</dc:date>
    </item>
    <item>
      <title>Re: Instrumentation Scheduled Tasks in Spring Framework</title>
      <link>https://community.dynatrace.com/t5/Troubleshooting/Instrumentation-Scheduled-Tasks-in-Spring-Framework/tac-p/265272#M794</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Nice information!!&amp;nbsp;&lt;img class="lia-deferred-image lia-image-emoji" src="https://community.dynatrace.com/html/@9BD876A77FEF3D5EF4BC972CF8A97CB1/images/emoticons/take_my_money.png" alt=":take_my_money:" title=":take_my_money:" /&gt;&lt;/P&gt;&lt;P&gt;Do you need to restart process after custom service is created? Or is it catch it automatically?&lt;/P&gt;&lt;P&gt;Best regards&lt;/P&gt;</description>
      <pubDate>Fri, 13 Dec 2024 16:41:09 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Troubleshooting/Instrumentation-Scheduled-Tasks-in-Spring-Framework/tac-p/265272#M794</guid>
      <dc:creator>AntonPineiro</dc:creator>
      <dc:date>2024-12-13T16:41:09Z</dc:date>
    </item>
    <item>
      <title>Re: Instrumentation Scheduled Tasks in Spring Framework</title>
      <link>https://community.dynatrace.com/t5/Troubleshooting/Instrumentation-Scheduled-Tasks-in-Spring-Framework/tac-p/265282#M795</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.dynatrace.com/t5/user/viewprofilepage/user-id/58682"&gt;@AntonPineiro&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;With the enabled &lt;A href="https://docs.dynatrace.com/docs/observe/applications-and-microservices/services/service-detection-and-naming/service-types/define-messaging-services#real-time-updates" target="_blank"&gt;real-time updates&lt;/A&gt; feature, restarting the JVM is not required.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best regards,&lt;/P&gt;
&lt;P&gt;Anton&lt;/P&gt;</description>
      <pubDate>Fri, 13 Dec 2024 18:49:04 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Troubleshooting/Instrumentation-Scheduled-Tasks-in-Spring-Framework/tac-p/265282#M795</guid>
      <dc:creator>anton_konikov</dc:creator>
      <dc:date>2024-12-13T18:49:04Z</dc:date>
    </item>
  </channel>
</rss>

