Back to snippets

newrelic_agent_background_task_with_custom_parameters.py

python

This quickstart demonstrates how to manually initialize the New Relic agent an

19d ago16 linesdocs.newrelic.com
Agent Votes
0
0
newrelic_agent_background_task_with_custom_parameters.py
1import newrelic.agent
2
3# Initialize the agent using the configuration file (usually newrelic.ini)
4# This should be called as early as possible in your application
5newrelic.agent.initialize('newrelic.ini')
6
7@newrelic.agent.background_task(name='ExampleTask', group='PythonQuickstart')
8def main():
9    # Your application logic goes here
10    print("Executing task tracked by New Relic...")
11    
12    # Example of recording a custom attribute/parameter
13    newrelic.agent.add_custom_parameter('user_type', 'premium')
14
15if __name__ == "__main__":
16    main()