The Microsoft Visual Studio Code Supporting Add-on for Splunk provides support for debugging user Python code contained in apps, add-ons, custom search commands, custom REST handlers, modular visualizations, or any user Python code run within Splunk Enterprise. The supporting add-on can automatically create a debug configuration for your Splunk Enterprise project and provides helper methods for the Visual Studio Code Python Debug Adapter.
Microsoft Visual Studio Code - a free cross-platform code editor from Microsoft
Microsoft Visual Studio Code Supporting Add-on for Splunk (this add-on)
Visual Studio Code Splunk extension
In order to debug your Python code, some minor changes need to be made. Place the following in your Python file you would like to debug:
import sys, os sys.path.append(os.path.join(os.environ['SPLUNK_HOME'],'etc','apps','SA-VSCode','bin')) import splunk_debug as dbg dbg.enable_debugging(timeout=25)
The above code does 2 main things:
Breakpoints can be set in Visual Studio Code, or you can use the following line to force a breakpoint anywhere in your Python code:
The debugger can be configured for an app by creating a new file with the name debug.conf in the
[debug] enabled = <boolean> * Set whether an app allows debugging * Enabling debugging can delay execution and introduce artificial latency. It is recommended to either remove debug code or disable debugging options for production. * Default: true
Important: enabling debugging can delay execution and introduce artificial latency. It is recommended to either remove debug code or disable debugging options for production.
Visual Studio Code attaches to your modified code using a debug configuration created by the supported add-on. This configuration is named "Splunk Enterprise: Python Debugger".
It is necessary to open the folder in order for Visual Studio Code to read the debug configuration created by the supporting add-on.
After launching Visual Studio Code, choose Open folder...
Once your Python code is running, perform the following steps in Visual Studio Code:
Added support for a debug.conf file to control the debugger. See the details page for more information.
Splunk AppInspect evaluates Splunk apps against a set of Splunk-defined criteria to assess the validity and security of an app package and components.
As a Splunkbase app developer, you will have access to all Splunk development resources and receive a 10GB license to build an app that will help solve use cases for customers all over the world. Splunkbase has 1000+ apps and add-ons from Splunk, our partners and our community. Find an app or add-on for most any data source and user need, or simply create your own with help from our developer portal.