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 2121
2222from opentelemetry ._opamp import messages
2323from opentelemetry ._opamp .proto import opamp_pb2
24+ from opentelemetry ._opamp .transport .base import HttpTransport
2425from opentelemetry ._opamp .transport .requests import RequestsTransport
2526from opentelemetry ._opamp .version import __version__
2627from opentelemetry .context import (
@@ -61,9 +62,12 @@ def __init__(
6162 timeout_millis : int = _DEFAULT_OPAMP_TIMEOUT_MS ,
6263 agent_identifying_attributes : Mapping [str , AnyValue ],
6364 agent_non_identifying_attributes : Mapping [str , AnyValue ] | None = None ,
65+ transport : HttpTransport = None ,
6466 ):
6567 self ._timeout_millis = timeout_millis
66- self ._transport = RequestsTransport ()
68+ self ._transport = (
69+ RequestsTransport () if transport is None else transport
70+ )
6771
6872 self ._endpoint = endpoint
6973 headers = headers or {}
Original file line number Diff line number Diff line change 1212# See the License for the specific language governing permissions and
1313# limitations under the License.
1414
15+ from __future__ import annotations
16+
1517from typing import Mapping
1618
1719import requests
2224
2325
2426class 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
2729
2830 def send (
2931 self ,
Original file line number Diff line number Diff line change 3030from opentelemetry ._opamp .proto .anyvalue_pb2 import (
3131 KeyValue as PB2KeyValue , # pylint: disable=no-name-in-module
3232)
33+ from opentelemetry ._opamp .transport .requests import RequestsTransport
3334from opentelemetry ._opamp .version import __version__
3435
3536
@@ -61,12 +62,14 @@ def test_can_instantiate_opamp_client_with_defaults():
6162
6263
6364def test_can_instantiate_opamp_client_all_params ():
65+ transport = RequestsTransport ()
6466 client = OpAMPClient (
6567 endpoint = "url" ,
6668 headers = {"an" : "header" },
6769 timeout_millis = 2_000 ,
6870 agent_identifying_attributes = {"foo" : "bar" },
6971 agent_non_identifying_attributes = {"bar" : "baz" },
72+ transport = transport ,
7073 )
7174
7275 assert client
@@ -85,6 +88,7 @@ def test_can_instantiate_opamp_client_all_params():
8588 assert client ._agent_description .non_identifying_attributes == [
8689 PB2KeyValue (key = "bar" , value = PB2AnyValue (string_value = "baz" )),
8790 ]
91+ assert client ._transport is transport
8892
8993
9094def test_client_headers_override_defaults ():
Original file line number Diff line number Diff line change 1515from unittest import mock
1616
1717import pytest
18+ import requests
1819
1920from opentelemetry ._opamp .proto import opamp_pb2
2021from opentelemetry ._opamp .transport .base import base_headers
@@ -28,6 +29,14 @@ def test_can_instantiate_requests_transport():
2829 assert transport
2930
3031
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+
3140def test_can_send ():
3241 transport = RequestsTransport ()
3342 serialized_message = opamp_pb2 .ServerToAgent ().SerializeToString ()
You can’t perform that action at this time.
0 commit comments