- 필수 기능
- 앱 내
- 서비스 관리
- 인프라스트럭처
- 애플리케이션 성능
- 디지털 경험
- 소프트웨어 제공
- 보안
- 로그 관리
- 관리
- 인프라스트럭처
- 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:
If you have not yet read the instructions for auto-instrumentation and setup, start with the Python Setup Instructions.
Set DD_TRACE_OTEL_ENABLED
environment variable to true
.
To create custom spans within an existing trace context:
from opentelemetry import trace
tracer = trace.get_tracer(__name__)
def do_work():
with tracer.start_as_current_span("operation_name") as span:
# Perform the work that you want to track with the span
print("Doing work...")
# When the 'with' block ends, the span is automatically closed
To access the currently active span, use the get_current_span()
function:
from opentelemetry import trace
current_span = trace.get_current_span()
# enrich 'current_span' with information
Add attributes to a span to provide additional context or metadata.
Here’s an example of how to add attributes to the current span:
from opentelemetry import trace
current_span = trace.get_current_span()
current_span.set_attribute("attribute_key1", 1)
Additional helpful documentation, links, and articles: