Python Quick Start
Install Graphsignal agent by running:
pip install graphsignal
Or clone and install the GitHub repository:
git clone https://github.com/graphsignal/graphsignal-python.git python setup.py install
Configure Graphsignal agent by specifying your API key directly or via
GRAPHSIGNAL_API_KEY environment variable.
import graphsignal graphsignal.configure(api_key='my-api-key', deployment='my-model-prod-v1')
To get an API key, sign up for a free account at graphsignal.com. The key can then be found in your account's Settings / API Keys page.
To track deployments, versions and environments separately, specify a
deployment parameter or environment variable
Use the following examples to integrate Graphsignal agent into your machine learning application. See integration documentation and API reference for full reference. More integration examples are available in examples repo.
Monitoring and tracing
Graphsignal auto-instruments and traces libraries and frameworks, such as OpenAI, LangChain, and many others.
To measure and monitor any other executions, e.g. model inference or inference API calls, wrap the code with
start_trace method or use
with graphsignal.start_trace(endpoint='predict'): pred = model(x)
@graphsignal.trace_function def predict(x): return model(x)
Other integrations and callbacks are available as well. See integration documentation for more information.
Enable profiling to additionally record code-level statistics. Profiling is disabled by default due to potential overhead. To enable, provide
with graphsignal.start_trace( endpoint='predict', options=graphsignal.TraceOptions(enable_profiling=True)): pred = model(x)
The agent will automatically choose a profiler depending on available modules. Currently, CProfile, PyTorch Kineto and Yappi are supported. The Kineto profiler is used if
torch module is found and Yappi profiler is used if
yappi module is found. Otherwise, CProfile is used. To properly profile
asyncio coroutines, just
pip install yappi.
For auto-instrumented libraries, or when using
start_trace method with
with context manager or callbacks, exceptions are automatically recorded. For other cases, use
Data is automatically monitored for auto-instrumented libraries. To track data metrics and record data profiles for other cases,
Trace.set_data method can be used.
with graphsignal.start_trace(endpoint='predict') as trace: trace.set_data('input', input_data)
The following data types are currently supported:
No raw data is recorded by the agent, only statistics such as size, shape or number of missing values.
After everything is setup, log in to Graphsignal to monitor and analyze execution performance and monitor for issues.
Graphsignal agent is very lightweight. While all executions are measured, Graphsignal agent only records certain executions, automatically limiting the overhead.
To enable debug logging, add
configure(). If the debug log doesn't give you any hints on how to fix a problem, please report it to our support team via your account.
In case of connection issues, please make sure outgoing connections to