- 필수 기능
- 앱 내
- 서비스 관리
- 인프라스트럭처
- 애플리케이션 성능
- 디지털 경험
- 소프트웨어 제공
- 보안
- 로그 관리
- 관리
- 인프라스트럭처
- ci
- containers
- csm
- ndm
- otel_guides
- overview
- slos
- synthetics
- tests
- 워크플로
There are a few reasons to manually instrument your applications with the OpenTelemetry API:
ddtrace
library’s functionality.The ddtrace
library provides several techniques to help you achieve these goals. The following sections demonstrate how to use the OpenTelemetry API for custom instrumentation to use with Datadog.
To configure OpenTelemetry to use the Datadog trace provider:
Add your desired manual OpenTelemetry instrumentation to your Node.js code following the OpenTelemetry Node.js Manual Instrumentation documentation. Note: Where those instructions indicate that your code should call the OpenTelemetry SDK, call the Datadog tracing library instead.
Add the dd-trace
module to your package.json:
npm install dd-trace
Initialize the dd-trace
module in your application:
const tracer = require('dd-trace').init({
// ...
})
Get TracerProvider
from tracer
:
const { TracerProvider } = tracer
Construct and register a TracerProvider
:
const provider = new TracerProvider()
provider.register()
Import the OpenTelemetry API and create an OpenTelemetry tracer instance:
const ot = require('@opentelemetry/api')
const otelTracer = ot.trace.getTracer(
'my-service'
)
Run your application.
Datadog combines these OpenTelemetry spans with other Datadog APM spans into a single trace of your application. It also supports integration instrumentation and OpenTelemetry automatic instrumentation.
Add custom attributes to your spans to provide additional context:
function processData(i, param1, param2) {
return tracer.startActiveSpan(`processData:${i}`, (span) => {
const result = someOperation(param1, param2);
// Add an attribute to the span
span.setAttribute('app.processedData', result.toString());
span.end();
return result;
});
}
To create a new span and properly close it, use the startActiveSpan
method:
function performTask(iterations, param1, param2) {
// Create a span. A span must be closed.
return tracer.startActiveSpan('performTask', (span) => {
const results = [];
for (let i = 0; i < iterations; i++) {
results.push(processData(i, param1, param2));
}
// Be sure to end the span!
span.end();
return results;
});
}
In some cases, you may want to exclude certain requests from being instrumented, such as health checks or synthetic traffic. You can use the blocklist
or allowlist
option on the http
plugin to ignore these requests.
To exclude requests at the application level, add the following after initializing the tracer:
// at the top of the entry point right after tracer.init()
tracer.use('http', {
blocklist: ['/health', '/ping']
})
You can also split the configuration between client and server if needed:
tracer.use('http', {
server: {
blocklist: ['/ping']
}
})
Additionally, you can exclude traces based on their resource name to prevent the Agent from sending them to Datadog. For more information on security and fine-tuning Agent configurations, read the Security or Ignoring Unwanted Resources.
Additional helpful documentation, links, and articles: