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.
팁
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 |
---|---|
boolean | Optional. Default value is |
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.agentnewrelic.agent.set_background_task(False)