---
title: Trace URLs
description: Each trace has a unique URL that you can use to share it with others or to access it directly.
sidebarTitle: Trace URLs
---

# 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.

<LangTabs items={["Python SDK", "JS/TS SDK", "Langchain (JS/TS)"]}>
<Tab>
When using the `@observe()` decorator:

```python
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:

```python
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)
```

</Tab>
<Tab title="JS/TS SDK">

```ts
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);
```

</Tab>
<Tab title="Langchain (JS/TS)">

Use the interoperability of the Langfuse SDK with the Langchain integration to get the URL of a trace ([interop docs](/integrations/frameworks/langchain#interoperability)).

```ts
import { CallbackHandler } from "@langfuse/langchain";
import { startActiveObservation } from "@langfuse/tracing";
import { LangfuseClient } from "@langfuse/client";

const langfuse = new LangfuseClient();
const langfuseHandler = new CallbackHandler();

await startActiveObservation("langchain-call", async (span) => {
  await chain.invoke(
    { input: "<user_input>" },
    { callbacks: [langfuseHandler] },
  );

  // Get the trace URL
  const traceUrl = await langfuse.getTraceUrl(span.traceId);
  console.log("Trace URL: ", traceUrl);
});
```

</Tab>
</LangTabs>

## 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.

_Example: https://cloud.langfuse.com/project/clkpwwm0m000gmm094odg11gi/traces/2d6b96f2-0a4d-4366-99a5-1ad558c66e99_

<LangTabs items={["Langfuse UI", "Python SDK", "JS/TS SDK"]}>

<Tab title="Python SDK (v3)">

When using the `@observe()` decorator:

```python
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:

```python
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}")
```

</Tab>
<Tab>

```ts /setTraceAsPublic/
import { startObservation } from "@langfuse/tracing";

const rootSpan = startObservation("my-trace");

rootSpan.setTraceAsPublic();

rootSpan.end();
```

</Tab>
</LangTabs>

<!-- agent-instructions -->

---

## Agent Instructions

This page is part of the [Langfuse](https://langfuse.com) documentation, published as plain Markdown for AI agents. Every page is available as Markdown by appending `.md` to its URL, or by sending an `Accept: text/markdown` header. This page: `https://langfuse.com/docs/observability/features/url.md`.

### Querying these docs

If the answer is not on this page, query the documentation instead of guessing:

- **Semantic search** across all Langfuse docs, returning an answer with the relevant pages and excerpts. Ask a specific, self-contained question:

  ```bash
  curl -sG "https://langfuse.com/api/search-docs" --data-urlencode "query=How do I trace a LangGraph agent?"
  ```

- **Index of every page**: <https://langfuse.com/llms.txt>, with per-section indexes [llms-docs.txt](https://langfuse.com/llms-docs.txt), [llms-integrations.txt](https://langfuse.com/llms-integrations.txt), and [llms-self-hosting.txt](https://langfuse.com/llms-self-hosting.txt).

### Before writing Langfuse code

- **Install the [Langfuse Agent Skill](https://langfuse.com/docs/api-and-data-platform/features/agent-skill).** It encodes Langfuse's own best practices for instrumentation, prompt management, and evaluation, and materially improves results.
- **Read [What does a good trace look like?](https://langfuse.com/docs/observability/best-practices.md)** before instrumenting an application.
- **Verify endpoints, parameters, and response fields** against the [API reference](https://api.reference.langfuse.com) instead of inferring them from code examples.
- **Use the [Langfuse CLI](https://langfuse.com/docs/api-and-data-platform/features/cli)** (`npx langfuse-cli api <resource> <action>`) to read or write traces, prompts, datasets, and scores from the terminal.

Found an error in these docs? Please open an issue at <https://github.com/langfuse/langfuse-docs/issues>.
