Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding datadog agent causes "java not found" error and fails to start #6761

Closed
bruno-chavez opened this issue Feb 28, 2024 · 3 comments
Closed

Comments

@bruno-chavez
Copy link

bruno-chavez commented Feb 28, 2024

Hi, Im trying to instrument a Spring Boot application deployed on AWS ECS Fargate with the agent. Running the container with ENTRYPOINT ["java", "-jar", "app.jar"] works, but the moment I try to add the agent, it fails to start with the following error: /bin/sh: 1: [java,: not found. Completely stuck at what could be causing the issue.

  • Agent version: latest
  • Spring Boot version: 3.1.2
  • JDK version: Eclipse Temurin 17
  • Dockerfile:
FROM eclipse-temurin:17-jdk-jammy as builder

COPY build.gradle settings.gradle gradlew ./
COPY gradle/ gradle/
RUN chmod +x ./gradlew

COPY . .

RUN ./gradlew assemble


FROM eclipse-temurin:17-jdk-jammy

WORKDIR /app

EXPOSE 3000

# DataDog agent setup
RUN apt-get update
RUN apt-get install wget -y
RUN wget -O dd-java-agent.jar 'https://dtdg.co/latest-java-tracer'

COPY --from=builder /app/build/libs/app.jar /app/app.jar

ENTRYPOINT ["java", "-javaagent:dd-java-agent.jar" "-jar", "app.jar"]
  • Task Definition (edited non-relevant sections):
    A very similar configuration for the datadog-agent and log-forwarder containers works for our Node applications, not sure if Java needs additional configuration.
{
  "family": "app",
  "memory": "2048",
  "cpu": "1024",
  "taskRoleArn": "arn:aws:iam::000000000000:role/ecs-service-app",
  "executionRoleArn": "arn:aws:iam::000000000000:role/ecs-task-execution",
  "networkMode": "awsvpc",
  "containerDefinitions": [
    {
      "name": "app",
      "image": "000000000000.dkr.ecr.us-east-1.amazonaws.com/app",
      "essential": true,
      "portMappings": [
        {
          "containerPort": "3000",
          "protocol": "tcp"
        }
      ],
      "logConfiguration": {
        "logDriver": "awsfirelens",
        "options": {
          "Name": "datadog",
          "dd_service": "app-api",
          "dd_source": "ecs-task",
          "TLS": "on",
          "provider": "ecs"
        },
        "secretOptions": [
          {
            "name": "apikey",
            "valueFrom": "arn:aws:ssm:us-east-1:000000000000:parameter/DD_API_KEY"
          }
        ]
      },
      "environment": [
        {
          "name": "DD_ENV",
          "value": "development"
        },
        {
          "name": "DD_APM_ENABLED",
          "value": "true"
        },
        {
          "name": "DD_SERVICE",
          "value": "app-api"
        },
        {
          "name": "SERVER_PORT",
          "value": "3000"
        },
        {
          "name": "LOG_LEVEL",
          "value": "ERROR"
        }
      ]
    },
    {
      "name": "datadog-agent",
      "image": "public.ecr.aws/datadog/agent:latest",
      "essential": true,
      "environment": [
        {
          "name": "ECS_FARGATE",
          "value": "true"
        }
      ],
      "secrets": [
        {
          "name": "DD_API_KEY",
          "valueFrom": "arn:aws:ssm:us-east-1:000000000000:parameter/shared/DD_API_KEY"
        }
      ]
    },
    {
      "name": "log-forwarder",
      "image": "amazon/aws-for-fluent-bit:stable",
      "essential": true,
      "firelensConfiguration": {
        "type": "fluentbit",
        "options": {
          "enable-ecs-log-metadata": "true"
        }
      }
    }
  ]
}
@mcculls
Copy link
Contributor

mcculls commented Feb 28, 2024

Hi @bruno-chavez - you're missing a comma between the -javaagent option and the -jar option

i.e. it should be:

ENTRYPOINT ["java", "-javaagent:dd-java-agent.jar", "-jar", "app.jar"]

and not

ENTRYPOINT ["java", "-javaagent:dd-java-agent.jar" "-jar", "app.jar"]

@bruno-chavez
Copy link
Author

Oh man,so embarrassing, haha. Yea that was definitely it! Thanks for that, all containers are running now.

Unfortunately I´m not seeing the app getting registered in DataDog, also the API Key associated shows "No recent usage". Not sure if something is missing

@bruno-chavez
Copy link
Author

Nothing to report here, just some errors on the app side

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants