<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Datadog Archives - Codersee blog- Kotlin on the backend</title>
	<atom:link href="https://blog.codersee.com/tag/datadog/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>Kotlin &#38; Backend Tutorials - Learn Through Practice.</description>
	<lastBuildDate>Wed, 16 Apr 2025 04:49:36 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://blog.codersee.com/wp-content/uploads/2025/04/cropped-codersee_logo_circle_2-32x32.png</url>
	<title>Datadog Archives - Codersee blog- Kotlin on the backend</title>
	<link></link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Sending Spring Boot Metrics to Datadog</title>
		<link>https://blog.codersee.com/sending-spring-boot-metrics-datadog/</link>
					<comments>https://blog.codersee.com/sending-spring-boot-metrics-datadog/#respond</comments>
		
		<dc:creator><![CDATA[Piotr]]></dc:creator>
		<pubDate>Tue, 27 Aug 2024 04:00:00 +0000</pubDate>
				<category><![CDATA[Spring]]></category>
		<category><![CDATA[Datadog]]></category>
		<category><![CDATA[Metrics]]></category>
		<category><![CDATA[Micrometer]]></category>
		<category><![CDATA[Monitoring]]></category>
		<category><![CDATA[Spring Boot]]></category>
		<guid isPermaLink="false">https://codersee.com/?p=11009048</guid>

					<description><![CDATA[<p>A step-by-step guide on how to implement and configure a Spring Boot application to send metrics to Datadog.</p>
<p>The post <a href="https://blog.codersee.com/sending-spring-boot-metrics-datadog/">Sending Spring Boot Metrics to Datadog</a> appeared first on <a href="https://blog.codersee.com">Codersee blog- Kotlin on the backend</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Hello and welcome to the next article in which we will briefly discuss Datadog and Micrometer, but what&#8217;s more important- we will learn how to send <strong>Spring Boot metrics</strong> to <strong>Datadog in practice</strong>.</p>



<p>Moreover, we will take a quick look into the Spring Boot Actuator and how it can help us, so, to let&#8217;s not waste our time and let&#8217;s get to work! 🙂 </p>



<h2 class="wp-block-heading" id="h-video-tutorial">Video Tutorial</h2>



<p>If you prefer <strong>video content</strong>, then check out my video:</p>



<div style="text-align: center; width: 90%; margin-left: 5%;">
<a href="https://blog.codersee.com/sending-spring-boot-metrics-datadog/"><img decoding="async" src="https://blog.codersee.com/wp-content/plugins/wp-youtube-lyte/lyteCache.php?origThumbUrl=%2F%2Fi.ytimg.com%2Fvi%2F2YHVgbJGzqU%2Fhqdefault.jpg" alt="YouTube Video"></a><br /><br /></p></div>



<p>If you find this content useful,<strong> please leave a subscription</strong> 🙂</p>



<h2 class="wp-block-heading" id="h-datadog">Datadog</h2>



<p>If you came here directly, then I bet you already know what <a href="https://www.datadoghq.com/" target="_blank" rel="noreferrer noopener">Datadog</a> is and what purpose it will serve in your project.</p>



<p>However, for those who hear about it for the first time, let me give you a really short intro.</p>



<p>Long story short- Datadog is an <strong>integrated platform for monitoring &amp; security</strong>. It provides tools for monitoring applications, databases, distributed tracing, logs management, and many many more. In other words, makes all the things that are not so cool, but necessary in production-ready environments, a bit less painful 😉</p>



<p>However, what is the most important for us today- it provides tools to <strong>collect metrics</strong> from our applications so that later we can make use of them.</p>



<p>But, what are they? </p>



<h2 class="wp-block-heading" id="h-what-are-metrics">What Are Metrics? </h2>



<p>According to the Datadog documentation:</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>Metrics are numerical values that can track anything about your environment over time.</p>
</blockquote>



<p>And I must admit- I love this definition for its completeness in its simplicity.</p>



<p>Because basically, <strong>metric</strong> is everything in our system that we can assign a number to and track. From Garbage Collector stats, JVM memory, CPU, and request latency, to the average cart size. Literally everything.</p>



<p>And in this tutorial, we will see how to send metrics <strong>collected automatically</strong> by our Spring Boot app to DataDog.</p>



<h2 class="wp-block-heading" id="h-create-new-project">Create New Project</h2>



<p>As the first step, let&#8217;s navigate to the <a href="https://start.spring.io/" target="_blank" rel="noreferrer noopener">Spring Initializr page</a>, select the following and import the project to our IDE:</p>



<figure class="wp-block-image aligncenter size-large is-resized"><img fetchpriority="high" decoding="async" width="1024" height="511" src="http://blog.codersee.com/wp-content/uploads/2024/08/spring_boot_datadog_actuator_1-1024x511.png" alt="Screenshot presents the Spring Initializr page with Spring Boot Actuator and Spring Web dependencies selected." class="wp-image-11009063" style="width:840px;height:auto" srcset="https://blog.codersee.com/wp-content/uploads/2024/08/spring_boot_datadog_actuator_1-1024x511.png 1024w, https://blog.codersee.com/wp-content/uploads/2024/08/spring_boot_datadog_actuator_1-300x150.png 300w, https://blog.codersee.com/wp-content/uploads/2024/08/spring_boot_datadog_actuator_1-768x383.png 768w, https://blog.codersee.com/wp-content/uploads/2024/08/spring_boot_datadog_actuator_1.png 1527w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>Apart from versions and metadata, we can see that we added two dependencies: <strong>Spring Web</strong> and <strong>Spring Boot Actuator.</strong> </p>



<p>The first one is quite obvious, but in terms of metrics Spring Boot Actuator provides dependency management and auto-configuration for <strong>Micrometer</strong> &#8211; a vendor-neutral application observability facade. </p>



<p>With that, Spring Boot takes care of configuring <code>MeterRegistry</code> and the only thing we need to do is to add the <code>micrometer-registry-{system}</code> dependency to the <code>build.gradle.kts</code> :</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">implementation("io.micrometer:micrometer-registry-datadog")</pre>



<p><strong>Note:</strong> we could achieve exactly the same using the Spring Initializr page and searching for the Datadog dependency, but I wanted to emphasize the fact, that other vendors, like Elastic, or OpenTelemetry can be added in the same manner.  </p>



<h2 class="wp-block-heading" id="h-verify-and-expose-metrics-endpoint">Verify and Expose Metrics Endpoint</h2>



<p>After we import our project, let&#8217;s run it, and let&#8217;s take a look at the endpoints exposed by default by Spring Boot Actuator: </p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">curl --location --request GET 'http://localhost:8080/actuator' </pre>



<p>As a result, we should see the following: </p>



<pre class="EnlighterJSRAW" data-enlighter-language="json" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">{
    "_links": {
        "self": {
            "href": "http://localhost:8080/actuator",
            "templated": false
        },
        "health": {
            "href": "http://localhost:8080/actuator/health",
            "templated": false
        },
        "health-path": {
            "href": "http://localhost:8080/actuator/health/{*path}",
            "templated": true
        }
    }
}</pre>



<p>And the first lesson is that <strong>the metrics endpoint is not exposed by default.</strong></p>



<p>So to change that, let&#8217;s navigate to the <code>application.yaml</code> and add the following:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="yaml" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">management:
  endpoints:
    web:
      exposure:
        include: metrics, health</pre>



<p>After that, let&#8217;s rerun the application. </p>



<p>As a result, this time, we should see that two new endpoints are present: </p>



<pre class="EnlighterJSRAW" data-enlighter-language="json" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">{
    "_links": {
        "self": {
            "href": "http://localhost:8080/actuator",
            "templated": false
        },
        "health": {
            "href": "http://localhost:8080/actuator/health",
            "templated": false
        },
        "health-path": {
            "href": "http://localhost:8080/actuator/health/{*path}",
            "templated": true
        },
        "metrics-requiredMetricName": {
            "href": "http://localhost:8080/actuator/metrics/{requiredMetricName}",
            "templated": true
        },
        "metrics": {
            "href": "http://localhost:8080/actuator/metrics",
            "templated": false
        }
    }
}</pre>



<p>The last one- <code>/actuator/metrics</code>&#8211; simply <strong>displays a list of available meter names</strong>, and when we invoke it, we should see the following JSON response: </p>



<pre class="EnlighterJSRAW" data-enlighter-language="json" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">{
    "names": [
        "application.ready.time",
        "application.started.time",
        "disk.free",
        "disk.total",
        "executor.active",
        "executor.completed",
        "executor.pool.core",
        "executor.pool.max",
        "executor.pool.size",
        "executor.queue.remaining",
        "executor.queued",
        "http.server.requests",
        "http.server.requests.active",
        "jvm.buffer.count",
        "jvm.buffer.memory.used",
        "jvm.buffer.total.capacity",
        "jvm.classes.loaded",
        "jvm.classes.unloaded",
        "jvm.compilation.time",
        "jvm.gc.concurrent.phase.time",
        "jvm.gc.live.data.size",
        "jvm.gc.max.data.size",
        "jvm.gc.memory.allocated",
        "jvm.gc.memory.promoted",
        "jvm.gc.overhead",
        "jvm.gc.pause",
        "jvm.info",
        "jvm.memory.committed",
        "jvm.memory.max",
        "jvm.memory.usage.after.gc",
        "jvm.memory.used",
        "jvm.threads.daemon",
        "jvm.threads.live",
        "jvm.threads.peak",
        "jvm.threads.started",
        "jvm.threads.states",
        "logback.events",
        "process.cpu.time",
        "process.cpu.usage",
        "process.start.time",
        "process.uptime",
        "system.cpu.count",
        "system.cpu.usage",
        "tomcat.sessions.active.current",
        "tomcat.sessions.active.max",
        "tomcat.sessions.alive.max",
        "tomcat.sessions.created",
        "tomcat.sessions.expired",
        "tomcat.sessions.rejected"
    ]
}</pre>



