@@ -85,12 +85,40 @@ func (l *Listener) HandlerStarted(ctx context.Context, msg json.RawMessage) cont
85
85
serviceName = "aws.lambda"
86
86
}
87
87
extensionNotRunning := ! l .extensionManager .IsExtensionRunning ()
88
- opts := append ([]tracer.StartOption {
88
+
89
+ // Initialize base options
90
+ baseOpts := []tracer.StartOption {
89
91
tracer .WithService (serviceName ),
90
92
tracer .WithLambdaMode (extensionNotRunning ),
91
93
tracer .WithGlobalTag ("_dd.origin" , "lambda" ),
92
94
tracer .WithSendRetries (2 ),
93
- }, l .tracerOptions ... )
95
+ }
96
+
97
+ // Read sampling rules from environment
98
+ samplingRulesStr := os .Getenv ("DD_TRACE_SAMPLING_RULES" )
99
+ if samplingRulesStr != "" {
100
+ logger .Debug (fmt .Sprintf ("Found DD_TRACE_SAMPLING_RULES: %s" , samplingRulesStr ))
101
+ var rules []tracer.SamplingRule
102
+ if err := json .Unmarshal ([]byte (samplingRulesStr ), & rules ); err != nil {
103
+ logger .Error (fmt .Errorf ("Failed to parse DD_TRACE_SAMPLING_RULES: %v" , err ))
104
+ } else {
105
+ logger .Debug (fmt .Sprintf ("Successfully parsed %d sampling rules" , len (rules )))
106
+ // Convert the JSON rules to tracer.SamplingRule objects
107
+ var samplingRules []tracer.SamplingRule
108
+ for _ , rule := range rules {
109
+ if rate , ok := rule ["sample_rate" ].(float64 ); ok {
110
+ samplingRules = append (samplingRules , tracer .RateRule (rate ))
111
+ }
112
+ }
113
+ if len (samplingRules ) > 0 {
114
+ baseOpts = append (baseOpts , tracer .WithSamplingRules (samplingRules ))
115
+ }
116
+ }
117
+ }
118
+
119
+ // Merge base options with any user-provided options
120
+ opts := append (baseOpts , l .tracerOptions ... )
121
+
94
122
if l .otelTracerEnabled {
95
123
provider := ddotel .NewTracerProvider (
96
124
opts ... ,
0 commit comments