Python OpenTracing Example
Python 앱 opentracing 라이브러리 사용 예제
⌨️ Python 에서 opentracing 라이브러리 사용해보기
✔️ https://github.com/yurishkuro/opentracing-tutorial/tree/master/python 코드를 참고하여 작성했습니다.
Install
$ pip install opentracing
Example
import opentracing
tracer = opentracing.tracer
def say_hello(hello_to):
## Span 시작
span = tracer.start_span('say-hello')
hello_str = 'Hello, %s!' % hello_to
print(hello_str)
## Span 끝
span.finish()
Basic features of OpenTracing API
start_span
: 새로운 span 시작span은 operation name 을 가집니다.
span.finish()
: span 종료해당 span 의 start/end Timestamp 는 tracer implementation 에 의해 자동으로 측정됩니다.
Context manger 로 span 사용하기
def open_tracing_example_with_context_manager(hello_to):
with tracer.start_span('say-hello') as span:
hello_str = 'Hello, %s!' % hello_to
print(hello_str)
이렇게까지하면 opentracing.tracer
의 포인트가 no-op tracer 에 있기 때문에, Tracing UI 에서는 확인할 수 없습니다.
이제 실제 Tracer 인스턴스를 생성해봅시다.
(다음 포스팅에 계속..)
Last updated
Was this helpful?