• EnglishEspañol日本語한국어Português
  • Log inStart now

accept_distributed_trace_headers (Python agent API)


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.


Python agent version or higher.

Distributed tracing must be enabled.


For context on how to use this call, first read its partner API call insert_distributed_trace_headers and Enable distributed tracing with agent APIs.

This call is used to link transactions by parsing the distributed tracing headers generated by insert_distributed_trace_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.



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


Accept a distributed trace payload inside a background task

An example of using accept_distributed_trace_payload in a background task:

def handle(request):

Consume from a queue

An example of using accept_distributed_trace_payload and creating a background task for each message:

import newrelic.agent
application = newrelic.agent.register_application(timeout=10.0)
def main(queue):
for message in queue.consume():
with newrelic.agent.BackgroundTask(application, 'Queue Consume'):
Copyright © 2024 New Relic Inc.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.