3737import azure .functions as func
3838import mock
3939
40+ import elasticapm
4041from elasticapm .conf import constants
4142from elasticapm .contrib .serverless .azure import AzureFunctionsClient , ElasticAPMExtension , get_faas_data
4243from tests .fixtures import TempStoreClient
@@ -95,6 +96,7 @@ def test_extension_configure():
9596 ElasticAPMExtension .configure (client_class = AzureFunctionsTestClient )
9697 client = ElasticAPMExtension .client
9798 assert client .config .metrics_interval == datetime .timedelta (0 )
99+ assert client .config .breakdown_metrics is False
98100 assert client .config .central_config is False
99101 assert client .config .cloud_provider == "none"
100102 assert client .config .framework_name == "Azure Functions"
@@ -106,6 +108,27 @@ def test_extension_configure():
106108 ElasticAPMExtension .client = None
107109
108110
111+ def test_extension_configure_with_kwargs ():
112+ try :
113+ ElasticAPMExtension .configure (
114+ client_class = AzureFunctionsTestClient , metrics_sets = ["foo" ], service_name = "foo" , environment = "bar"
115+ )
116+ client = ElasticAPMExtension .client
117+
118+ assert client .config .metrics_interval == datetime .timedelta (0 )
119+ assert client .config .breakdown_metrics is False
120+ assert client .config .central_config is False
121+ assert client .config .cloud_provider == "none"
122+ assert client .config .framework_name == "Azure Functions"
123+ assert client .config .service_name == "foo"
124+ assert client .config .environment == "bar"
125+ assert client .config .metrics_sets == ["foo" ]
126+ finally :
127+ if ElasticAPMExtension .client :
128+ ElasticAPMExtension .client .close ()
129+ ElasticAPMExtension .client = None
130+
131+
109132@pytest .mark .parametrize (
110133 "elasticapm_client" , [{"client_class" : AzureFunctionsTestClient }], indirect = ["elasticapm_client" ]
111134)
@@ -122,8 +145,7 @@ def test_pre_post_invocation_app_level_request(elasticapm_client):
122145 body = b"" ,
123146 )
124147 response = func .HttpResponse ("" , status_code = 200 , headers = {}, mimetype = "text/html" )
125- context = mock .Mock (function_name = "foo" )
126- context .function_name = "foo_function"
148+ context = mock .Mock (function_name = "foo_function" , invocation_id = "fooid" )
127149 ElasticAPMExtension .pre_invocation_app_level (None , context , {"request" : request })
128150 ElasticAPMExtension .post_invocation_app_level (None , context , func_ret = response )
129151 transaction = elasticapm_client .events [constants .TRANSACTION ][0 ]
0 commit comments