Skip to content
1 change: 1 addition & 0 deletions .ci/.matrix_framework.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,4 @@ FRAMEWORK:
- kafka-python-newest
- grpc-newest
- azurefunctions-newest
- azure-newest
1 change: 1 addition & 0 deletions .ci/.matrix_framework_full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,4 @@ FRAMEWORK:
- grpc-newest
#- grpc-1.24 # This appears to have problems with python>3.6?
- azurefunctions-newest
- azure-newest
11 changes: 7 additions & 4 deletions elasticapm/instrumentation/packages/azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,12 @@ def handle_azuretable(request, hostname, path, query_params, service, service_ty
account_name = hostname.split(".")[0]
method = request.method
body = request.body
try:
body = json.loads(body)
except json.decoder.JSONDecodeError: # str not bytes
if body:
try:
body = json.loads(body)
except json.decoder.JSONDecodeError: # str not bytes
body = {}
else:
body = {}
# /tablename(PartitionKey='<partition-key>',RowKey='<row-key>')
resource_name = path.split("/", 1)[1] if "/" in path else path
Expand All @@ -313,7 +316,7 @@ def handle_azuretable(request, hostname, path, query_params, service, service_ty
}

operation_name = "Unknown"
if method.lower() == "put":
if method.lower() == "put" or method.lower() == "patch":
operation_name = "Update"
if "properties" in query_params.get("comp", []):
operation_name = "SetProperties"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import pytest

azure = pytest.importorskip("azure")
azure = pytest.importorskip("azure.functions")

import datetime
import os
Expand Down
70 changes: 70 additions & 0 deletions tests/instrumentation/azure_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,13 @@
azureblob = pytest.importorskip("azure.storage.blob")
azurequeue = pytest.importorskip("azure.storage.queue")
azuretable = pytest.importorskip("azure.cosmosdb.table")
azuredatatable = pytest.importorskip("azure.data.tables")
azurefile = pytest.importorskip("azure.storage.fileshare")
pytestmark = [pytest.mark.azurestorage]


from azure.cosmosdb.table.tableservice import TableService
from azure.data.tables import TableServiceClient as DataTableServiceClient
from azure.storage.blob import BlobServiceClient
from azure.storage.fileshare import ShareClient
from azure.storage.queue import QueueClient
Expand Down Expand Up @@ -82,6 +85,19 @@ def queue_client():
queue_client.delete_queue()


@pytest.fixture()
def data_table_service():
table_name = "apmagentpythonci" + str(uuid.uuid4().hex)
data_table_service_client = DataTableServiceClient.from_connection_string(conn_str=CONNECTION_STRING)
data_table_service = data_table_service_client.get_table_client(table_name)
data_table_service.create_table()
data_table_service.table_name = table_name

yield data_table_service

data_table_service.delete_table()


@pytest.fixture()
def table_service():
table_name = "apmagentpythonci" + str(uuid.uuid4().hex)
Expand Down Expand Up @@ -182,6 +198,24 @@ def test_queue(instrument, elasticapm_client, queue_client):
assert span["action"] == "delete"


def test_data_table_create(instrument, elasticapm_client):
table_name = "apmagentpythonci" + str(uuid.uuid4().hex)
data_table_service_client = DataTableServiceClient.from_connection_string(conn_str=CONNECTION_STRING)
data_table_service = data_table_service_client.get_table_client(table_name)

elasticapm_client.begin_transaction("transaction.test")
data_table_service.create_table()
data_table_service.delete_table()
elasticapm_client.end_transaction("MyView")

span = elasticapm_client.events[constants.SPAN][0]

assert span["name"] == "AzureTable Create {}".format(table_name)
assert span["type"] == "storage"
assert span["subtype"] == "azuretable"
assert span["action"] == "Create"


def test_table_create(instrument, elasticapm_client):
table_name = "apmagentpythonci" + str(uuid.uuid4().hex)
table_service = TableService(connection_string=CONNECTION_STRING)
Expand All @@ -199,6 +233,42 @@ def test_table_create(instrument, elasticapm_client):
assert span["action"] == "Create"


def test_data_table(instrument, elasticapm_client, data_table_service):
table_name = data_table_service.table_name
elasticapm_client.begin_transaction("transaction.test")
task = {"PartitionKey": "tasksSeattle", "RowKey": "001", "description": "Take out the trash", "priority": 200}
data_table_service.create_entity(task)
task = {"PartitionKey": "tasksSeattle", "RowKey": "001", "description": "Take out the garbage", "priority": 250}
data_table_service.update_entity(task)
task = data_table_service.get_entity("tasksSeattle", "001")
data_table_service.delete_entity("tasksSeattle", "001")
elasticapm_client.end_transaction("MyView")

span = elasticapm_client.events[constants.SPAN][0]
assert span["name"] == "AzureTable Insert {}".format(table_name)
assert span["type"] == "storage"
assert span["subtype"] == "azuretable"
assert span["action"] == "Insert"

span = elasticapm_client.events[constants.SPAN][1]
assert span["name"] == "AzureTable Update {}(PartitionKey='tasksSeattle',RowKey='001')".format(table_name)
assert span["type"] == "storage"
assert span["subtype"] == "azuretable"
assert span["action"] == "Update"

span = elasticapm_client.events[constants.SPAN][2]
assert span["name"] == "AzureTable Query {}(PartitionKey='tasksSeattle',RowKey='001')".format(table_name)
assert span["type"] == "storage"
assert span["subtype"] == "azuretable"
assert span["action"] == "Query"

span = elasticapm_client.events[constants.SPAN][3]
assert span["name"] == "AzureTable Delete {}(PartitionKey='tasksSeattle',RowKey='001')".format(table_name)
assert span["type"] == "storage"
assert span["subtype"] == "azuretable"
assert span["action"] == "Delete"


def test_table(instrument, elasticapm_client, table_service):
table_name = table_service.table_name
elasticapm_client.begin_transaction("transaction.test")
Expand Down
6 changes: 6 additions & 0 deletions tests/requirements/reqs-azure-newest.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
azure-storage-blob
azure-storage-queue
azure-data-tables
azure-storage-file-share
azure-cosmosdb-table
-r reqs-base.txt
Loading