L
L
LakeForest2022-01-18 21:21:06
Python
LakeForest, 2022-01-18 21:21:06

How to implement grpc service performance monitoring in python using sentry?

I guess I need to write custom transactions.
1. What does span mean? I don't understand at all.
transaction = sentry_sdk.Hub.current.scope.transaction
span = sentry_sdk.Hub.current.scope.span
2. do_task() - instead of this function, should I call the code for processing my requests coming to the grpc server? That is, now any request will go through the creation of a sentry transaction?
So?

import sentry_sdk

class TestService(
    stt_pb2_grpc.TestService
):

    def Method(
        self, request,
        context
    ):
          transaction = sentry_sdk.Hub.current.scope.transaction

          if transaction is None:
              with sentry_sdk.start_transaction(name="task_method"):
                  response = do_task(request)  # МОЯ ОБРАБОТКА ЗАПРОСА
          else:
              transaction.name = "new name"
              with transaction.start_child(op="task_method"):  # equivalent to `sentry_sdk.start_span`
                  response = do_task(request)
          return response


3. Then sentry will measure and send the results to gui?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Shitskov, 2022-01-19
@LakeForest

  1. When using a transaction, the sentry will receive information about the execution time of a part of the code and the operation from the opening of this transaction to the closing. But an operation can consist of many "heavy" sections of code, each of which can be measured separately within the transaction by creating a span. Those. a transaction can include several spans as child operations to detail the process that is going on. For example, in a "request for data" transaction with a duration of 15 ms. can have a "database query" span of 5ms.
  2. Use the first two examples - create a transaction before calling the processing of each of the requests (1st example) and add spans to the transaction as needed (2nd example). If your service has one entry point - grpc, then you always have a situation defined. Incoming requests are guaranteed to create a transaction that all the rest of the code will use.
  3. Yes, if if dsn is correct.

Don't forget to lower traces_sample_rate for production so that it doesn't affect service performance.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question