Skip to content

Commit 627717c

Browse files
committed
contrib/serverless/azure: fix client_class and metrics sets invocation
Fix extension handling of client_class that was ignored and typo in metrics_sets arg that was mistyped. While at it fix also a broken tests and add testing in the matrix.
1 parent f64a0e5 commit 627717c

File tree

5 files changed

+30
-4
lines changed

5 files changed

+30
-4
lines changed

.ci/.matrix_framework.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,4 @@ FRAMEWORK:
5656
- aiobotocore-newest
5757
- kafka-python-newest
5858
- grpc-newest
59+
- azurefunctions-newest

.ci/.matrix_framework_full.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,4 @@ FRAMEWORK:
9292
- kafka-python-newest
9393
- grpc-newest
9494
#- grpc-1.24 # This appears to have problems with python>3.6?
95+
- azurefunctions-newest

elasticapm/contrib/serverless/azure.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def configure(cls, client_class=AzureFunctionsClient, **kwargs) -> None:
9696
if not client:
9797
kwargs["metrics_interval"] = "0ms"
9898
kwargs["breakdown_metrics"] = "false"
99-
if "metric_sets" not in kwargs and "ELASTIC_APM_METRICS_SETS" not in os.environ:
99+
if "metrics_sets" not in kwargs and "ELASTIC_APM_METRICS_SETS" not in os.environ:
100100
# Allow users to override metrics sets
101101
kwargs["metrics_sets"] = []
102102
kwargs["central_config"] = "false"
@@ -114,7 +114,7 @@ def configure(cls, client_class=AzureFunctionsClient, **kwargs) -> None:
114114
and "AZURE_FUNCTIONS_ENVIRONMENT" in os.environ
115115
):
116116
kwargs["environment"] = os.environ["AZURE_FUNCTIONS_ENVIRONMENT"]
117-
client = AzureFunctionsClient(**kwargs)
117+
client = client_class(**kwargs)
118118
cls.client = client
119119

120120
@classmethod

tests/contrib/serverless/azurefunctions/azure_functions_tests.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import azure.functions as func
3838
import mock
3939

40+
import elasticapm
4041
from elasticapm.conf import constants
4142
from elasticapm.contrib.serverless.azure import AzureFunctionsClient, ElasticAPMExtension, get_faas_data
4243
from 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]
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
azure-functions
2+
-r reqs-base.txt

0 commit comments

Comments
 (0)