0
0
LangChainframework~10 mins

Viewing trace details and latency in LangChain - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to enable tracing in LangChain.

LangChain
from langchain import [1]

tracer = [1]()
Drag options to blanks, or click blank then click option'
ATracing
Btrace
CTracer
DTrace
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase 'trace' instead of the class name.
Confusing 'Tracing' with 'Tracer'.
2fill in blank
medium

Complete 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'
Atracer
Btracing
Ctrace
Dtracer_enabled
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'trace' instead of 'tracer' as the attribute name.
Trying to enable tracing with a boolean attribute.
3fill in blank
hard

Fix 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'
Alatency
Bduration
Ctime
Ddelay
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.
4fill in blank
hard

Fill 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'
Aoperation_name
Bname
Coperation
Dop
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.
5fill in blank
hard

Fill 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'
Aoperation_name
Bduration
Cduration_ms
Dlatency
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'duration_ms' which is not the attribute name.
Using 'latency' which does not exist as an attribute.