pyroscope
pyroscope copied to clipboard
Python labels don't appear to follow threads
I'm working on tracking down a redis usage issue in a multi-threaded application so I wrapped several calls to redis_client.get with various labels in python 3.7, but it's not correctly filtering my stack traces. For instance this block
with pyroscope.tag_wrapper({ "redis": "my_listener.one_loop" }):
self.overall_status = self.redis_client.get(RedisKeys.overall_status_key)
should only return a trace for calls to redis/client.py, but it seems to just grab the entire applications stack trace during that time across all open threads
Here's a simplified example of what I'm seeing:
import threading
import time
import pyroscope
def one_func():
with pyroscope.tag_wrapper({ "thread": "one_thread" }):
while True:
time.sleep(0.01)
def two_func():
with pyroscope.tag_wrapper({ "thread": "two_thread" }):
while True:
time.sleep(0.01)
pyroscope.configure(
app_name = "thread-test", # replace this with some name for your application
server_address = "http://pyroscope.default:4040", # replace this with the address of your pyroscope server
# auth_token = "{YOUR_API_KEY}", # optionally, if authentication is enabled, specify the API key
)
one_thread = threading.Thread(target=one_func, args=(), daemon=True)
one_thread.start()
two_thread = threading.Thread(target=two_func, args=(), daemon=True)
two_thread.start()
while True:
time.sleep(1)
This ends up with only two_thread showing up in the tags and when I filter on two_thread I still see the one_func running
@chasain The current implementation doesn't support tagging through multiple threads. We are currently working a new implementation with multi-thread tagging support. It is still in early-beta (and very recently released) but in case you want to try it:
- You need to install
libunwind8-dev
, if you are in Ubuntu runapt-get install -y libunwind8-dev
- You also need the Rust toolchain, since the library will be compiled locally:
curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain stable -y
. Make sure to include the rustc binary in your pathexport PATH=$PATH:/root/.cargo/bin
- Install the PIP package
pip install pyroscope_beta
Configuring is practically the same
pyroscope_beta.configure(
application_name = "app.name",
server_address = "http://pyroscope:4040",
tags = {
"region": f'{os.getenv("REGION")}',
}
)
Only tag_wrapper is supported at the moment
with pyroscope_beta.tag_wrapper({ "key": "value" }):
# tagged profiling
@omarabid is this still the case?