Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to enable tracing in LangChain.
LangChain
from langchain import [1] tracer = [1]()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase 'trace' instead of the class name.
Confusing 'Tracing' with 'Tracer'.
✗ Incorrect
The Tracer class is used to enable tracing in LangChain.
2fill in blank
mediumComplete the code to attach the tracer to the LangChain client.
LangChain
from langchain import LangChainClient client = LangChainClient() client.[1] = tracer
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'trace' instead of 'tracer' as the attribute name.
Trying to enable tracing with a boolean attribute.
✗ Incorrect
The client uses the tracer attribute to attach the tracer instance.
3fill in blank
hardFix the error in printing the latency from the trace details.
LangChain
trace_details = tracer.get_trace() print(f"Latency: {trace_details.[1] ms")
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'latency' which is not the attribute name.
Using 'time' or 'delay' which do not exist on trace details.
✗ Incorrect
The correct attribute to get latency is duration in milliseconds.
4fill in blank
hardFill both blanks to filter trace spans by operation name and minimum latency.
LangChain
filtered_spans = [span for span in tracer.get_trace().spans if span.[1] == '[2]' and span.duration > 100]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'operation' or 'op' which are not the correct attribute names.
Confusing the attribute name with the value to compare.
✗ Incorrect
The span attribute for the operation is operation_name, and the value to filter by is name.
5fill in blank
hardFill all three blanks to create a dictionary of span names and their latencies for spans longer than 200 ms.
LangChain
latency_dict = {span.[1]: span.[2] for span in tracer.get_trace().spans if span.[3] > 200} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'duration_ms' which is not the attribute name.
Using 'latency' which does not exist as an attribute.
✗ Incorrect
Use operation_name for the key, and duration for the latency attribute and comparison.