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, 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.
Tag Specification for Log Collection
logs:
- type: file
path: /var/log/nginx/access.log
tags: raju:ramu
source: nginx
logs:
- type: file
path: /var/log/nginx/access.log
env: raj
tags: raju:ramu, env:prod, app:web
source: nginxCode language: JavaScript (javascript)
What the tags field does in log collection
Each item under logs: in an integration config describes one log source. The Agent attaches every tag in tags to each log it ships from that source. Tags let you filter in Log Explorer (for example env:prod app:web), split queries and dashboards, build log-based metrics and monitors, and limit who can see which logs.
Tags work alongside a few reserved fields. source selects the processing pipeline that parses the logs (nginx enables the built-in Nginx pipeline). service links the logs to APM and to the Service Catalog. The Agent also adds host-level tags, such as host and any global tags set in datadog.yaml.
Corrected configuration
The second example above has two problems. The file declares logs: twice, and it uses env: raj as if env 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. env 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:
# /etc/datadog-agent/conf.d/nginx.d/conf.yaml
logs:
- type: file
path: /var/log/nginx/access.log
service: web
source: nginx
tags:
- env:prod
- app:web
- team:platform
- type: file
path: /var/log/nginx/error.log
service: web
source: nginx
tags:
- env:prod
- app:webCode language: PHP (php)
- One
logs:key holds a list. Add more sources as more- type: fileitems under that key. tagsis written as a YAML list. The inline formtags: ["env:prod", "app:web"]is equivalent. Both are clearer than a single comma-separated string.serviceis set explicitly. If you leave it out, logs may show up under a generic or missing service name.- Placeholder tags such as
raju:ramufrom the example above work, but use meaningful keys liketeam,apporownerin real configs.
Note: Use the same env value everywhere (Agent, APM, metrics). A tag like env:prod on logs and env:production on traces breaks correlation between the two.
Prerequisites and applying the change
- Turn on log collection in
/etc/datadog-agent/datadog.yamlby settinglogs_enabled: true. It is off by default. - Put the config above in
/etc/datadog-agent/conf.d/nginx.d/conf.yaml. If the Nginx integration is already set up for metrics, add thelogs:block to that same file. - Make sure the
dd-agentuser can read the log files. On Debian and Ubuntu, Nginx logs usually belong to theadmgroup:sudo usermod -aG adm dd-agent. - Restart the Agent:
sudo systemctl restart datadog-agent. - Generate some traffic, for example
curl -s http://localhost/ > /dev/null, then check the Agent status.
Verifying tags
sudo datadog-agent configcheck # confirms the nginx config loaded without errors
sudo datadog-agent status # see the "Logs Agent" section
sudo datadog-agent stream-logs # live view of logs being processed (recent Agent versions)Code language: PHP (php)
In the status output, the Logs Agent section lists each source with its path, a status of OK, and bytes read. A permission error or a wrong path also appears here. In Datadog, open Log Explorer and search service:web env:prod. Click a log line to see its tags in the side panel.
Note: In Log Explorer, tags are searched without a prefix (env:prod), while attributes parsed from the log body use @ (@http.status_code:500). If a tag search returns nothing, check whether the value was parsed as an attribute instead.
Where else tags can be set
| Level | How | Applies to |
|---|---|---|
| Log source | tags: under a logs: item | Logs from that source only |
| Agent (global) | tags: list and env: in datadog.yaml, or the DD_TAGS / DD_ENV environment variables | All metrics, traces and logs from that host |
| Container | Autodiscovery labels or annotations, such as com.datadoghq.ad.logs, plus unified service tagging labels for env, service and version | Logs from that container |
| Pipeline | Processors in Logs > Pipelines (remappers, category processors) | Logs after ingestion |
Global Agent tags look like this in datadog.yaml. Tags from all levels are combined on each log:
env: prod
tags:
- team:platform
- region:ap-south-1Code language: CSS (css)
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| No logs in Datadog at all | logs_enabled is not true | Set it in datadog.yaml and restart the Agent |
| Status shows a permission denied error | dd-agent cannot read the file | Add dd-agent to the owning group, or adjust file permissions |
| Only one source is collected | Duplicate logs: keys in one file | Merge them into one logs: list |
env tag missing | Used env: as a log parameter | Move it into tags: or set env globally |
| Config not loaded | YAML indentation or tab characters | Run datadog-agent configcheck and use spaces only |
Tagging best practices
- Always use the
key:valueform. A bare tag without a key is hard to group by. - Keep tags lowercase and consistent. Agree on a small set of keys, such as
env,service,version,teamandapp, and document them. - Use the reserved
env,serviceandversiontags (unified service tagging) so logs, traces and metrics link together. - 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.
- Set host-wide tags once at the Agent level rather than repeating them in every log source.
Frequently asked questions
How do I add multiple tags to a Datadog log source?
List them under tags: as YAML list items, for example - env:prod and - app:web, or inline as tags: ["env:prod", "app:web"]. Every log collected from that source gets all of the listed tags.
Can I set env directly on a log source in the Datadog Agent?
No. env is not a valid log source parameter, so the Agent ignores it. Add env:prod to the source's tags, or set env globally in datadog.yaml or with DD_ENV.
Why are my log tags not showing in Datadog?
Common causes are logs_enabled not set to true, a YAML error that stops the config from loading, or duplicate logs: keys. Run datadog-agent configcheck and datadog-agent status, then restart the Agent after fixing the file.
Do Agent global tags apply to logs?
Yes. Tags set with tags: in datadog.yaml or with DD_TAGS are added to logs from that host, along with any tags defined on the individual log source.
What is the difference between source and service in a log config?
source names the technology that produced the log and picks the matching processing pipeline, such as nginx. service names your application and links the logs to APM traces and the Service Catalog.
Related tutorials
- Datadog Log: Lab and Assignment
- Datadog Troubleshooting Master Guide
- Datadog Agent CLI โ datadog-agent and Windows agent.exe with examples
- More Datadog tutorials
I’m Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms.
I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.
Find Trusted Cardiac Hospitals
Compare heart hospitals by city and services โ all in one place.
Explore Hospitals
An additional point worth covering is the long-term governance of tags in large environments. Tagging becomes significantly more valuable when every team follows the same naming conventions and classification rules. A standardized approach makes it easier to filter metrics, troubleshoot issues, assign ownership, and generate meaningful reports, while preventing the confusion that often results from inconsistent or duplicate tags.