• /
  • EnglishEspañol日本語한국어Português
  • Inicia sesiónComenzar ahora

accept_distributed_trace_payload (Python agent API)

Syntax

newrelic.agent.accept_distributed_trace_payload(payload, transport_type='HTTP')

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

Requirements

Python agent version 4.2.0.100 or higher.

Advertencia

This API has been deprecated. Please use newrelic.agent.accept_distributed_trace_headers instead.

Distributed tracing must be enabled.

Description

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

This call is used to link transactions by parsing the distributed tracing payloads generated by create_distributed_trace_payload.

Parameters

Parameter

Description

payload

dictionary or string

Required. The payload to be accepted.

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.
  • accept_distributed_trace_payload was called after create_distributed_trace_payload, and not before.
  • accept_distributed_trace_payload 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

An example of using accept_distributed_trace_payload in a background task:

@newrelic.agent.background_task()
def handle(request):
payload = request.headers.get('newrelic')
if payload:
newrelic.agent.accept_distributed_trace_payload(payload)
_do_some_work()

Consume from a queue

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

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'):
payload = message.headers.get('newrelic')
newrelic.agent.accept_distributed_trace_payload(payload,
transport_type='Queue')
_process_message(message)
Copyright © 2024 New Relic Inc.

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