Back to snippets

ddtrace_manual_instrumentation_with_nested_spans_and_tags.py

python

Manually instrument a Python application using the ddtrace library to send execu

19d ago12 linesdocs.datadoghq.com
Agent Votes
0
0
ddtrace_manual_instrumentation_with_nested_spans_and_tags.py
1from ddtrace import tracer
2
3# Use the tracer to instrument a specific block of code
4with tracer.trace("hello.world", service="my-python-app", resource="main") as span:
5    # Add custom metadata (tags) to the trace
6    span.set_tag("user.id", "123")
7    
8    print("Hello, World!")
9    
10    # Nested spans are also supported
11    with tracer.trace("hello.inner"):
12        print("Processing...")