3939azureblob = pytest .importorskip ("azure.storage.blob" )
4040azurequeue = pytest .importorskip ("azure.storage.queue" )
4141azuretable = pytest .importorskip ("azure.cosmosdb.table" )
42+ azuredatatable = pytest .importorskip ("azure.data.tables" )
4243azurefile = pytest .importorskip ("azure.storage.fileshare" )
4344pytestmark = [pytest .mark .azurestorage ]
4445
46+ from azure .data .tables import TableServiceClient as DataTableServiceClient
4547from azure .cosmosdb .table .tableservice import TableService
4648from azure .storage .blob import BlobServiceClient
4749from azure .storage .fileshare import ShareClient
@@ -82,6 +84,18 @@ def queue_client():
8284 queue_client .delete_queue ()
8385
8486
87+ @pytest .fixture ()
88+ def data_table_service ():
89+ table_name = "apmagentpythonci" + str (uuid .uuid4 ().hex )
90+ data_table_service_client = DataTableServiceClient .from_connection_string (conn_str = CONNECTION_STRING )
91+ data_table_service = data_table_service_client .get_table_client (table_name )
92+ data_table_service .create_table ()
93+ data_table_service .table_name = table_name
94+
95+ yield data_table_service
96+
97+ data_table_service .delete_table ()
98+
8599@pytest .fixture ()
86100def table_service ():
87101 table_name = "apmagentpythonci" + str (uuid .uuid4 ().hex )
@@ -182,6 +196,23 @@ def test_queue(instrument, elasticapm_client, queue_client):
182196 assert span ["action" ] == "delete"
183197
184198
199+ def test_data_table_create (instrument , elasticapm_client ):
200+ table_name = "apmagentpythonci" + str (uuid .uuid4 ().hex )
201+ data_table_service_client = DataTableServiceClient .from_connection_string (conn_str = CONNECTION_STRING )
202+ data_table_service = data_table_service_client .get_table_client (table_name )
203+
204+ elasticapm_client .begin_transaction ("transaction.test" )
205+ data_table_service .create_table ()
206+ data_table_service .delete_table ()
207+ elasticapm_client .end_transaction ("MyView" )
208+
209+ span = elasticapm_client .events [constants .SPAN ][0 ]
210+
211+ assert span ["name" ] == "AzureTable Create {}" .format (table_name )
212+ assert span ["type" ] == "storage"
213+ assert span ["subtype" ] == "azuretable"
214+ assert span ["action" ] == "Create"
215+
185216def test_table_create (instrument , elasticapm_client ):
186217 table_name = "apmagentpythonci" + str (uuid .uuid4 ().hex )
187218 table_service = TableService (connection_string = CONNECTION_STRING )
@@ -198,6 +229,40 @@ def test_table_create(instrument, elasticapm_client):
198229 assert span ["subtype" ] == "azuretable"
199230 assert span ["action" ] == "Create"
200231
232+ def test_data_table (instrument , elasticapm_client , data_table_service ):
233+ table_name = data_table_service .table_name
234+ elasticapm_client .begin_transaction ("transaction.test" )
235+ task = {"PartitionKey" : "tasksSeattle" , "RowKey" : "001" , "description" : "Take out the trash" , "priority" : 200 }
236+ data_table_service .create_entity (task )
237+ task = {"PartitionKey" : "tasksSeattle" , "RowKey" : "001" , "description" : "Take out the garbage" , "priority" : 250 }
238+ data_table_service .update_entity (task )
239+ task = data_table_service .get_entity ("tasksSeattle" , "001" )
240+ data_table_service .delete_entity ("tasksSeattle" , "001" )
241+ elasticapm_client .end_transaction ("MyView" )
242+
243+ span = elasticapm_client .events [constants .SPAN ][0 ]
244+ assert span ["name" ] == "AzureTable Insert {}" .format (table_name )
245+ assert span ["type" ] == "storage"
246+ assert span ["subtype" ] == "azuretable"
247+ assert span ["action" ] == "Insert"
248+
249+ span = elasticapm_client .events [constants .SPAN ][1 ]
250+ assert span ["name" ] == "AzureTable Update {}(PartitionKey='tasksSeattle',RowKey='001')" .format (table_name )
251+ assert span ["type" ] == "storage"
252+ assert span ["subtype" ] == "azuretable"
253+ assert span ["action" ] == "Update"
254+
255+ span = elasticapm_client .events [constants .SPAN ][2 ]
256+ assert span ["name" ] == "AzureTable Query {}(PartitionKey='tasksSeattle',RowKey='001')" .format (table_name )
257+ assert span ["type" ] == "storage"
258+ assert span ["subtype" ] == "azuretable"
259+ assert span ["action" ] == "Query"
260+
261+ span = elasticapm_client .events [constants .SPAN ][3 ]
262+ assert span ["name" ] == "AzureTable Delete {}(PartitionKey='tasksSeattle',RowKey='001')" .format (table_name )
263+ assert span ["type" ] == "storage"
264+ assert span ["subtype" ] == "azuretable"
265+ assert span ["action" ] == "Delete"
201266
202267def test_table (instrument , elasticapm_client , table_service ):
203268 table_name = table_service .table_name
0 commit comments