1# ------------------------------------
2# Copyright (c) Microsoft Corporation.
3# Licensed under the MIT License.
4# ------------------------------------
5from enum import Enum
6from typing import Dict, Mapping, Optional, Union, Sequence, TypedDict
7
8from .._enum_meta import CaseInsensitiveEnumMeta
9
10
11AttributeValue = Union[
12 str,
13 bool,
14 int,
15 float,
16 Sequence[str],
17 Sequence[bool],
18 Sequence[int],
19 Sequence[float],
20]
21Attributes = Mapping[str, AttributeValue]
22
23
24class SpanKind(Enum, metaclass=CaseInsensitiveEnumMeta):
25 """Describes the role or kind of a span within a distributed trace.
26
27 This helps to categorize spans based on their relationship to other spans and the type
28 of operation they represent.
29 """
30
31 UNSPECIFIED = 1
32 """Unspecified span kind."""
33
34 SERVER = 2
35 """Indicates that the span describes an operation that handles a remote request."""
36
37 CLIENT = 3
38 """Indicates that the span describes a request to some remote service."""
39
40 PRODUCER = 4
41 """Indicates that the span describes the initiation or scheduling of a local or remote operation."""
42
43 CONSUMER = 5
44 """Indicates that the span represents the processing of an operation initiated by a producer."""
45
46 INTERNAL = 6
47 """Indicates that the span is used internally in the application."""
48
49
50class Link:
51 """Represents a reference from one span to another span.
52
53 :param headers: A dictionary of the request header as key value pairs.
54 :type headers: dict
55 :param attributes: Any additional attributes that should be added to link
56 :type attributes: dict
57 """
58
59 def __init__(self, headers: Dict[str, str], attributes: Optional[Attributes] = None) -> None:
60 self.headers = headers
61 self.attributes = attributes
62
63
64class TracingOptions(TypedDict, total=False):
65 """Options to configure tracing behavior for operations."""
66
67 enabled: bool
68 """Whether tracing is enabled for the operation. By default, if the global setting is enabled, tracing is
69 enabled for all operations. This option can be used to override the global setting for a specific operation."""
70 attributes: Attributes
71 """Attributes to include in the spans emitted for the operation."""