---
title: current_trace_id (Python agent API)
source: https://docs.newrelic.com/docs/apm/agents/python-agent/python-agent-api/currenttraceid-python-agent
---

## Syntax [#syntax]

```py
    newrelic.agent.current_trace_id()
```

Returns the trace ID of the current transaction or `None` if no transaction exists.

## Description [#description]

Use `current_trace_id` to retrieve the trace ID of the current [transaction](https://docs.newrelic.com/docs/accounts-partnerships/education/getting-started-new-relic/glossary#transaction).

## Return values [#return-values]

Returns the trace ID of the current transaction. Returns `None` if there is no active transaction.

## Examples [#examples]

### Get the current trace ID [#function-trace-example]

```py
    import newrelic.agent

    @newrelic.agent.background_task()
    def main():
        trace_id = newrelic.agent.current_trace_id()
```
