@@ -327,3 +327,77 @@ func TestOnEndDoesNotFinishSentryRequests(t *testing.T) {
327
327
events := sentryTransport .Events ()
328
328
assertEqual (t , len (events ), 0 )
329
329
}
330
+
331
+ func TestParseSpanAttributesHttpClient (t * testing.T ) {
332
+ _ , _ , tracer := setupSpanProcessorTest ()
333
+ ctx , otelRootSpan := tracer .Start (
334
+ emptyContextWithSentry (),
335
+ "rootSpan" ,
336
+ trace .WithSpanKind (trace .SpanKindClient ),
337
+ trace .WithAttributes (attribute .String ("http.method" , "GET" )),
338
+ trace .WithAttributes (attribute .String ("http.url" , "http://localhost:1234/api/checkout1?q1=q2#fragment" )),
339
+ )
340
+ _ , otelChildSpan := tracer .Start (ctx ,
341
+ "childSpan" ,
342
+ trace .WithSpanKind (trace .SpanKindClient ),
343
+ trace .WithAttributes (attribute .String ("http.method" , "POST" )),
344
+ trace .WithAttributes (attribute .String ("http.url" , "http://localhost:2345/api/checkout2?q1=q2#fragment" )),
345
+ )
346
+
347
+ sentryTransaction , _ := sentrySpanMap .Get (otelRootSpan .SpanContext ().SpanID ())
348
+ sentrySpan , _ := sentrySpanMap .Get (otelChildSpan .SpanContext ().SpanID ())
349
+
350
+ otelChildSpan .End ()
351
+ otelRootSpan .End ()
352
+
353
+ // Transaction
354
+ assertEqual (t , sentryTransaction .Name , "GET http://localhost:1234/api/checkout1" )
355
+ assertEqual (t , sentryTransaction .Description , "" )
356
+ assertEqual (t , sentryTransaction .Op , "http.client" )
357
+ assertEqual (t , sentryTransaction .Source , sentry .TransactionSource ("url" ))
358
+
359
+ // Span
360
+ assertEqual (t , sentrySpan .Name , "" )
361
+ assertEqual (t , sentrySpan .Description , "POST http://localhost:2345/api/checkout2" )
362
+ assertEqual (t , sentrySpan .Op , "http.client" )
363
+ assertEqual (t , sentrySpan .Source , sentry .TransactionSource ("" ))
364
+ }
365
+
366
+ func TestParseSpanAttributesHttpServer (t * testing.T ) {
367
+ _ , _ , tracer := setupSpanProcessorTest ()
368
+ ctx , otelRootSpan := tracer .Start (
369
+ emptyContextWithSentry (),
370
+ "rootSpan" ,
371
+ trace .WithSpanKind (trace .SpanKindServer ),
372
+ trace .WithAttributes (attribute .String ("http.method" , "GET" )),
373
+ trace .WithAttributes (attribute .String ("http.target" , "/api/checkout1?k=v" )),
374
+ // We ignore "http.url" if "http.target" is present
375
+ trace .WithAttributes (attribute .String ("http.url" , "http://localhost:1234/api/checkout?q1=q2#fragment" )),
376
+ )
377
+ _ , otelChildSpan := tracer .Start (
378
+ ctx ,
379
+ "span name" ,
380
+ trace .WithSpanKind (trace .SpanKindServer ),
381
+ trace .WithAttributes (attribute .String ("http.method" , "POST" )),
382
+ trace .WithAttributes (attribute .String ("http.target" , "/api/checkout2?k=v" )),
383
+ // We ignore "http.url" if "http.target" is present
384
+ trace .WithAttributes (attribute .String ("http.url" , "http://localhost:2345/api/checkout?q1=q2#fragment" )),
385
+ )
386
+ sentryTransaction , _ := sentrySpanMap .Get (otelRootSpan .SpanContext ().SpanID ())
387
+ sentrySpan , _ := sentrySpanMap .Get (otelChildSpan .SpanContext ().SpanID ())
388
+
389
+ otelChildSpan .End ()
390
+ otelRootSpan .End ()
391
+
392
+ // Transaction
393
+ assertEqual (t , sentryTransaction .Name , "GET /api/checkout1" )
394
+ assertEqual (t , sentryTransaction .Description , "" )
395
+ assertEqual (t , sentryTransaction .Op , "http.server" )
396
+ assertEqual (t , sentryTransaction .Source , sentry .TransactionSource ("url" ))
397
+
398
+ // Span
399
+ assertEqual (t , sentrySpan .Name , "" )
400
+ assertEqual (t , sentrySpan .Description , "POST /api/checkout2" )
401
+ assertEqual (t , sentrySpan .Op , "http.server" )
402
+ assertEqual (t , sentrySpan .Source , sentry .TransactionSource ("" ))
403
+ }
0 commit comments