@@ -519,6 +519,12 @@ func (s *Span) toEvent() *Event {
519
519
}
520
520
contexts ["trace" ] = s .traceContext ().Map ()
521
521
522
+ // Make sure that the transaction source is valid
523
+ transactionSource := s .Source
524
+ if ! transactionSource .isValid () {
525
+ transactionSource = SourceCustom
526
+ }
527
+
522
528
return & Event {
523
529
Type : transactionType ,
524
530
Transaction : s .Name ,
@@ -529,7 +535,7 @@ func (s *Span) toEvent() *Event {
529
535
StartTime : s .StartTime ,
530
536
Spans : finished ,
531
537
TransactionInfo : & TransactionInfo {
532
- Source : s . Source ,
538
+ Source : transactionSource ,
533
539
},
534
540
sdkMetaData : SDKMetaData {
535
541
dsc : s .dynamicSamplingContext ,
@@ -620,6 +626,24 @@ const (
620
626
SourceTask TransactionSource = "task"
621
627
)
622
628
629
+ // A set of all valid transaction sources.
630
+ var allTransactionSources = map [TransactionSource ]struct {}{
631
+ SourceCustom : {},
632
+ SourceURL : {},
633
+ SourceRoute : {},
634
+ SourceView : {},
635
+ SourceComponent : {},
636
+ SourceTask : {},
637
+ }
638
+
639
+ // isValid returns 'true' if the given transaction source is a valid
640
+ // source as recognized by the envelope protocol:
641
+ // https://develop.sentry.dev/sdk/event-payloads/transaction/#transaction-annotations
642
+ func (ts TransactionSource ) isValid () bool {
643
+ _ , found := allTransactionSources [ts ]
644
+ return found
645
+ }
646
+
623
647
// SpanStatus is the status of a span.
624
648
type SpanStatus uint8
625
649
@@ -788,7 +812,7 @@ type SpanOption func(s *Span)
788
812
// starting a span affects the span tree as a whole, potentially overwriting a
789
813
// name set previously.
790
814
//
791
- // Deprecated: Use WithTransactionSource () instead.
815
+ // Deprecated: Use WithTransactionName () instead.
792
816
func TransactionName (name string ) SpanOption {
793
817
return WithTransactionName (name )
794
818
}
@@ -826,6 +850,10 @@ func TransctionSource(source TransactionSource) SpanOption {
826
850
}
827
851
828
852
// WithTransactionSource sets the source of the transaction name.
853
+ //
854
+ // Note: if the transaction source is not a valid source (as described
855
+ // by the spec https://develop.sentry.dev/sdk/event-payloads/transaction/#transaction-annotations),
856
+ // it will be corrected to "custom" eventually, before the transaction is sent.
829
857
func WithTransactionSource (source TransactionSource ) SpanOption {
830
858
return func (s * Span ) {
831
859
s .Source = source
0 commit comments