File tree Expand file tree Collapse file tree 4 files changed +22
-3
lines changed
opamp/opentelemetry-opamp-client Expand file tree Collapse file tree 4 files changed +22
-3
lines changed Original file line number Diff line number Diff line change 21
21
22
22
from opentelemetry ._opamp import messages
23
23
from opentelemetry ._opamp .proto import opamp_pb2
24
+ from opentelemetry ._opamp .transport .base import HttpTransport
24
25
from opentelemetry ._opamp .transport .requests import RequestsTransport
25
26
from opentelemetry ._opamp .version import __version__
26
27
from opentelemetry .context import (
@@ -61,9 +62,12 @@ def __init__(
61
62
timeout_millis : int = _DEFAULT_OPAMP_TIMEOUT_MS ,
62
63
agent_identifying_attributes : Mapping [str , AnyValue ],
63
64
agent_non_identifying_attributes : Mapping [str , AnyValue ] | None = None ,
65
+ transport : HttpTransport = None ,
64
66
):
65
67
self ._timeout_millis = timeout_millis
66
- self ._transport = RequestsTransport ()
68
+ self ._transport = (
69
+ RequestsTransport () if transport is None else transport
70
+ )
67
71
68
72
self ._endpoint = endpoint
69
73
headers = headers or {}
Original file line number Diff line number Diff line change 12
12
# See the License for the specific language governing permissions and
13
13
# limitations under the License.
14
14
15
+ from __future__ import annotations
16
+
15
17
from typing import Mapping
16
18
17
19
import requests
22
24
23
25
24
26
class RequestsTransport (HttpTransport ):
25
- def __init__ (self ):
26
- self .session = requests .Session ()
27
+ def __init__ (self , session : requests . Session | None = None ):
28
+ self .session = requests .Session () if session is None else session
27
29
28
30
def send (
29
31
self ,
Original file line number Diff line number Diff line change 30
30
from opentelemetry ._opamp .proto .anyvalue_pb2 import (
31
31
KeyValue as PB2KeyValue , # pylint: disable=no-name-in-module
32
32
)
33
+ from opentelemetry ._opamp .transport .requests import RequestsTransport
33
34
from opentelemetry ._opamp .version import __version__
34
35
35
36
@@ -61,12 +62,14 @@ def test_can_instantiate_opamp_client_with_defaults():
61
62
62
63
63
64
def test_can_instantiate_opamp_client_all_params ():
65
+ transport = RequestsTransport ()
64
66
client = OpAMPClient (
65
67
endpoint = "url" ,
66
68
headers = {"an" : "header" },
67
69
timeout_millis = 2_000 ,
68
70
agent_identifying_attributes = {"foo" : "bar" },
69
71
agent_non_identifying_attributes = {"bar" : "baz" },
72
+ transport = transport ,
70
73
)
71
74
72
75
assert client
@@ -85,6 +88,7 @@ def test_can_instantiate_opamp_client_all_params():
85
88
assert client ._agent_description .non_identifying_attributes == [
86
89
PB2KeyValue (key = "bar" , value = PB2AnyValue (string_value = "baz" )),
87
90
]
91
+ assert client ._transport is transport
88
92
89
93
90
94
def test_client_headers_override_defaults ():
Original file line number Diff line number Diff line change 15
15
from unittest import mock
16
16
17
17
import pytest
18
+ import requests
18
19
19
20
from opentelemetry ._opamp .proto import opamp_pb2
20
21
from opentelemetry ._opamp .transport .base import base_headers
@@ -28,6 +29,14 @@ def test_can_instantiate_requests_transport():
28
29
assert transport
29
30
30
31
32
+ def test_can_instantiate_requests_transport_with_own_session ():
33
+ session = requests .Session ()
34
+ transport = RequestsTransport (session = session )
35
+
36
+ assert transport
37
+ assert transport .session is session
38
+
39
+
31
40
def test_can_send ():
32
41
transport = RequestsTransport ()
33
42
serialized_message = opamp_pb2 .ServerToAgent ().SerializeToString ()
You can’t perform that action at this time.
0 commit comments