<p>In simple words, this is the list of all metrics collected at this point by our Spring Boot application. And yes- we will be able to export them to Datadog. </p>



<p>Nevertheless, let&#8217;s verify what the second endpoint- <code>/actuator/metrics/{requiredMetricName}</code>&#8211; does.</p>



<p>To do that, let&#8217;s make a GET request and specify any metric name:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">curl --location --request GET 'http://localhost:8080/actuator/metrics/process.cpu.usage'</pre>



<p>This time, the endpoint will return metric details along with the <strong>current value</strong>:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="json" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">{
    "name": "process.cpu.usage",
    "description": "The \"recent cpu usage\" for the Java Virtual Machine process",
    "measurements": [
        {
            "statistic": "VALUE",
            "value": 0.038209510879134205
        }
    ],
    "availableTags": []
}</pre>



<h2 class="wp-block-heading" id="h-create-datadog-account">Create Datadog Account</h2>



<p>Excellent! At this point, we are sure that our Spring Boot app collects metrics, so it&#8217;s time to proceed with the Datadog part. </p>



<p>If you haven&#8217;t done it yet, then let&#8217;s create a trial account together. </p>



<p>Let&#8217;s navigate to the <a href="https://www.datadoghq.com/">https://www.datadoghq.com/</a> and click the &#8220;Free trial&#8221; button:</p>



<figure class="wp-block-image aligncenter size-large"><img decoding="async" width="1024" height="456" src="http://blog.codersee.com/wp-content/uploads/2024/08/spring_boot_datadog_free_trial_2-1024x456.png" alt="Screenshot presents the main page of Datadog site with free trial button." class="wp-image-11009071" srcset="https://blog.codersee.com/wp-content/uploads/2024/08/spring_boot_datadog_free_trial_2-1024x456.png 1024w, https://blog.codersee.com/wp-content/uploads/2024/08/spring_boot_datadog_free_trial_2-300x134.png 300w, https://blog.codersee.com/wp-content/uploads/2024/08/spring_boot_datadog_free_trial_2-768x342.png 768w, https://blog.codersee.com/wp-content/uploads/2024/08/spring_boot_datadog_free_trial_2.png 1397w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>Following, let&#8217;s fill out the signup form: </p>



