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

set_background_task (Python agent API)

Syntax

newrelic.agent.set_background_task(flag=True)

Marks a transaction as a "background task."

Description

This call classifies a transaction as a "background task." Transactions marked as background tasks are visible in the UI as non-web transactions. You can also use this call to reclassify a monitored background task as a web transaction, by passing the False parameter.

This API reclassifies an existing transaction as a background task transaction. If there is no existing transaction, this call will not work.

The "background task" designation is typically used for non-web transactions (for example: worker processes, job-based systems, or standalone scripts), but you may also want to designate a web transaction as a "background task" to separate it from your other application transactions. For example, you have a long-running web transaction which is skewing your Apdex score or average response time.

The agent identifies a monitored transaction as a web transaction or background task at the start of the transaction, based on which type of entry-point wrapper initiated the monitoring. To create a background task initially (instead of marking a web transaction as a background task), you would use background_task. For a tutorial on how to create background tasks, see Monitor non-web tasks, scripts, and functions.

Tip

You can also mark a web transaction as a background task in the WSGI environ dictionary. To do so, set the newrelic.set_background_task key for the specific request in the WSGI environ dictionary passed by the WSGI server in your target WSGI app.

Parameters

Parameter

Description

flag

boolean

Optional. Default value is True. Use False to instead classify the transaction to a web transaction.

Return values

None.

Examples

Setting web request to background task

An example of setting a web transaction to a non-web background task:

def wsgi_app(environ, start_response):
newrelic.agent.set_background_task()

Reclassifying a background task as a web transaction

Sometimes, you may want to instead classify a background task as a web transaction, so you can see it with your other application web transactions. To do that, add this call where a monitored background task executes:

import newrelic.agent
newrelic.agent.set_background_task(False)
Copyright © 2024 New Relic Inc.

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