@@ -43,7 +43,7 @@ func (d *DeepCodeLLMBindingImpl) runExplain(ctx context.Context, options Explain
4343 }
4444 }
4545
46- responseBody , err := d .submitRequest (ctx , u , requestBody )
46+ responseBody , err := d .submitRequest (span . Context () , u , requestBody , "" )
4747 if err != nil {
4848 return Explanations {}, err
4949 }
@@ -62,17 +62,19 @@ func (d *DeepCodeLLMBindingImpl) runExplain(ctx context.Context, options Explain
6262 return explains , nil
6363}
6464
65- func (d * DeepCodeLLMBindingImpl ) submitRequest (ctx context.Context , url * url.URL , requestBody []byte ) ([]byte , error ) {
65+ func (d * DeepCodeLLMBindingImpl ) submitRequest (ctx context.Context , url * url.URL , requestBody []byte , orgId string ) ([]byte , error ) {
6666 logger := d .logger .With ().Str ("method" , "submitRequest" ).Logger ()
6767 logger .Trace ().Str ("payload body: %s\n " , string (requestBody )).Msg ("Marshaled payload" )
68+ span := d .instrumentor .StartSpan (ctx , "code.SubmitRequest" )
69+ defer span .Finish ()
6870
6971 req , err := http .NewRequestWithContext (ctx , http .MethodPost , url .String (), bytes .NewBuffer (requestBody ))
7072 if err != nil {
7173 logger .Err (err ).Str ("requestBody" , string (requestBody )).Msg ("error creating request" )
7274 return nil , err
7375 }
7476
75- d .addDefaultHeaders (req )
77+ d .addDefaultHeaders (req , span . GetTraceId (), orgId )
7678
7779 resp , err := d .httpClientFunc ().Do (req ) //nolint:bodyclose // this seems to be a false positive
7880 if err != nil {
@@ -123,11 +125,11 @@ func (d *DeepCodeLLMBindingImpl) explainRequestBody(options *ExplainOptions) ([]
123125
124126var failed = AutofixStatus {Message : "FAILED" }
125127
126- func (d * DeepCodeLLMBindingImpl ) runAutofix (ctx context.Context , requestId string , options AutofixOptions ) (AutofixResponse , AutofixStatus , error ) {
128+ func (d * DeepCodeLLMBindingImpl ) runAutofix (ctx context.Context , options AutofixOptions ) (AutofixResponse , AutofixStatus , error ) {
127129 span := d .instrumentor .StartSpan (ctx , "code.RunAutofix" )
128130 defer span .Finish ()
129131
130- logger := d .logger .With ().Str ("method" , "code.RunAutofix" ).Str ("requestId" , requestId ).Logger ()
132+ logger := d .logger .With ().Str ("method" , "code.RunAutofix" ).Str ("requestId" , span . GetTraceId () ).Logger ()
131133
132134 endpoint , err := url .Parse (fmt .Sprintf ("%s/autofix/suggestions" , options .Host ))
133135 if err != nil {
@@ -142,7 +144,7 @@ func (d *DeepCodeLLMBindingImpl) runAutofix(ctx context.Context, requestId strin
142144 }
143145
144146 logger .Info ().Msg ("Started obtaining autofix Response" )
145- responseBody , err := d .submitRequest (ctx , endpoint , requestBody )
147+ responseBody , err := d .submitRequest (span . Context () , endpoint , requestBody , options . CodeRequestContext . Org . PublicId )
146148 logger .Info ().Msg ("Finished obtaining autofix Response" )
147149
148150 if err != nil {
@@ -199,11 +201,11 @@ func (d *DeepCodeLLMBindingImpl) autofixRequestBody(options *AutofixOptions) ([]
199201 return requestBody , err
200202}
201203
202- func (d * DeepCodeLLMBindingImpl ) submitAutofixFeedback (ctx context.Context , requestId string , options AutofixFeedbackOptions ) error {
204+ func (d * DeepCodeLLMBindingImpl ) submitAutofixFeedback (ctx context.Context , options AutofixFeedbackOptions ) error {
203205 span := d .instrumentor .StartSpan (ctx , "code.SubmitAutofixFeedback" )
204206 defer span .Finish ()
205207
206- logger := d .logger .With ().Str ("method" , "code.SubmitAutofixFeedback" ).Str ("requestId" , requestId ).Logger ()
208+ logger := d .logger .With ().Str ("method" , "code.SubmitAutofixFeedback" ).Str ("requestId" , span . GetTraceId () ).Logger ()
207209
208210 endpoint , err := url .Parse (fmt .Sprintf ("%s/autofix/event" , options .Host ))
209211 if err != nil {
@@ -218,7 +220,7 @@ func (d *DeepCodeLLMBindingImpl) submitAutofixFeedback(ctx context.Context, requ
218220 }
219221
220222 logger .Info ().Msg ("Started obtaining autofix Response" )
221- _ , err = d .submitRequest (ctx , endpoint , requestBody )
223+ _ , err = d .submitRequest (span . Context () , endpoint , requestBody , options . CodeRequestContext . Org . PublicId )
222224 logger .Info ().Msg ("Finished obtaining autofix Response" )
223225
224226 return err
@@ -257,7 +259,14 @@ func prepareDiffs(diffs []string) []string {
257259 return encodedDiffs
258260}
259261
260- func (d * DeepCodeLLMBindingImpl ) addDefaultHeaders (req * http.Request ) {
262+ func (d * DeepCodeLLMBindingImpl ) addDefaultHeaders (req * http.Request , requestId string , orgId string ) {
263+ // if requestId is empty it will be enriched from the Gateway
264+ if len (requestId ) > 0 {
265+ req .Header .Set ("snyk-request-id" , requestId )
266+ }
267+ if len (orgId ) > 0 {
268+ req .Header .Set ("snyk-org-name" , orgId )
269+ }
261270 req .Header .Set ("Cache-Control" , "private, max-age=0, no-cache" )
262271 req .Header .Set ("Content-Type" , "application/json" )
263272}
0 commit comments