Ryu
  • 👩🏻‍💻 Ryu / software_engineer
  • ✨Resume
  • Python3
    • Python3 가상환경 설정하기
      • Python3 vs Python2
      • Pyenv
      • Venv
      • Pip
    • Flask
      • Flask 설치하기
      • API Server 만들기
    • REST API
    • Command Line 활용하기
    • Module 사용하기
      • Pickle - 자료형을 파일로 저장할 때
    • MongoDB connection
      • Pymongo
    • WSGI
      • 💡WSGI 가 필요한 이유
      • Web Server / WSGI / Middleware / Application 구조
      • WSGI Middleware 종류
      • Gunicorn
        • Gunicorn vs Uwsgi
    • Dockerize
      • 💡Dockerize 가 필요한 이유
      • 1. Create Dockerfile
        • Gunicorn 으로 nginx 와 app 연결하기
    • Kubernetes 로 배포하기
      • 💡Kubernetes 가 필요한 이유
      • Helm 사용하기
      • Helm 으로 k8s 에 앱 배포하기
  • Open Tracing (정리중)
    • Open Tracing 이란 무엇인가
    • Python OpenTracing Example
    • Jaeger, Jaeger UI
    • Python Jaeger Tutorial
    • Zipkin 알아보기
    • Jaeger-client 리스팅
  • Microservice Architecture
    • Netflix의 MSA 컨셉
      • ⚡️ MSA 를 도입할때 고려해야할 점들
  • Paper
    • Dynamo: Amazon’s Highly Available Key-value Store
      • 1. Introduction
      • 2. Background
      • 3. Related Work
        • Related Paper) Pastry, Chord
        • Byzantine Fault Tolerance
      • 4. System Architecture
        • 4.1 System Interface
        • 4.2 Partitioning
        • 4.3 Replication
        • Hash Function
  • Frontend
    • CommonJS 와 AMD
    • RequireJS
    • WebSocket
      • WebSocket vs Socket.io
      • polling vs long polling vs streaming
    • Vue.js
      • Vue.js 에서 WebSocket 사용하기
      • [프로젝트] Vue, Vuex, AntDesignVue 로 운영툴 만들기
    • React x Redux 로 프로젝트 만들기
      • 0. React, Redux 를 선택한 이유
      • 1. 프로젝트 생성하고 Webpack4 적용하기
      • 2. React 와 ReactDOM 적용하기
      • 3. Material UI 적용하기
  • Data Engineering
    • Spark
      • Spark 이란?
      • 각 데몬의 역할 Driver, Master, Worker
      • 장단점 / 함께사용하는 툴 / 사용 사례
  • Service Mesh (정리중)
    • RPC
    • gRPC - Python Server 만들기
      • step 2.
Powered by GitBook
On this page
  • 1. Jaeger 사용하기 - Basic Tutorial
  • Install jaeger-client
  • Initialize a Real Tracer
  • 2. Tags, Logs 를 사용하여 Trace Annotate 하기
  • 방법 1) Tag 사용하기
  • 방법 2) Log 사용하기
  • Tags vs Logs

Was this helpful?

  1. Open Tracing (정리중)

Python Jaeger Tutorial

Python 앱에서 Jaeger 를 사용하여 Tracing 하기

PreviousJaeger, Jaeger UINextZipkin 알아보기

Last updated 5 years ago

Was this helpful?

1. Jaeger 사용하기 - Basic Tutorial

Install jaeger-client

$ pip install jaeger-client

Initialize a Real Tracer

import sys
import logging
from jaeger_client import Config
import time


def open_tracing_example(hello_to):
    ## Span 시작
    span = tracer.start_span('say-hello')

    hello_str = 'Hello, %s!' % hello_to
    print(hello_str)

    ## Span 끝
    span.finish()


def init_tracer(service):
    logging.getLogger('').handlers = []
    logging.basicConfig(format='%(message)s', level=logging.DEBUG)

    config = Config(
        config={
            'sampler': {
                'type': 'const',
                'param': 1,
            },
            'logging': True,
        },
        service_name=service,
    )

    # this call also sets opentracing.tracer
    return config.initialize_tracer()


tracer = init_tracer('hello-world')

hello_to = sys.argv[1]
open_tracing_example(hello_to)

# yield to IOLoop to flush the spans
time.sleep(2)
tracer.close()

✔️ tracer = init_tracer('hello-world')

  • 파라미터로 넘겨주는 String hello-world의 의미:

    • tracer에 의해 방출된 모든 span 들을 hello-world 서비스로부터 비롯된것으로 표시하는데 사용됩니다.

✔️ time.sleep(2)

  • Jaeger Backend 에 spans 를 임의로 플러쉬하기 위해.

💻 logs output

$ python -m jaeger_tutorial Bryan

Initializing Jaeger Tracer with UDP reporter
Using sampler ConstSampler(True)
opentracing.tracer initialized to <jaeger_client.tracer.Tracer object at 0x102a7b6a0>[app_name=hello-world]
Hello, Bryan!
Reporting span 618c339cb1ca725a:deddc16d2e0305c7:0:1 hello-world.say-hello

2. Tags, Logs 를 사용하여 Trace Annotate 하기

  • 각각 다른 Argument 로 프로그램을 호출할때, 각각을 식별하기 위해 Program Arguments 를 포착해둘 필요가 있습니다.

방법 1) Tag 사용하기

  • Tag 는 span 에 대한 metadata 를 제공하는 key-value 쌍입니다.

방법 2) Log 사용하기

  • Log 는 보통의 log statement 와 유사하게, 로깅된 span 에 대한 timestamp 및 여러 데이터들을 포함합니다.

Tags vs Logs

  • Tag 는 span 의 전체 기간에 적용되는 속성들을 나타내기 위한 것입니다.

  • 예를들어, 어떤 span 이 HTTP request 를 나타내고 있다면,

Python 에서도 Java-Spring 처럼 method 단위로 자동 span 생성해주는게 있는지 찾아보기.

Annotation 형태로 하는게 없다면 직접 만들어보기.

https://github.com/jaegertracing/jaeger-client-python