- 필수 기능
- 시작하기
- Glossary
- 표준 속성
- Guides
- Agent
- 통합
- 개방형텔레메트리
- 개발자
- Administrator's Guide
- API
- Datadog Mobile App
- CoScreen
- Cloudcraft
- 앱 내
- 서비스 관리
- 인프라스트럭처
- 애플리케이션 성능
- APM
- Continuous Profiler
- 스팬 시각화
- 데이터 스트림 모니터링
- 데이터 작업 모니터링
- 디지털 경험
- 소프트웨어 제공
- 보안
- AI Observability
- 로그 관리
- 관리
Ensure log collection is configured. See Java Log Collection for Log4j, Log4j 2, or Logback instructions.
Starting in version 0.74.0, the Java tracer automatically injects trace correlation identifiers into JSON formatted logs. For earlier versions, enable automatic injection in the Java tracer by adding dd.logs.injection=true
as a system property, or through the environment variable DD_LOGS_INJECTION=true
. Full configuration details can be found on the Java tracer configuration page.
Notes:
attribute.path
for your trace ID is not dd.trace_id
, ensure that your trace ID reserved attribute settings account for the attribute.path
. For more information, see Correlated Logs Not Showing Up in the Trace ID Panel.DD_LOGS_INJECTION
in the Service Catalog UI.If you prefer to manually correlate your traces with your logs, use the Java tracer’s API to retrieve correlation identifiers. Use CorrelationIdentifier.getTraceId
and CorrelationIdentifier.getSpanId
methods to inject identifiers at the beginning of the span being logged, and remove the identifiers when the span is complete.
import org.apache.logging.log4j.ThreadContext;
import datadog.trace.api.CorrelationIdentifier;
// There must be spans started and active before this block.
try {
ThreadContext.put("dd.trace_id", CorrelationIdentifier.getTraceId());
ThreadContext.put("dd.span_id", CorrelationIdentifier.getSpanId());
// Log something
} finally {
ThreadContext.remove("dd.trace_id");
ThreadContext.remove("dd.span_id");
}
import org.slf4j.MDC;
import datadog.trace.api.CorrelationIdentifier;
// There must be spans started and active before this block.
try {
MDC.put("dd.trace_id", CorrelationIdentifier.getTraceId());
MDC.put("dd.span_id", CorrelationIdentifier.getSpanId());
// Log something
} finally {
MDC.remove("dd.trace_id");
MDC.remove("dd.span_id");
}
import org.tinylog.ThreadContext;
import datadog.trace.api.CorrelationIdentifier;
// There must be spans started and active before this block.
try {
ThreadContext.put("dd.trace_id", CorrelationIdentifier.getTraceId());
ThreadContext.put("dd.span_id", CorrelationIdentifier.getSpanId());
// Log something
} finally {
ThreadContext.remove("dd.trace_id");
ThreadContext.remove("dd.span_id");
}
Note: If you are not using a Datadog Log Integration to parse your logs, custom log parsing rules need to ensure that dd.trace_id
and dd.span_id
are being parsed as strings. For more information, see Correlated Logs Not Showing Up in the Trace ID Panel.
See the Java log collection documentation for more details about specific logger implementation and instructions for logging in JSON format.