- 필수 기능
- 앱 내
- 서비스 관리
- 인프라스트럭처
- 애플리케이션 성능
- 디지털 경험
- 소프트웨어 제공
- 보안
- 로그 관리
- 관리
- 인프라스트럭처
- 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:
composer require open-telemetry/sdk
Add your desired manual OpenTelemetry instrumentation to your PHP code following the OpenTelemetry PHP Manual Instrumentation documentation.
Install the Datadog PHP tracing library.
Set DD_TRACE_OTEL_ENABLED
to true
.
Datadog combines these OpenTelemetry spans with other Datadog APM spans into a single trace of your application.
You can add attributes at the exact moment as you are starting the span:
$span = $tracer->spanBuilder('mySpan')
->setAttribute('key', 'value')
->startSpan();
Or while the span is active:
$activeSpan = OpenTelemetry\API\Trace\Span::getCurrent();
$activeSpan->setAttribute('key', 'value');
Exception information is captured and attached to a span if one is active when the exception is raised.
// Create a span
$span = $tracer->spanBuilder('mySpan')->startSpan();
throw new \Exception('Oops!');
// 'mySpan' will be flagged as erroneous and have
// the stack trace and exception message attached as tags
Flagging a trace as erroneous can also be done manually:
use OpenTelemetry\API\Trace\Span;
use OpenTelemetry\Context\Context;
// Can only be done after the setup steps, such as initializing the tracer.
try {
throw new \Exception('Oops!');
} catch (\Exception $e) {
$rootSpan = Span::fromContext(Context::getRoot());
$rootSpan->recordException($e);
}
To add a span:
// Get a tracer or use an existing one
$tracerProvider = \OpenTelemetry\API\Globals::tracerProvider();
$tracer = $tracerProvider->getTracer('datadog')
// Create a span
$span = $tracer->spanBuilder('mySpan')->startSpan();
// ... do stuff
// Close the span
$span->end();
To access the currently active span:
$span = OpenTelemetry\API\Trace\Span::getCurrent();
Additional helpful documentation, links, and articles: