Language Integration
Based on the language of your application, please find the corresponding languages to begin language integration.
Language |
---|
Go |
Python |
Python + Django |
Java |
Go Client
This utility can be plugged into your go application to collect vital data about your code's behavior so that Mindsight can help you write better code more safely, without significantly impacting your application performance.
Step 1. Go Installation Package
You can install this package the standard way you install Go packages in your environment:
go get github.com/MindsightCo/go-mindsight-collector
Step 2. Go Configuration Setup
Before you get started, make sure you set up the Mindsight Agent, which is required to send diagnostic data to Mindsight's backend for further analysis.
Let's assume for the example below that your agent will be listening at http://localhost:8000
.
To start collecting data from your application, do the following your application (main
is probably where you want to do this):
import (
"context"
"github.com/MindsightCo/go-mindsight-collector"
)
... // in a function, such as main:
ctx := context.Background()
err := collector.StartMindsightCollector(ctx,
collector.OptionProject("My-project"),
collector.OptionEnvironment("production"),
collector.OptionAgentURL("http://localhost:8000/samples/"),
collector.OptionWatchPackage("github.com/you/your-package"),
collector.OptionWatchPackage("github.com/you/other-package"))
The hotpaths for the packages specified via OptionWatchPackage will be measured periodically and reported to the Mindsight backend via the Mindsight Agent.
Step 3. Optional Fine Tuning Configuration
Sampling Frequency Control
You can control how frequently samples are sent to the Agent via collector.OptionCacheDepth()
.
Vendor Packages
By default, vendored packages within the set of watched packages are not sampled. If you would like to include vendored packages in the data, set collector.OptionIncludeVendor()
.
Cancellation Request
Feel free to provide your own context according to your needs. The collector will halt if the context receives a cancellation request [i.e. it respects ctx.Done()
].
Python Client
Unobstrusively detects the most common running stacks in your Python program, for use with the Mindsight product.
This utility can be plugged in to your Python application to collect vital data about your code's behavior so that Mindsight can help you write better code more safely.
Exceptions & Notes
This utility is not designed to work with web frameworks that utilize multithreading like Django and Flask. If you are using one of those frameworks, use the appropriate data collector: Mindsight Django Collector
Step 1. Installation
To install this utility for use in your program:
pip install mindsight-sampler
Step 2. Python Configuration
Before proceeding, make sure you have setup your Mindsight account. Contact us if you need help.
To use this utility to observe your program and send data to Mindsight:
-
First, set up and run the Mindsight Agent (the binary download is easy and recommended).
-
For the purpose of this example, we will assume your agent is running at http://localhost:8000
Initialize the sampler in your code:
import sampler
sampler.start("http://localhost:8000", "My Project", ["my.module", "my.other_module"], environment="production")
Let's explain each parameter:
"http://localhost:8000"
- URL to your running Mindsight Agent
"My Project"
-The name of your project in your Mindsight account that tracks this application["my.module", "my.other_module"]
- The Python modules that you want to have monitored by Mindsight
- Each element of this array is a prefix, so ["my"] will watch those 2, plus any others under my.
environment="production"
- Name of the environment the application is running in
- This parameter is optional
- You can name your environments however you like
Python + Django Client
This utility can be plugged in to your Django application to collect vital data about your code's behavior so that Mindsight can help you write better code more safely.
Step 1. Installation
The latest production-ready version of this utility is distributed via PyPI and can be installed as follows:
pip install mindsight-django-hotpath
Step 2. Configuration
This utility runs as a Django middleware in your application. To configure it add the following to your settings.py
file:
import mindsight_django
# rest of your configuration
# Mindsight collector config
# URL where you are running the Mindsight Agent
MINDSIGHT_AGENT_URL = 'http://localhost:8000'
# Name of your project as configured in Mindsight
MINDSIGHT_PROJECT = 'my-project-name'
The MINDSIGHT_AGENT_URL
setting is the URL of the Mindsight Agent, which is required to send diagnostic data to Mindsight's backend for further analysis. If this setting is omitted, Mindsight's middleware will be disabled by the Django runtime.
The MINDSIGHT_PROJECT
setting is the name of your project you've configured in the Mindsight service. If this setting is omitted, Mindsight's middleware will be disabled by the Django runtime.
Finally, register Mindsight as a Django middleware in your settings.py
file:
MIDDLEWARE = [
# ... other middlewares
'mindsight_django.Middleware', # should be the last middleware
]
To ensure the highest quality data to better analyze your application with, the Mindsight middleware should be the last one to run.
Step 3. Fine Tuning Configuration
The Mindsight middleware has additional configuration options to fine-tune its behavior. The defaults should be desirable for most applications, but they can be tweaked if needed:
Options
MINDSIGHT_ENVIRONMENT
- Default:
'production'
- Deployment environment your program is running in. Change this if you have multiple environments you want to measure independently.
- Default:
MINDSIGHT_SEND_AFTER
- Default:
100
- Number of measurements to cache before sending data to the Mindsight Agent.
- Default:
MINDSIGHT_SEND_TIMEOUT
- Default:
0.05
- Amount of time (seconds) to wait for a response from the Mindsight Agent when sending measurements. An error will be logged in case of communication failure with the agent.
- Default:
MINDSIGHT_SAMPLE_PROBABILITY
- Default:
0.02
- Probability that a request will be intercepted and analyzed by Mindsight.
- Default:
MINDSIGHT_SAMPLE_INTERVAL
- Default:
0.010
- Simulates the behavior of a sampling profiler that interrupts the application every 10ms.
- Default:
Java Client
Before getting started, please ensure you have set up the Mindsight Agent.
Step 1. Download Latest Release
The Mindsight Java client is packaged and released as a single jar file. The latest version can be downloaded from its release page.
Step 2. Run Application With Java Agent
The Mindsight Java Client uses the -javaagent
feature of the JVM to automatically instrument your application and inspect your run time. Below is an example of how you might invoke your application on the command line:
MINDSIGHT_AGENT=http://localhost:8000 MINDSIGHT_PROJECT=Todo MINDSIGHT_MODULES=com.example java -javaagent:target/mindsight-client-1.0.1-all.jar=reporter=io.mindsight.client.JavaClient,sampleInterval=100 -cp target/mindsight-client-1.0.1-all.jar:target/TodoDemo-0.0.1-SNAPSHOT.war -jar target/TodoDemo-0.0.1-SNAPSHOT.war
Explanation of Options
Several environment variables are needed to configure the Mindsight Java Client:
MINDSIGHT_MODULES
- Comma-separated list of the packages you want to analyze
- i.e. If your application is in
com.example.todo
, this variable can simply be set tocom.example
MINDSIGHT_PROJECT
- The name of your project in your Mindsight account (how we distinguish between different applications in one account)
MINDSIGHT_AGENT
- URL to the Mindsight Agent
MINDSIGHT_ENTRY_POINTS
- Comma-separated function names (fully qualified with package) of "entry points" such as main functions in wait loops that should be excluded from the analysis
- Can be omitted if your application has no such functions
Finally, the -javaagent
flag also has the following arguments:
- Path to the jar containing the Mindsight Java client
reporter=io.mindsight.client.JavaClient
- Must be set to
io.mindsight.client.JavaClient
- Must be set to
sampleInterval=N
- sets the data collection interval to every N ms