@@ -181,22 +181,48 @@ def test_database_db_statement_exclude():
181
181
182
182
183
183
@pytest .mark .parametrize (
184
- "trace_type,args,attrs " ,
184
+ "trace_type,args,i_attrs,a_attrs " ,
185
185
(
186
186
(
187
187
DatastoreTrace ,
188
- ("db_product" , "db_target" , "db_operation" ),
189
- {"db.collection" : "db_target" , "db.operation" : "db_operation" },
188
+ ("db_product" , "db_target" , "db_operation" , "db_host" , "1234" , "db_name" ),
189
+ {"component" : "db_product" , "span.kind" : "client" },
190
+ {
191
+ "db.system" : "db_product" ,
192
+ "db.operation" : "db_operation" ,
193
+ "db.collection" : "db_target" ,
194
+ "db.instance" : "db_name" ,
195
+ "peer.address" : "db_host:1234" ,
196
+ "peer.hostname" : "db_host" ,
197
+ "server.address" : "db_host" ,
198
+ "server.port" : 1234 ,
199
+ },
190
200
),
191
201
(
192
202
DatabaseTrace ,
193
203
("select 1 from db_table" ,),
194
- {"db.collection" : "db_table" , "db.statement" : "select ? from db_table" },
204
+ {"span.kind" : "client" },
205
+ {"db.collection" : "db_table" , "db.statement" : "select ? from db_table" , "db.operation" : "select" },
206
+ ),
207
+ (
208
+ DatabaseTrace ,
209
+ ("select 1 from db_table" , None , None , None , None , None , "db_host" , "1234" , "db_name" ),
210
+ {"span.kind" : "client" },
211
+ {
212
+ "db.statement" : "select ? from db_table" ,
213
+ "db.operation" : "select" ,
214
+ "db.collection" : "db_table" ,
215
+ "db.instance" : "db_name" ,
216
+ "peer.address" : "db_host:1234" ,
217
+ "peer.hostname" : "db_host" ,
218
+ "server.address" : "db_host" ,
219
+ "server.port" : 1234 ,
220
+ },
195
221
),
196
222
),
197
223
)
198
- def test_datastore_database_trace_attrs (trace_type , args , attrs ):
199
- @validate_span_events (count = 1 , exact_agents = attrs )
224
+ def test_datastore_database_trace_attrs (trace_type , args , i_attrs , a_attrs ):
225
+ @validate_span_events (count = 1 , exact_intrinsics = i_attrs , exact_agents = a_attrs )
200
226
@override_application_settings ({"distributed_tracing.enabled" : True , "span_events.enabled" : True })
201
227
@background_task (name = "test_database_db_statement_exclude" )
202
228
def test ():
@@ -293,8 +319,23 @@ def _test():
293
319
@pytest .mark .parametrize (
294
320
"kwarg_override,attribute_override" ,
295
321
(
296
- ({"host" : "a" * 256 }, {"peer.hostname" : "a" * 255 , "peer.address" : "a" * 255 }),
297
- ({"port_path_or_id" : "a" * 256 , "host" : "a" }, {"peer.hostname" : "a" , "peer.address" : f"a:{ 'a' * 253 } " }),
322
+ ({"product" : "a" * 256 }, {"component" : "a" * 255 , "db.system" : "a" * 255 }),
323
+ ({"target" : "a" * 256 }, {"db.collection" : "a" * 255 }),
324
+ ({"operation" : "a" * 256 }, {"db.operation" : "a" * 255 }),
325
+ ({"host" : "a" * 256 }, {"peer.hostname" : "a" * 255 , "peer.address" : "a" * 255 , "server.address" : "a" * 255 }),
326
+ (
327
+ {"port_path_or_id" : "a" * 256 , "host" : "a" },
328
+ {"peer.hostname" : "a" , "peer.address" : f"a:{ 'a' * 253 } " , "server.address" : "a" , "server.port" : None },
329
+ ),
330
+ (
331
+ {"port_path_or_id" : "1" * 256 , "host" : "a" },
332
+ {
333
+ "peer.hostname" : "a" ,
334
+ "peer.address" : f"a:{ '1' * 253 } " ,
335
+ "server.address" : "a" ,
336
+ "server.port" : int ("1" * 256 ),
337
+ },
338
+ ),
298
339
({"database_name" : "a" * 256 }, {"db.instance" : "a" * 255 }),
299
340
),
300
341
)
@@ -308,7 +349,16 @@ def test_datastore_span_limits(kwarg_override, attribute_override):
308
349
"component" : "library" ,
309
350
}
310
351
311
- exact_agents = {"db.instance" : "db" , "peer.hostname" : "foo" , "peer.address" : "foo:1234" }
352
+ exact_agents = {
353
+ "db.collection" : "table" ,
354
+ "db.instance" : "db" ,
355
+ "db.operation" : "operation" ,
356
+ "db.system" : "library" ,
357
+ "peer.address" : "foo:1234" ,
358
+ "peer.hostname" : "foo" ,
359
+ "server.address" : "foo" ,
360
+ "server.port" : 1234 ,
361
+ }
312
362
313
363
for k , v in attribute_override .items ():
314
364
if k in exact_agents :
0 commit comments