Skip to content

Instantly share code, notes, and snippets.

@ajazfarhad
Created May 12, 2020 13:00
Show Gist options
  • Save ajazfarhad/0af0c81ab1e2e480a1b77bbadc5f4e91 to your computer and use it in GitHub Desktop.
Save ajazfarhad/0af0c81ab1e2e480a1b77bbadc5f4e91 to your computer and use it in GitHub Desktop.
docker-compose file for Rails API and Datadog Agent
version: "3.7"
services:
db:
image: postgres
environment:
POSTGRES_PASSWORD: password
volumes:
- ./tmp/db:/var/lib/postgresql/data
app:
container_name: rails_api
build:
context: .
dockerfile: config/containers/app/Dockerfile
depends_on:
- db
ports:
- '3001:3000'
volumes:
- .:/var/www/app
labels:
com.datadoghq.ad.logs: '[{"source": "ruby", "service": "app"}]'
environment:
PG_PASSWORD: password
DATADOG_HOST: datadog
# agent section
datadog:
image: "datadog/agent:latest"
environment:
- DD_API_KEY=${DD_API_KEY}
- DD_LOGS_ENABLED=true
- DD_AC_INCLUDE="name:rails_api"
- DD_PROCESS_AGENT_ENABLED=true
- DD_SITE=datadoghq.eu
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- /proc/:/host/proc/:ro
- /sys/fs/cgroup/:/host/sys/fs/cgroup:ro
@sevetseh28
Copy link

Im trying to set this up but it's not sending the logs in my case. I run agent status on the container but it's not sending the logs. Do you have any idea ?

@ajazfarhad
Copy link
Author

Hi there, can you please share logs from local machine? or by chance you a public URL for your repo?

@sevetseh28
Copy link

sevetseh28 commented Dec 17, 2020

It's not a public repo, but this is my Docker-compose file

version: "3.8"

services:
  webserver:
    image: sig
    container_name: webserver
    environment:
      - NODE_ENV=development

      - DATADOG_HOST=datadog_agent
      - DD_AGENT_HOST=datadog_agent
      - DD_TRACE_ENABLED=true
      - DD_ENV=experimental
      - DD_LOGS_INJECTION=true

    command: npm run dev
    ports:
      - 5000:5000
    expose:
      - 5000
    labels:
      com.datadoghq.ad.logs: '[{"source": "nodejs", "service": "webserver"}]'

  datadog_agent:
    image: gcr.io/datadoghq/agent:latest
    links:
      - webserver
    ports:
      - 8126:8126
      - 8125:8125
    expose:
      - 8126
      - 8125
    environment:
      - DD_API_KEY={}
      - DD_SITE=datadoghq.eu
      - DD_APM_ENABLED=false
      - DD_PROCESS_AGENT_ENABLED=true
      - DD_LOGS_ENABLED=true
      - DD_APM_NON_LOCAL_TRAFFIC=true
      - DD_DOGSTATSD_NON_LOCAL_TRAFFIC=true
      - DD_CONTAINER_INCLUDE_LOGS="name:webserver"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - /proc/:/host/proc/:ro
      - /sys/fs/cgroup/:/host/sys/fs/cgroup:ro

And when I run agent status I get this in the logs part:

==========
Logs Agent
==========

    Sending compressed logs in HTTPS to agent-http-intake.logs.datadoghq.eu on port 443
    BytesSent: 0
    EncodedBytesSent: 28
    LogsProcessed: 0
    LogsSent: 0

My werbserver container is logging everything to the stdout. I have no clue why it's not collecting the logs, I have tried lots already.

Thank you

@ajazfarhad
Copy link
Author

Hm, i will try to figure out what's happening. Just to confirm something in which region do you have your DataDog account in EU or US ?

@sevetseh28
Copy link

It's EU, I have that setup correctly. So the connection is OK because if I enable the APM it's working correctly and showing up.
But now I'm troubleshooting the Logs collection that's not working. TY

@ajazfarhad
Copy link
Author

ajazfarhad commented Dec 18, 2020

Things seems to be fine in terms of setup. Also if you already have performed auto-discovery troubleshooting. Then you might need to speak with DD support they can investigate by looking into the Agent Flare.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment