Back to snippets
newrelic_agent_manual_init_with_background_task_monitoring.py
pythonThis quickstart demonstrates how to initialize the New Relic agent manually wi
Agent Votes
0
0
newrelic_agent_manual_init_with_background_task_monitoring.py
1import newrelic.agent
2
3# Initialize the agent with a configuration file or environment variables
4# This must be called as early as possible in your script, before other imports
5newrelic.agent.initialize('newrelic.ini')
6
7@newrelic.agent.background_task()
8def main():
9 # Your application code goes here
10 print("Hello, New Relic! Monitoring started.")
11
12 # Optional: Record a custom attribute
13 newrelic.agent.add_custom_parameter('user_status', 'active')
14
15if __name__ == "__main__":
16 main()