<figure class="wp-block-image aligncenter size-full"><img decoding="async" width="532" height="867" src="http://blog.codersee.com/wp-content/uploads/2024/08/spring_boot_datadog_sign_up_form_3_1.png" alt="Image is a screenshot of the Datadog signup form" class="wp-image-11009072" srcset="https://blog.codersee.com/wp-content/uploads/2024/08/spring_boot_datadog_sign_up_form_3_1.png 532w, https://blog.codersee.com/wp-content/uploads/2024/08/spring_boot_datadog_sign_up_form_3_1-184x300.png 184w" sizes="(max-width: 532px) 100vw, 532px" /></figure>



<p>And with that done, when we confirm our e-mail address, we will land on this page: </p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="960" height="1006" src="http://blog.codersee.com/wp-content/uploads/2024/08/spring_boot_datadog_key_4.png" alt="Screenshot presents the Datadog agent setup page. " class="wp-image-11009073" srcset="https://blog.codersee.com/wp-content/uploads/2024/08/spring_boot_datadog_key_4.png 960w, https://blog.codersee.com/wp-content/uploads/2024/08/spring_boot_datadog_key_4-286x300.png 286w, https://blog.codersee.com/wp-content/uploads/2024/08/spring_boot_datadog_key_4-768x805.png 768w" sizes="auto, (max-width: 960px) 100vw, 960px" /></figure>



<p>As we can see, the above page contains a bunch of guides on how to set up the agent. </p>



<p>And although we are not interested in any of those, this page has one, valuable information for us- the <strong>API key</strong>. </p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p><strong>Note:</strong> I think that readers of this blog are well aware of that, but for my own peace of mind- API keys are vulnerable data, so you <strong>must be cautious</strong> with them! 🙂 </p>
</blockquote>



<p>At this point, please copy this value and we will use it in the proceeding steps. </p>



<h2 class="wp-block-heading" id="h-configure-app-to-send-metrics">Configure App To Send Metrics</h2>



<p>When we have our Datadog account ready, we can finally configure our app. </p>



<h3 class="wp-block-heading" id="h-api-key">API Key</h3>



<p>Firstly, let&#8217;s get back to our Spring Boot project and update the <code>application.yaml</code> :</p>



<pre class="EnlighterJSRAW" data-enlighter-language="yaml" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">management:
  endpoints:
    web:
      exposure:
        include: metrics, health
  datadog:
    metrics:
      export:
        api-key: YOUR_KEY_VALUE</pre>



<p>Of course, we must replace the <code>YOUR_KEY_VALUE</code> with the actual API key. </p>



<h3 class="wp-block-heading" id="h-update-datadog-uri">Update Datadog URI </h3>



<p>If you are using Datadog US (the option you could select when signing up), then that&#8217;s pretty much it and you can restart the application.</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>By default, metrics are sent to the Datadog US site (api.datadoghq.com). If your Datadog project is hosted on one of the other sites, or you need to send metrics through a proxy, configure the URI accordingly.</p>
</blockquote>



<p>So given the above, if we use another region, then we need to add one more line: </p>



<pre class="EnlighterJSRAW" data-enlighter-language="yaml" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">management:
  endpoints:
    web:
      exposure:
        include: metrics, health
  datadog:
    metrics:
      export:
        api-key: YOUR_KEY_VALUE 
        uri: https://api.datadoghq.eu</pre>



<h3 class="wp-block-heading" id="h-update-metrics-upload-interval">Update Metrics Upload Interval</h3>



<p>Following, let&#8217;s see how easily we can update the interval, in which data are sent to Datadog: </p>



<pre class="EnlighterJSRAW" data-enlighter-language="yaml" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">management:
  endpoints:
    web:
      exposure:
        include: metrics, health
  datadog:
    metrics:
      export:
        api-key: YOUR_KEY_VALUE 
        uri: https://api.datadoghq.eu
        step: 10s</pre>



<p>The default value is <strong>30 seconds</strong>. And to change that, the only thing we need to do is to add the <code>step</code> value. </p>



<h3 class="wp-block-heading" id="h-set-spring-logging-level-to-debug">Set Spring Logging Level to DEBUG</h3>



<p>As the last thing, which technically is not directly related to sending metrics, I would like to add the following to the root of our <code>application.yaml</code> file: </p>



<pre class="EnlighterJSRAW" data-enlighter-language="yaml" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">logging:
  level:
    root: DEBUG</pre>



<p>This way we set the logging level in our Spring Boot application to <code>DEBUG</code>. </p>



