- 필수 기능
- 시작하기
- Glossary
- 표준 속성
- Guides
- Agent
- 통합
- 개방형텔레메트리
- 개발자
- Administrator's Guide
- API
- Datadog Mobile App
- CoScreen
- Cloudcraft
- 앱 내
- 서비스 관리
- 인프라스트럭처
- 애플리케이션 성능
- APM
- Continuous Profiler
- 스팬 시각화
- 데이터 스트림 모니터링
- 데이터 작업 모니터링
- 디지털 경험
- 소프트웨어 제공
- 보안
- AI Observability
- 로그 관리
- 관리
Enable injection with the environment variable DD_LOGS_INJECTION=true
or by configuring the tracer directly:
// This line must come before importing the logger.
const tracer = require('dd-trace').init({
logInjection: true
});
This enables automatic trace ID injection for bunyan
, paperplane
, pino
, and winston
.
If you haven’t done so already, configure the Node.js tracer with DD_ENV
, DD_SERVICE
, and DD_VERSION
. This will provide the best
experience for adding env
, service
, and version
(see Unified Service Tagging for more details).
Note: Automatic injection only works for logs formatted as JSON.
If you are using a logging library not supported for automatic injection but are using JSON format, it’s possible to do manual injection directly in your code.
Example using console
as the underlying logger:
const tracer = require('dd-trace');
const formats = require('dd-trace/ext/formats');
class Logger {
log(level, message) {
const span = tracer.scope().active();
const time = new Date().toISOString();
const record = { time, level, message };
if (span) {
tracer.inject(span.context(), formats.LOG, record);
}
console.log(JSON.stringify(record));
}
}
module.exports = Logger;