pyroscope icon indicating copy to clipboard operation
pyroscope copied to clipboard

Python labels don't appear to follow threads

Open chasain opened this issue 2 years ago • 3 comments

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 image

chasain avatar May 02 '22 21:05 chasain

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 image

chasain avatar May 04 '22 18:05 chasain

@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:

  1. You need to install libunwind8-dev, if you are in Ubuntu run apt-get install -y libunwind8-dev
  2. 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 path export PATH=$PATH:/root/.cargo/bin
  3. 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 avatar May 06 '22 00:05 omarabid

@omarabid is this still the case?

metasyn avatar Jan 31 '24 23:01 metasyn