<p>Why? It will be useful in a moment when we will be testing our implementation. </p>



<h2 class="wp-block-heading" id="h-testing">Testing </h2>



<p>With all of that done, we can finally verify that everything is working properly. </p>



<h3 class="wp-block-heading" id="h-verify-spring-boot-sends-data-to-datadog">Verify Spring Boot Sends Data to Datadog</h3>



<p>Firstly, let&#8217;s rerun our application and take a look at the logs.</p>



<p>If we see the following: </p>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">i.m.datadog.DatadogMeterRegistry         : successfully sent 78 metrics to datadog</pre>



<p>Then data are successfully sent to the Datadog API. </p>



<p>Let&#8217;s leave it running for some time (like 2 minutes, or something), so that we have actual data later to work with 🙂 </p>



<h2 class="wp-block-heading" id="h-review-metrics-in-datadog">Review Metrics in Datadog </h2>



<p>After that time, the only thing left is to take a look at metrics in Datadog. </p>



<p>If we haven&#8217;t closed the Datadog &#8220;Agent Setup&#8221; page, then it should automatically close and redirect us to the dashboard. </p>



<p>However, if that didn&#8217;t happen, then no worries, we can simply navigate to the <a href="https://app.datadoghq.eu/metric/summary" target="_blank" rel="noreferrer noopener">metrics summary page</a>: </p>



<figure class="wp-block-image aligncenter size-large"><img loading="lazy" decoding="async" width="1024" height="733" src="http://blog.codersee.com/wp-content/uploads/2024/08/spring_boot_datadog_metrics_summary_5-1024x733.png" alt="Screenshot presents the Datadog metrics summary page where all Spring Boot metrics are displayed." class="wp-image-11009076" srcset="https://blog.codersee.com/wp-content/uploads/2024/08/spring_boot_datadog_metrics_summary_5-1024x733.png 1024w, https://blog.codersee.com/wp-content/uploads/2024/08/spring_boot_datadog_metrics_summary_5-300x215.png 300w, https://blog.codersee.com/wp-content/uploads/2024/08/spring_boot_datadog_metrics_summary_5-768x550.png 768w, https://blog.codersee.com/wp-content/uploads/2024/08/spring_boot_datadog_metrics_summary_5.png 1350w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>On this page, we can see all the metrics that have been gathered so far. Long story short, this page contains meta-information about metrics themselves, like tags, etc. </p>



<p>I strongly recommend you spend here some time and figure out different options. </p>



<p>And if we would like to take a look at the actual values, then let&#8217;s navigate to the <a href="https://app.datadoghq.eu/metric/explorer" target="_blank" rel="noreferrer noopener">metrics explorer</a>: </p>



<figure class="wp-block-image aligncenter size-large"><img loading="lazy" decoding="async" width="1024" height="249" src="http://blog.codersee.com/wp-content/uploads/2024/08/spring_boot_datadog_metrics_explorer_6-1024x249.png" alt="Screenshot presents Datadog metrics explorer with jvm memory used metric chart." class="wp-image-11009077" srcset="https://blog.codersee.com/wp-content/uploads/2024/08/spring_boot_datadog_metrics_explorer_6-1024x249.png 1024w, https://blog.codersee.com/wp-content/uploads/2024/08/spring_boot_datadog_metrics_explorer_6-300x73.png 300w, https://blog.codersee.com/wp-content/uploads/2024/08/spring_boot_datadog_metrics_explorer_6-768x187.png 768w, https://blog.codersee.com/wp-content/uploads/2024/08/spring_boot_datadog_metrics_explorer_6-1536x373.png 1536w, https://blog.codersee.com/wp-content/uploads/2024/08/spring_boot_datadog_metrics_explorer_6-2048x498.png 2048w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>I know, the image is quite small (the &#8220;Open Image in New Tab&#8221; option will help here 😉 ). However, the only thing we need to do here is to specify the metric name in the left upper part and the period we would like to view in the right upper part. </p>



<p>After that, we will see the above chart. </p>



<p>And basically, that&#8217;s how metrics work with Spring Boot and Datadog, but please don&#8217;t close this article yet, I wanted to show you two, interesting things that may be useful to you in real life. </p>



