{"id":33091,"date":"2026-11-21T22:05:33","date_gmt":"2026-11-21T22:05:33","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=33091"},"modified":"2026-11-21T22:05:33","modified_gmt":"2026-11-21T22:05:33","slug":"datadog-tutorials-tag-specifications","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/datadog-tutorials-tag-specifications\/","title":{"rendered":"Datadog Tutorials: Tag Specifications"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">In a Datadog Agent log collection config, the <code>tags<\/code> field adds <code>key:value<\/code> tags to every log line the Agent collects from a source. You can then filter, group and control access to those logs in Datadog. This page explains the examples above, corrects two problems in them, and covers how to verify tags and which tagging conventions to follow.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Tag Specification for Log Collection<\/h2>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">logs:\r\n  - type: file\r\n    <span class=\"hljs-attr\">path<\/span>: <span class=\"hljs-regexp\">\/var\/<\/span>log\/nginx\/access.log\r\n    <span class=\"hljs-attr\">tags<\/span>: raju:ramu\r\n    <span class=\"hljs-attr\">source<\/span>: nginx\r\n\r\n<span class=\"hljs-attr\">logs<\/span>:\r\n  - type: file\r\n    <span class=\"hljs-attr\">path<\/span>: <span class=\"hljs-regexp\">\/var\/<\/span>log\/nginx\/access.log\r\n    <span class=\"hljs-attr\">env<\/span>: raj\r\n    <span class=\"hljs-attr\">tags<\/span>: raju:ramu, <span class=\"hljs-attr\">env<\/span>:prod, <span class=\"hljs-attr\">app<\/span>:web\r\n    <span class=\"hljs-attr\">source<\/span>: nginx<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">What the tags field does in log collection<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Each item under <code>logs:<\/code> in an integration config describes one log source. The Agent attaches every tag in <code>tags<\/code> to each log it ships from that source. Tags let you filter in Log Explorer (for example <code>env:prod app:web<\/code>), split queries and dashboards, build log-based metrics and monitors, and limit who can see which logs.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Tags work alongside a few reserved fields. <code>source<\/code> selects the processing pipeline that parses the logs (<code>nginx<\/code> enables the built-in Nginx pipeline). <code>service<\/code> links the logs to APM and to the Service Catalog. The Agent also adds host-level tags, such as <code>host<\/code> and any global tags set in <code>datadog.yaml<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Corrected configuration<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The second example above has two problems. The file declares <code>logs:<\/code> twice, and it uses <code>env: raj<\/code> as if <code>env<\/code> were a log setting. Duplicate top-level keys are invalid YAML. Depending on the parser, the Agent either rejects the file or quietly keeps only the last block. <code>env<\/code> is not a valid parameter for a log source, so the Agent ignores it. Set the environment as a tag instead. Here is a single valid file:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-comment\"># \/etc\/datadog-agent\/conf.d\/nginx.d\/conf.yaml<\/span>\nlogs:\n  - type: file\n    path: \/<span class=\"hljs-keyword\">var<\/span>\/log\/nginx\/access.log\n    service: web\n    source: nginx\n    tags:\n      - env:prod\n      - app:web\n      - team:platform\n\n  - type: file\n    path: \/<span class=\"hljs-keyword\">var<\/span>\/log\/nginx\/error.log\n    service: web\n    source: nginx\n    tags:\n      - env:prod\n      - app:web<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<ul class=\"wp-block-list\">\n<li>One <code>logs:<\/code> key holds a list. Add more sources as more <code>- type: file<\/code> items under that key.<\/li>\n\n\n<li><code>tags<\/code> is written as a YAML list. The inline form <code>tags: [&quot;env:prod&quot;, &quot;app:web&quot;]<\/code> is equivalent. Both are clearer than a single comma-separated string.<\/li>\n\n\n<li><code>service<\/code> is set explicitly. If you leave it out, logs may show up under a generic or missing service name.<\/li>\n\n\n<li>Placeholder tags such as <code>raju:ramu<\/code> from the example above work, but use meaningful keys like <code>team<\/code>, <code>app<\/code> or <code>owner<\/code> in real configs.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Note:<\/strong> Use the same <code>env<\/code> value everywhere (Agent, APM, metrics). A tag like <code>env:prod<\/code> on logs and <code>env:production<\/code> on traces breaks correlation between the two.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites and applying the change<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Turn on log collection in <code>\/etc\/datadog-agent\/datadog.yaml<\/code> by setting <code>logs_enabled: true<\/code>. It is off by default.<\/li>\n\n\n<li>Put the config above in <code>\/etc\/datadog-agent\/conf.d\/nginx.d\/conf.yaml<\/code>. If the Nginx integration is already set up for metrics, add the <code>logs:<\/code> block to that same file.<\/li>\n\n\n<li>Make sure the <code>dd-agent<\/code> user can read the log files. On Debian and Ubuntu, Nginx logs usually belong to the <code>adm<\/code> group: <code>sudo usermod -aG adm dd-agent<\/code>.<\/li>\n\n\n<li>Restart the Agent: <code>sudo systemctl restart datadog-agent<\/code>.<\/li>\n\n\n<li>Generate some traffic, for example <code>curl -s http:\/\/localhost\/ &gt; \/dev\/null<\/code>, then check the Agent status.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">Verifying tags<\/h2>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">sudo datadog-agent configcheck     <span class=\"hljs-comment\"># confirms the nginx config loaded without errors<\/span>\nsudo datadog-agent status          <span class=\"hljs-comment\"># see the \"Logs Agent\" section<\/span>\nsudo datadog-agent stream-logs     <span class=\"hljs-comment\"># live view of logs being processed (recent Agent versions)<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">In the <code>status<\/code> output, the Logs Agent section lists each source with its path, a status of <code>OK<\/code>, and bytes read. A permission error or a wrong path also appears here. In Datadog, open Log Explorer and search <code>service:web env:prod<\/code>. Click a log line to see its tags in the side panel.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Note:<\/strong> In Log Explorer, tags are searched without a prefix (<code>env:prod<\/code>), while attributes parsed from the log body use <code>@<\/code> (<code>@http.status_code:500<\/code>). If a tag search returns nothing, check whether the value was parsed as an attribute instead.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Where else tags can be set<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Level<\/th><th>How<\/th><th>Applies to<\/th><\/tr><\/thead><tbody><tr><td>Log source<\/td><td><code>tags:<\/code> under a <code>logs:<\/code> item<\/td><td>Logs from that source only<\/td><\/tr><tr><td>Agent (global)<\/td><td><code>tags:<\/code> list and <code>env:<\/code> in <code>datadog.yaml<\/code>, or the <code>DD_TAGS<\/code> \/ <code>DD_ENV<\/code> environment variables<\/td><td>All metrics, traces and logs from that host<\/td><\/tr><tr><td>Container<\/td><td>Autodiscovery labels or annotations, such as <code>com.datadoghq.ad.logs<\/code>, plus unified service tagging labels for env, service and version<\/td><td>Logs from that container<\/td><\/tr><tr><td>Pipeline<\/td><td>Processors in Logs &gt; Pipelines (remappers, category processors)<\/td><td>Logs after ingestion<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Global Agent tags look like this in <code>datadog.yaml<\/code>. Tags from all levels are combined on each log:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-tag\">env<\/span>: <span class=\"hljs-selector-tag\">prod<\/span>\n<span class=\"hljs-selector-tag\">tags<\/span>:\n  <span class=\"hljs-selector-tag\">-<\/span> <span class=\"hljs-selector-tag\">team<\/span><span class=\"hljs-selector-pseudo\">:platform<\/span>\n  <span class=\"hljs-selector-tag\">-<\/span> <span class=\"hljs-selector-tag\">region<\/span><span class=\"hljs-selector-pseudo\">:ap-south-1<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\">Common errors<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Symptom<\/th><th>Likely cause<\/th><th>Fix<\/th><\/tr><\/thead><tbody><tr><td>No logs in Datadog at all<\/td><td><code>logs_enabled<\/code> is not <code>true<\/code><\/td><td>Set it in <code>datadog.yaml<\/code> and restart the Agent<\/td><\/tr><tr><td>Status shows a permission denied error<\/td><td><code>dd-agent<\/code> cannot read the file<\/td><td>Add <code>dd-agent<\/code> to the owning group, or adjust file permissions<\/td><\/tr><tr><td>Only one source is collected<\/td><td>Duplicate <code>logs:<\/code> keys in one file<\/td><td>Merge them into one <code>logs:<\/code> list<\/td><\/tr><tr><td><code>env<\/code> tag missing<\/td><td>Used <code>env:<\/code> as a log parameter<\/td><td>Move it into <code>tags:<\/code> or set <code>env<\/code> globally<\/td><\/tr><tr><td>Config not loaded<\/td><td>YAML indentation or tab characters<\/td><td>Run <code>datadog-agent configcheck<\/code> and use spaces only<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Tagging best practices<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Always use the <code>key:value<\/code> form. A bare tag without a key is hard to group by.<\/li>\n\n\n<li>Keep tags lowercase and consistent. Agree on a small set of keys, such as <code>env<\/code>, <code>service<\/code>, <code>version<\/code>, <code>team<\/code> and <code>app<\/code>, and document them.<\/li>\n\n\n<li>Use the reserved <code>env<\/code>, <code>service<\/code> and <code>version<\/code> tags (unified service tagging) so logs, traces and metrics link together.<\/li>\n\n\n<li>Never put high-cardinality or sensitive values such as user IDs, request IDs, emails or tokens in tags. Leave them in the log body as attributes, and scrub secrets.<\/li>\n\n\n<li>Set host-wide tags once at the Agent level rather than repeating them in every log source.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Frequently asked questions<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">How do I add multiple tags to a Datadog log source?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">List them under <code>tags:<\/code> as YAML list items, for example <code>- env:prod<\/code> and <code>- app:web<\/code>, or inline as <code>tags: [&quot;env:prod&quot;, &quot;app:web&quot;]<\/code>. Every log collected from that source gets all of the listed tags.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Can I set env directly on a log source in the Datadog Agent?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No. <code>env<\/code> is not a valid log source parameter, so the Agent ignores it. Add <code>env:prod<\/code> to the source&#039;s <code>tags<\/code>, or set <code>env<\/code> globally in <code>datadog.yaml<\/code> or with <code>DD_ENV<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Why are my log tags not showing in Datadog?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Common causes are <code>logs_enabled<\/code> not set to <code>true<\/code>, a YAML error that stops the config from loading, or duplicate <code>logs:<\/code> keys. Run <code>datadog-agent configcheck<\/code> and <code>datadog-agent status<\/code>, then restart the Agent after fixing the file.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Do Agent global tags apply to logs?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Yes. Tags set with <code>tags:<\/code> in <code>datadog.yaml<\/code> or with <code>DD_TAGS<\/code> are added to logs from that host, along with any tags defined on the individual log source.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">What is the difference between source and service in a log config?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><code>source<\/code> names the technology that produced the log and picks the matching processing pipeline, such as <code>nginx<\/code>. <code>service<\/code> names your application and links the logs to APM traces and the Service Catalog.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Related tutorials<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.devopsschool.com\/blog\/datadog-log-lab-and-assignment\/\">Datadog Log: Lab and Assignment<\/a><\/li>\n\n\n<li><a href=\"https:\/\/www.devopsschool.com\/blog\/datadog-agent-troubleshooting-guide\/\">Datadog Troubleshooting Master Guide<\/a><\/li>\n\n\n<li><a href=\"https:\/\/www.devopsschool.com\/blog\/list-of-all-datadog-agent-commands-with-examples-and-explainations\/\">Datadog Agent CLI \u2014 datadog-agent and Windows agent.exe with examples<\/a><\/li>\n\n\n<li><a href=\"https:\/\/www.devopsschool.com\/blog\/category\/monitoring-observability\/datadog\/\">More Datadog tutorials<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>In a Datadog Agent log collection config, the tags field adds key:value tags to every log line the Agent collects from a source. You can then filter,&#8230; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[25768],"tags":[26270,4672],"class_list":["post-33091","post","type-post","status-publish","format-standard","hentry","category-datadog","tag-datadog-agent","tag-log-management"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/33091","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=33091"}],"version-history":[{"count":2,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/33091\/revisions"}],"predecessor-version":[{"id":80091,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/33091\/revisions\/80091"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=33091"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=33091"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=33091"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}