Trace URLs
Each trace has a unique URL that you can use to share it with others or to access it directly.
Get trace url
Sometimes, it is useful to get the trace URL directly in the SDK. E.g. to add it to your logs or interactively look at it when running experiments in notebooks.
When using the @observe() decorator:
from langfuse import observe, get_client
@observe()
def process_data():
langfuse = get_client()
# Get the URL of the current trace
trace_url = langfuse.get_trace_url()
print(f"View trace at: {trace_url}")
# or pass the trace id
trace_id = langfuse.get_current_trace_id()
trace_url = langfuse.get_trace_url(trace_id=trace_id)When using context managers:
from langfuse import get_client
langfuse = get_client()
with langfuse.start_as_current_observation(as_type="span", name="process-request") as span:
# Get the URL of this trace
trace_url = langfuse.get_trace_url()
print(f"View trace at: {trace_url}")
# or pass the trace id
trace_id = langfuse.get_current_trace_id()
trace_url = langfuse.get_trace_url(trace_id=trace_id)import { LangfuseClient } from "@langfuse/client";
import { startObservation } from "@langfuse/tracing";
const langfuse = new LangfuseClient();
const rootSpan = startObservation("my-trace");
const traceUrl = await langfuse.getTraceUrl(rootSpan.traceId);
console.log("Trace URL: ", traceUrl);Use the interoperability of the Langfuse SDK with the Langchain integration to get the URL of a trace (interop docs).
// Initialize Langfuse Client
import { CallbackHandler, Langfuse } from "langfuse-langchain";
const langfuse = new Langfuse();
// Create a Langfuse trace for an execution of your application
const trace = langfuse.trace();
// Get Langchain handler for this trace
const langfuseHandler = new CallbackHandler({ root: trace });
// Get the trace URL
langfuseHandler.getTraceUrl();Deprecated: flaky in cases of concurrent requests as it depends on the state of the handler.
handler.getTraceUrl();Share trace via url
By default, only members of your Langfuse project can view a trace.
You can make a trace public to share it via a public link. This allows others to view the trace without needing to log in or be members of your Langfuse project.
When using the @observe() decorator:
from langfuse import observe, get_client
@observe()
def process_data():
langfuse = get_client()
# Make the current trace public
langfuse.set_current_trace_as_public()When using context managers:
from langfuse import get_client
langfuse = get_client()
with langfuse.start_as_current_observation(as_type="span", name="process-request") as span:
# Make this trace public
span.set_trace_as_public()
# Get the URL to share
trace_id = langfuse.get_current_trace_id()
trace_url = langfuse.get_trace_url(trace_id=trace_id)
print(f"Share this trace at: {trace_url}")import { startObservation } from "@langfuse/tracing";
const rootSpan = startObservation("my-trace");
rootSpan.setTraceAsPublic();
rootSpan.end();