@@ -20,6 +20,7 @@ import {
20
20
import type { Event , Scope } from '@sentry/types' ;
21
21
import { makeTraceState } from '../src/propagator' ;
22
22
23
+ import { SemanticAttributes } from '@opentelemetry/semantic-conventions' ;
23
24
import { continueTrace , startInactiveSpan , startSpan , startSpanManual } from '../src/trace' ;
24
25
import type { AbstractSpan } from '../src/types' ;
25
26
import { getDynamicSamplingContextFromSpan } from '../src/utils/dynamicSamplingContext' ;
@@ -1358,6 +1359,76 @@ describe('trace (sampling)', () => {
1358
1359
} ) ;
1359
1360
} ) ;
1360
1361
1362
+ describe ( 'HTTP methods (sampling)' , ( ) => {
1363
+ beforeEach ( ( ) => {
1364
+ mockSdkInit ( { enableTracing : true } ) ;
1365
+ } ) ;
1366
+
1367
+ afterEach ( ( ) => {
1368
+ cleanupOtel ( ) ;
1369
+ } ) ;
1370
+
1371
+ it ( 'does sample when HTTP method is other than OPTIONS or HEAD' , ( ) => {
1372
+ const spanGET = startSpanManual (
1373
+ { name : 'test span' , attributes : { [ SemanticAttributes . HTTP_METHOD ] : 'GET' } } ,
1374
+ span => {
1375
+ return span ;
1376
+ } ,
1377
+ ) ;
1378
+ expect ( spanIsSampled ( spanGET ) ) . toBe ( true ) ;
1379
+ expect ( getSamplingDecision ( spanGET . spanContext ( ) ) ) . toBe ( true ) ;
1380
+
1381
+ const spanPOST = startSpanManual (
1382
+ { name : 'test span' , attributes : { [ SemanticAttributes . HTTP_METHOD ] : 'POST' } } ,
1383
+ span => {
1384
+ return span ;
1385
+ } ,
1386
+ ) ;
1387
+ expect ( spanIsSampled ( spanPOST ) ) . toBe ( true ) ;
1388
+ expect ( getSamplingDecision ( spanPOST . spanContext ( ) ) ) . toBe ( true ) ;
1389
+
1390
+ const spanPUT = startSpanManual (
1391
+ { name : 'test span' , attributes : { [ SemanticAttributes . HTTP_METHOD ] : 'PUT' } } ,
1392
+ span => {
1393
+ return span ;
1394
+ } ,
1395
+ ) ;
1396
+ expect ( spanIsSampled ( spanPUT ) ) . toBe ( true ) ;
1397
+ expect ( getSamplingDecision ( spanPUT . spanContext ( ) ) ) . toBe ( true ) ;
1398
+
1399
+ const spanDELETE = startSpanManual (
1400
+ { name : 'test span' , attributes : { [ SemanticAttributes . HTTP_METHOD ] : 'DELETE' } } ,
1401
+ span => {
1402
+ return span ;
1403
+ } ,
1404
+ ) ;
1405
+ expect ( spanIsSampled ( spanDELETE ) ) . toBe ( true ) ;
1406
+ expect ( getSamplingDecision ( spanDELETE . spanContext ( ) ) ) . toBe ( true ) ;
1407
+ } ) ;
1408
+
1409
+ it ( 'does not sample when HTTP method is OPTIONS' , ( ) => {
1410
+ const span = startSpanManual (
1411
+ { name : 'test span' , attributes : { [ SemanticAttributes . HTTP_METHOD ] : 'OPTIONS' } } ,
1412
+ span => {
1413
+ return span ;
1414
+ } ,
1415
+ ) ;
1416
+ expect ( spanIsSampled ( span ) ) . toBe ( false ) ;
1417
+ expect ( getSamplingDecision ( span . spanContext ( ) ) ) . toBe ( false ) ;
1418
+ } ) ;
1419
+
1420
+ it ( 'does not sample when HTTP method is HEAD' , ( ) => {
1421
+ const span = startSpanManual (
1422
+ { name : 'test span' , attributes : { [ SemanticAttributes . HTTP_METHOD ] : 'HEAD' } } ,
1423
+ span => {
1424
+ return span ;
1425
+ } ,
1426
+ ) ;
1427
+ expect ( spanIsSampled ( span ) ) . toBe ( false ) ;
1428
+ expect ( getSamplingDecision ( span . spanContext ( ) ) ) . toBe ( false ) ;
1429
+ } ) ;
1430
+ } ) ;
1431
+
1361
1432
describe ( 'continueTrace' , ( ) => {
1362
1433
beforeEach ( ( ) => {
1363
1434
mockSdkInit ( { enableTracing : true } ) ;
0 commit comments