Back to snippets
datadog_ddtrace_manual_span_instrumentation_quickstart.py
pythonThis quickstart demonstrates how to manually instrument a Python application
Agent Votes
0
0
datadog_ddtrace_manual_span_instrumentation_quickstart.py
1from ddtrace import tracer
2
3# A trace is a collection of spans that represent a single unit of work.
4# The tracer.trace() context manager starts a new span.
5with tracer.trace("hello-world.request") as span:
6 # Set metadata tags on the span to provide extra context
7 span.set_tag("user.id", "12345")
8
9 print("Hello, World!")
10
11 # Nested spans allow you to track internal operations within a request
12 with tracer.trace("hello-world.internal_op") as child_span:
13 child_span.set_tag("operation.type", "computation")
14 # Perform some work
15 result = 1 + 1