File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ import (
1414 "path/filepath"
1515 "runtime"
1616 "slices"
17+ "strconv"
1718 "strings"
1819 "sync"
1920 "time"
@@ -283,6 +284,7 @@ func (s *service) SetSampleRate(rate int) {
283284 defer s .mu .Unlock ()
284285
285286 s .sampleRate = rate
287+ s .commonDimensions ["sample_rate" ] = strconv .Itoa (rate )
286288}
287289
288290func (s * service ) Flush () {
Original file line number Diff line number Diff line change @@ -579,6 +579,24 @@ func TestServiceSampling(t *testing.T) {
579579 assert .False (t , called , "flusher should not be called after SetSampleRate reduced the rate" )
580580 })
581581
582+ t .Run ("SetSampleRate updates sample_rate dimension" , func (t * testing.T ) {
583+ t .Cleanup (stubDeviceID ("test-device" ))
584+
585+ var captured SendTelemetryPayload
586+ svc := newService (func (p SendTelemetryPayload ) { captured = p }, ghtelemetry.Dimensions {
587+ "sample_rate" : "1" ,
588+ })
589+ svc .sampleRate = 1
590+ svc .sampleBucket = 0
591+
592+ svc .SetSampleRate (100 )
593+ svc .Record (ghtelemetry.Event {Type : "test" })
594+ svc .Flush ()
595+
596+ require .Len (t , captured .Events , 1 )
597+ assert .Equal (t , "100" , captured .Events [0 ].Dimensions ["sample_rate" ])
598+ })
599+
582600 t .Run ("WithSampleRate option sets rate on construction" , func (t * testing.T ) {
583601 t .Cleanup (stubDeviceID ("test-device" ))
584602
You can’t perform that action at this time.
0 commit comments