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

## Syntax

```py
newrelic.agent.accept_distributed_trace_headers(headers, transport_type='HTTP')
```

This method is used for accepting the headers used to connect transactions within a distributed trace.

## Requirements

Python agent version 5.6.0.135 or higher.

Distributed tracing must be [enabled](https://docs.newrelic.com/docs/enable-distributed-tracing#python).

## Description

For context on how to use this call, first read its partner API call [`insert_distributed_trace_headers`](https://docs.newrelic.com/docs/agents/python-agent/python-agent-api/insertdistributedtraceheaders-python-agent-api) and [Enable distributed tracing with agent APIs](https://docs.newrelic.com/docs/enable-distributed-tracing#agent-apis).

This call is used to link transactions by parsing the distributed tracing headers generated by [`insert_distributed_trace_headers`](https://docs.newrelic.com/docs/agents/python-agent/python-agent-api/insertdistributedtraceheaders-python-agent-api).

## Parameters

| Parameter                      | Description                                                                                                                                                                       |
| ------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `headers` _dictionary or list_ | Required. The headers to be accepted. May be provided as an iterable of (`header_name`, `header_value`) or as a dictionary.                                                       |
| `transport_type` _string_      | Optional, defaults to `HTTP`. The type of transport that sent this payload. Must be one of the following: `HTTP`, `HTTPS`, `Kafka`, `JMS`, `IronMQ`, `AMQP`, `Queue`, or `Other`. |

## Return values

When successful, returns `True`.

When unsuccessful, returns `False`. Accepting a payload can fail for several reasons:

-   The current transaction is not enabled.
-   Accept was called outside the scope of a transaction.
-   The payload is empty.
-   Distributed tracing is not [enabled](https://docs.newrelic.com/docs/enable-distributed-tracing).
-   `accept_distributed_trace_*` was called after a payload had been created and not before.
-   `accept_distributed_trace_*` was called multiple times in a single transaction.
-   The payload could not be parsed.
-   The payload was sent from an untrusted account.

## Examples

### Accept a distributed trace payload inside a background task [#function-trace-example]

An example of using `accept_distributed_trace_headers` in a background task:

```py
@newrelic.agent.background_task()
def handle(request):
    newrelic.agent.accept_distributed_trace_headers(request.headers)

    _do_some_work()
```

### Consume from a queue [#function-trace-example]

An example of using `accept_distributed_trace_headers` and creating a [background task](https://docs.newrelic.com/docs/agents/python-agent/supported-features/python-background-tasks) for each message:

```py
import newrelic.agent
newrelic.agent.initialize('newrelic.ini')
application = newrelic.agent.register_application(timeout=10.0)

def main(queue):
    for message in queue.consume():
        with newrelic.agent.BackgroundTask(application, 'Queue Consume'):
            newrelic.agent.accept_distributed_trace_headers(message.headers,
                    transport_type='Queue')
            _process_message(message)
```
