File tree 3 files changed +12
-8
lines changed
src/opentelemetry/distributedcontext
opentelemetry-sdk/tests/distributedcontext 3 files changed +12
-8
lines changed Original file line number Diff line number Diff line change @@ -74,23 +74,26 @@ def __init__(
74
74
self .value = value
75
75
76
76
77
- class DistributedContext ( dict ) :
77
+ class DistributedContext :
78
78
"""A container for distributed context entries"""
79
79
80
+ def __init__ (self , entries : typing .Iterable [Entry ]) -> None :
81
+ self ._container = {entry .key : entry for entry in entries }
82
+
80
83
def get_entries (self ) -> typing .Iterable [Entry ]:
81
84
"""Returns an immutable iterator to entries."""
82
- return self .values ()
85
+ return self ._container . values ()
83
86
84
87
def get_entry_value (
85
88
self ,
86
89
key : EntryKey
87
- ) -> typing .Optional [EntryValue ]:
90
+ ) -> typing .Optional [Entry ]:
88
91
"""Returns the entry associated with a key or None
89
92
90
93
Args:
91
94
key: the key with which to perform a lookup
92
95
"""
93
- return self .get (key )
96
+ return self ._container . get (key )
94
97
95
98
96
99
class DistributedContextManager :
Original file line number Diff line number Diff line change @@ -72,8 +72,9 @@ def setUp(self):
72
72
distributedcontext .EntryKey ("key" ),
73
73
distributedcontext .EntryValue ("value" ),
74
74
)
75
- context = self .context = distributedcontext .DistributedContext ()
76
- context [entry .key ] = entry
75
+ context = self .context = distributedcontext .DistributedContext ((
76
+ entry ,
77
+ ))
77
78
78
79
def test_get_entries (self ):
79
80
self .assertIn (self .entry , self .context .get_entries ())
Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ def test_use_context(self):
27
27
self .assertIsNone (self .manager .get_current_context ())
28
28
29
29
# Start initial context
30
- dctx = dctx_api .DistributedContext ()
30
+ dctx = dctx_api .DistributedContext (() )
31
31
with self .manager .use_context (dctx ) as current :
32
32
self .assertIs (current , dctx )
33
33
self .assertIs (
@@ -36,7 +36,7 @@ def test_use_context(self):
36
36
)
37
37
38
38
# Context is overridden
39
- nested_dctx = dctx_api .DistributedContext ()
39
+ nested_dctx = dctx_api .DistributedContext (() )
40
40
with self .manager .use_context (nested_dctx ) as current :
41
41
self .assertIs (current , nested_dctx )
42
42
self .assertIs (
You can’t perform that action at this time.
0 commit comments