> For the complete documentation index, see [llms.txt](https://haleyryu.gitbook.io/engineer/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://haleyryu.gitbook.io/engineer/open-tracing/python-opentracing-example.md).

# Python OpenTracing Example

## ⌨️  Python 에서 opentracing 라이브러리 사용해보기 &#x20;

✔️ <https://github.com/yurishkuro/opentracing-tutorial/tree/master/python> 코드를 참고하여 작성했습니다.

### Install

```bash
$ pip install opentracing
```

### Example&#x20;

```python
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&#x20;

* `start_span` : 새로운 span 시작

  * span은 operation name 을 가집니다.

* `span.finish()` : span 종료&#x20;

* 해당 span 의 start/end Timestamp 는 tracer implementation 에 의해 자동으로 측정됩니다.

### Context manger 로 span 사용하기

```python
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 인스턴스를 생성해봅시다.

(다음 포스팅에 계속..)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://haleyryu.gitbook.io/engineer/open-tracing/python-opentracing-example.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