<h2 class="wp-block-heading" id="h-sending-custom-tags">Sending Custom Tags </h2>



<p><strong>Tags</strong> are nothing else, than additional metadata you can send with metrics.  </p>



<p>Why are they useful? Well, thanks to them we can later differentiate different metrics. For example, we can send a tag with the application name, so that later we will group metrics by microservices, or environment value, like dev, staging, or prod. </p>



<p>In Spring Boot, we have several ways to achieve that. And probably the easiest way is to (again) update the <code>application.yaml</code>:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="yaml" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">management:
  endpoints:
    web:
      exposure:
        include: metrics, health
  datadog:
    metrics:
      export:
        api-key: YOUR_KEY_VALUE 
        uri: https://api.datadoghq.eu
        step: 10s
  metrics:
    tags:
      application: "my-app-one"</pre>



<p>As we can see, we can add a custom tag by using  <code>metrics.tags</code> and specifying that as a key-value pair. In our case- the <code>application</code> tag has the <code>my-app-one</code> value. </p>



<p>This approach is not only straightforward but also quite flexible. We could always put a placeholder for the environment variable instead of the hardcoded value. </p>



<p>Anyway, when we rerun our application and let Spring send some metrics to the Datadog, we will see that from now on we can <strong>filter values using the &#8220;from&#8221; field:</strong></p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="281" src="http://blog.codersee.com/wp-content/uploads/2024/08/spring_boot_datadog_metrics_explorer_custom_tag_7-1024x281.png" alt="" class="wp-image-11009080" srcset="https://blog.codersee.com/wp-content/uploads/2024/08/spring_boot_datadog_metrics_explorer_custom_tag_7-1024x281.png 1024w, https://blog.codersee.com/wp-content/uploads/2024/08/spring_boot_datadog_metrics_explorer_custom_tag_7-300x82.png 300w, https://blog.codersee.com/wp-content/uploads/2024/08/spring_boot_datadog_metrics_explorer_custom_tag_7-768x210.png 768w, https://blog.codersee.com/wp-content/uploads/2024/08/spring_boot_datadog_metrics_explorer_custom_tag_7-1536x421.png 1536w, https://blog.codersee.com/wp-content/uploads/2024/08/spring_boot_datadog_metrics_explorer_custom_tag_7-2048x561.png 2048w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>Again, the &#8220;Open Image in New Tab&#8221; may be helpful here 😉 </p>



<h2 class="wp-block-heading" id="h-turn-off-metrics-export">Turn Off Metrics Export</h2>



<p>As the last thing, let&#8217;s take a look at how we can instruct our Spring app to <strong>stop sending metrics to Datadog</strong>.</p>



<p>Again, let&#8217;s navigate to the <code>application.yaml</code> file and set the <code>enabled</code> flag to false: </p>



<pre class="EnlighterJSRAW" data-enlighter-language="yaml" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">management:
  endpoints:
    web:
      exposure:
        include: metrics, health
  datadog:
    metrics:
      export:
        enabled: false
        api-key: YOURE_KEY_VALUE
        uri: https://api.datadoghq.eu
        step: 10s</pre>



<p>Of course, we can use an environment variable placeholder (like <code>${DATADOG_ENABLED}</code>) and turn on/off export in different environments. </p>



<h2 class="wp-block-heading" id="h-summary">Summary </h2>



<p>That&#8217;s all for this tutorial on <strong>how to send Spring Boot metrics to Datadog</strong>. </p>



<p>As always, you can find the source code in <a href="https://github.com/codersee-blog/spring-boot-3-kotlin-datadog" target="_blank" rel="noreferrer noopener">this GitHub repository</a>.</p>



<p>Have a great day and don&#8217;t forget to <strong>leave a comment</strong>! 😀</p>
<p>The post <a href="https://blog.codersee.com/sending-spring-boot-metrics-datadog/">Sending Spring Boot Metrics to Datadog</a> appeared first on <a href="https://blog.codersee.com">Codersee blog- Kotlin on the backend</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.codersee.com/sending-spring-boot-metrics-datadog/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Page Caching using Disk: Enhanced 

Served from: blog.codersee.com @ 2026-05-14 22:06:30 by W3 Total Cache
-->