ray-llm

Форк
0
/
baggage_span_processor.py 
43 строки · 1.6 Кб
1
# Apache 2.0 licensed copy of code from
2
# https://github.com/honeycombio/honeycomb-opentelemetry-python/blob/7c70bb6636ef5d8dae4b01eac46548600bf2836d/src/honeycomb/opentelemetry/baggage.py
3
# on 2023-08-23 by thomas@. No substancial changes made.
4

5
from typing import Optional
6

7
from opentelemetry.baggage import get_all as get_all_baggage
8
from opentelemetry.context import Context
9
from opentelemetry.sdk.trace import SpanProcessor
10
from opentelemetry.trace import Span
11

12

13
class BaggageSpanProcessor(SpanProcessor):
14
    """
15
    The BaggageSpanProcessor reads entries stored in Baggage
16
    from the parent context and adds the baggage entries' keys and
17
    values to the span as attributes on span start.
18

19
    Add this span processor to a tracer provider.
20

21
    Keys and values added to Baggage will appear on subsequent child
22
    spans for a trace within this service *and* be propagated to external
23
    services in accordance with any configured propagation formats
24
    configured. If the external services also have a Baggage span
25
    processor, the keys and values will appear in those child spans as
26
    well.
27

28
    ⚠ Warning ⚠️
29

30
    Do not put sensitive information in Baggage.
31

32
    To repeat: a consequence of adding data to Baggage is that the keys and
33
    values will appear in all outgoing HTTP headers from the application.
34

35
    """
36

37
    def __init__(self) -> None:
38
        pass
39

40
    def on_start(self, span: "Span", parent_context: Optional[Context] = None) -> None:
41
        baggage = get_all_baggage(parent_context)
42
        for key, value in baggage.items():
43
            span.set_attribute(key, value)
44

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.