honeyhive.utils.baggage_dict
Baggage dictionary for OpenTelemetry context management.
BaggageDict
Dictionary-like interface for OpenTelemetry baggage.
This class provides a convenient way to work with OpenTelemetry baggage as if it were a regular dictionary, while maintaining proper context propagation.
Source code in src/honeyhive/utils/baggage_dict.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | |
context
property
context: Context
Get the current context.
get
Get a value from baggage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Baggage key |
required |
default
|
Any
|
Default value if key not found |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
Value from baggage or default |
Source code in src/honeyhive/utils/baggage_dict.py
32 33 34 35 36 37 38 39 40 41 42 43 44 | |
set
set(key: str, value: Any) -> BaggageDict
Set a value in baggage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Baggage key |
required |
value
|
Any
|
Value to set |
required |
Returns:
| Type | Description |
|---|---|
BaggageDict
|
New BaggageDict with updated context |
Source code in src/honeyhive/utils/baggage_dict.py
46 47 48 49 50 51 52 53 54 55 56 57 58 | |
delete
delete(key: str) -> BaggageDict
Delete a key from baggage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Baggage key to delete |
required |
Returns:
| Type | Description |
|---|---|
BaggageDict
|
New BaggageDict with updated context |
Source code in src/honeyhive/utils/baggage_dict.py
60 61 62 63 64 65 66 67 68 69 70 71 | |
update
update(**kwargs: Any) -> BaggageDict
Update multiple baggage values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Any
|
Key-value pairs to set |
{}
|
Returns:
| Type | Description |
|---|---|
BaggageDict
|
New BaggageDict with updated context |
Source code in src/honeyhive/utils/baggage_dict.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |
clear
clear() -> BaggageDict
Clear all baggage.
Returns:
| Type | Description |
|---|---|
BaggageDict
|
New BaggageDict with empty baggage |
Source code in src/honeyhive/utils/baggage_dict.py
89 90 91 92 93 94 95 96 97 98 | |
items
Get all baggage items as a dictionary.
Returns:
| Type | Description |
|---|---|
Dict[str, str]
|
Dictionary of baggage key-value pairs |
Source code in src/honeyhive/utils/baggage_dict.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | |
keys
Get all baggage keys.
Source code in src/honeyhive/utils/baggage_dict.py
117 118 119 | |
values
values() -> ValuesView[str]
Get all baggage values.
Source code in src/honeyhive/utils/baggage_dict.py
121 122 123 | |
from_dict
classmethod
from_dict(
data: Dict[str, Any], ctx: Optional[Context] = None
) -> BaggageDict
Create BaggageDict from dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Dict[str, Any]
|
Dictionary of key-value pairs |
required |
ctx
|
Optional[Context]
|
Optional OpenTelemetry context |
None
|
Returns:
| Type | Description |
|---|---|
BaggageDict
|
New BaggageDict with baggage from dictionary |
Source code in src/honeyhive/utils/baggage_dict.py
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | |
as_context
as_context() -> Iterator[None]
Context manager to temporarily set baggage in current context.
Example
with BaggageDict().set("user_id", "123").as_context(): # baggage is available in this context pass
Source code in src/honeyhive/utils/baggage_dict.py
173 174 175 176 177 178 179 180 181 182 183 184 185 186 | |