Hello, is it possible to pull the trace id of the current request from the app where instrumentation is enabled.
Yes, you can retrieve the trace ID of the current request in an application where instrumentation is enabled using OpenTelemetry. You can use the get_current_span method to access the current span and then extract the trace ID from it. Here's an example in Python: LBKSfrom opentelemetry import traceLBKS# Get the current span current_span = trace.get_current_span()LBKS# Get the trace ID from the current span trace_id = current_span.get_span_context().trace_idLBKS# Convert the trace ID to a hexadecimal string trace_id_hex = format(trace_id, '032x')LBKSprint(f"Trace ID: {trace_id_hex}")LBKSThis code snippet retrieves the current span and extracts the trace ID, converting it to a hexadecimal string for readability.Would you like more detail on this process?Sources:
- Slack Discussion
馃挕聽Hint: Mention RunLLM in the thread for followups.
We also provide get_ancestor_spans if you need access to the root span
Hi Dustin N. we are using openinference.instrumentation.dspy.DSPyInstrumentor . So I used from opentelemetry import trace But its printing:
NonRecordingSpan(SpanContext(trace_id=0x00000000000000000000000000000000, span_id=0x0000000000000000, trace_flags=0x00, trace_state=[], is_remote=False))
0
Trace ID: 00000000000000000000000000000000 yes im trying to attach annotation . trying to implement a user feedback loop in my UI. so every response given to the UI shd have the traceid, which i can use later to annotate the feedback
