ECS Fargateä¸ã§åãã¦ããJavaã¢ããªã±ã¼ã·ã§ã³ã«Datadogãå°å ¥ããæé ãã¾ã¨ãã¾ãã
æ¬è¨äºã®ç°å¢ - Java 11 - Gradle 7.0.2 - Spring Boot 2.5.1 - Jib 3.3.1
大ã¾ããªæµã
- Gradleããã¸ã§ã¯ãã§ã¢ããªã±ã¼ã·ã§ã³ãä½ã
- ECS Fargateç°å¢ãç¨æãã
- ECS Fargateã«ãããã¤ã§ããããã«GitHub Actionsã¯ã¼ã¯ããã¼ãç¨æãã
- ECS Faragteä¸ã§åãã¦ããJavaã¢ããªã±ã¼ã·ã§ã³ã«Datadogãå°å ¥ãã
æ¬è¨äºã§ã¯4ã«ã¤ãã¦ã¾ã¨ãã¾ããJibã®Gradleãã©ã°ã¤ã³ãå©ç¨ãã¦Dockerã¤ã¡ã¼ã¸ãçæãã¦ãã¾ãã
æé
1. Javaã¯ã©ã¤ã¢ã³ãã®ã¤ã³ã¹ãã¼ã«
Javaã¯ã©ã¤ã¢ã³ããã¤ã³ã¹ãã¼ã«ãã¦ãä»»æã®å ´æã«é
ç½®ï¼ãã®è¨äºã§ã¯ .datadog/
ï¼ãã¾ãã
$ wget -O dd-java-agent.jar 'https://dtdg.co/latest-java-tracer' ããã㯠$ curl -L -o dd-java-agent.jar https://dtdg.co/latest-java-tracer
Java アプリケーションのトレースã«ãclasspath ã« dd-java-agent ã追å ããªãã§ãã ãããäºæãã¬æåãçããå ´åãããã¾ãããã¨ããã®ã§ãclasspathã«ã¯è¿½å ããªãããã«ãã¦ãã ããã
2. ã¿ã¹ã¯å®ç¾©ã«Datadog Agentç¨ãµã¤ãã«ã¼ã³ã³ããã追å
ã¿ã¹ã¯å®ç¾©ã«Datadog Agentç¨ãµã¤ãã«ã¼ã³ã³ããã追å ãã¾ãã
{ # ECS Fargateå ¨ä½ã®è¨å®ã¯çç¥ "containerDefinitions": [ { # ã¢ããªã±ã¼ã·ã§ã³ç¨ã³ã³ããã®è¨å® }, { "name": "datadog-agent", "image": "public.ecr.aws/datadog/agent:latest", "cpu": 128, "memory": 512, "memoryReservation": 512, "portMappings": [ { "containerPort": 8126 } ], "essential": true, "environment": [ { "name": "ECS_FARGATE", "value": "true" }, # Trace Agentãæå¹ã« { "name": "DD_APM_ENABLED", "value": "true" }, # Datadogä¸ã§ã®ç°å¢èå¥å { "name": "DD_ENV", "value": "dev" } ], "secrets": [ # AWS Systems Manager Parameter Storeã«æ ¼ç´ããAPI Key { "name": "DD_API_KEY", "valueFrom": "/datadog/DD_API_KEY" } ], "logConfiguration": { "logDriver": "awslogs", "options": { "awslogs-create-group": "true", "awslogs-group": "app-datadog", "awslogs-region": "ap-northeast-1", "awslogs-stream-prefix": "/datadog" } } } ] }
3. dd-java-agentãDockerã¤ã¡ã¼ã¸ã«å«ããããã«è¨å®ã追å
build.gradleã«ãdd-java-agentãDockerã¤ã¡ã¼ã¸ã«å«ããããã«è¨å®ã追å ãã¦ãã ããã
jib { from { image = 'amazoncorretto:11-alpine-jdk' } to { // ä»»æã®ã³ã³ããã¤ã¡ã¼ã¸å image = 'app' } container { // ã¢ããªã±ã¼ã·ã§ã³å®è¡æã«JVMã«æ¸¡ãJVMãã©ã° jvmFlags = ['-javaagent:/opt/datadog/dd-java-agent.jar'] } extraDirectories { paths { path { // dd-java-agent.jarãããã¸ã§ã¯ããã£ã¬ã¯ããªããDockerã¤ã¡ã¼ã¸ã«è¿½å from = file("${project.rootDir}/.datadog") into = '/opt/datadog' } } } }
4. ãããã¤
ECS Fargeteã«ãããã¤ããDatadogããã·ã¥ãã¼ãã§ç¢ºèªããã¨ã¡ããªã¯ã¹ãåããããã«ãªãã¾ãã