This method is used for inserting headers used to connect transactions within a distributed trace.
Python agent version 188.8.131.52 or higher.
Distributed tracing must be enabled.
This API requires distributed tracing to be enabled.
This call is used to implement distributed tracing. It inserts headers into a list that can be read by the receiving application with the
Required. A list of headers. This list will be mutated by the call (headers will be inserted into the list in the form of (header_name, header_value)).
None. The input list will be updated by a call to this function.
In order to maintain proper ordering of spans in a trace, you must generate the payload in the context of the span that sends it.
An example of using
insert_distributed_trace_headers in creating an external trace from within single a background task:
@newrelic.agent.background_task()def main(url):with newrelic.agent.ExternalTrace('my_external_library',url, method='GET'):# Generate the payload in the context of the ExternalTrace# span that sends itheaders = newrelic.agent.insert_distributed_trace_headers(headers)response = my_external_library._get(url, headers=headers)data = _process_response(response)
An example of using
insert_distributed_trace_headers in creating an external trace:
def _bind_url(url, *args, **kwargs):# _bind_url is called with the args and kwargs sent to the `get`# method belowreturn email@example.com_trace('my_external_library', _bind_url, method='GET')def get(url):headers = newrelic.agent.insert_distributed_trace_headers(headers)return my_external_library._get(url, headers=headers)
If you need more help, check out these support and learning resources:
- Browse the Explorers Hub to get help from the community and join in discussions.
- Find answers on our sites and learn how to use our support portal.
- Run New Relic Diagnostics, our troubleshooting tool for Linux, Windows, and macOS.
- Review New Relic's data security and licenses documentation.