@@ -43,7 +43,7 @@ func (d *DeepCodeLLMBindingImpl) runExplain(ctx context.Context, options Explain
43
43
}
44
44
}
45
45
46
- responseBody , err := d .submitRequest (ctx , u , requestBody )
46
+ responseBody , err := d .submitRequest (span . Context () , u , requestBody , "" )
47
47
if err != nil {
48
48
return Explanations {}, err
49
49
}
@@ -62,17 +62,19 @@ func (d *DeepCodeLLMBindingImpl) runExplain(ctx context.Context, options Explain
62
62
return explains , nil
63
63
}
64
64
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 ) {
66
66
logger := d .logger .With ().Str ("method" , "submitRequest" ).Logger ()
67
67
logger .Trace ().Str ("payload body: %s\n " , string (requestBody )).Msg ("Marshaled payload" )
68
+ span := d .instrumentor .StartSpan (ctx , "code.SubmitRequest" )
69
+ defer span .Finish ()
68
70
69
71
req , err := http .NewRequestWithContext (ctx , http .MethodPost , url .String (), bytes .NewBuffer (requestBody ))
70
72
if err != nil {
71
73
logger .Err (err ).Str ("requestBody" , string (requestBody )).Msg ("error creating request" )
72
74
return nil , err
73
75
}
74
76
75
- d .addDefaultHeaders (req )
77
+ d .addDefaultHeaders (req , span . GetTraceId (), orgId )
76
78
77
79
resp , err := d .httpClientFunc ().Do (req ) //nolint:bodyclose // this seems to be a false positive
78
80
if err != nil {
@@ -123,11 +125,11 @@ func (d *DeepCodeLLMBindingImpl) explainRequestBody(options *ExplainOptions) ([]
123
125
124
126
var failed = AutofixStatus {Message : "FAILED" }
125
127
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 ) {
127
129
span := d .instrumentor .StartSpan (ctx , "code.RunAutofix" )
128
130
defer span .Finish ()
129
131
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 ()
131
133
132
134
endpoint , err := url .Parse (fmt .Sprintf ("%s/autofix/suggestions" , options .Host ))
133
135
if err != nil {
@@ -142,7 +144,7 @@ func (d *DeepCodeLLMBindingImpl) runAutofix(ctx context.Context, requestId strin
142
144
}
143
145
144
146
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 )
146
148
logger .Info ().Msg ("Finished obtaining autofix Response" )
147
149
148
150
if err != nil {
@@ -199,11 +201,11 @@ func (d *DeepCodeLLMBindingImpl) autofixRequestBody(options *AutofixOptions) ([]
199
201
return requestBody , err
200
202
}
201
203
202
- func (d * DeepCodeLLMBindingImpl ) submitAutofixFeedback (ctx context.Context , requestId string , options AutofixFeedbackOptions ) error {
204
+ func (d * DeepCodeLLMBindingImpl ) submitAutofixFeedback (ctx context.Context , options AutofixFeedbackOptions ) error {
203
205
span := d .instrumentor .StartSpan (ctx , "code.SubmitAutofixFeedback" )
204
206
defer span .Finish ()
205
207
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 ()
207
209
208
210
endpoint , err := url .Parse (fmt .Sprintf ("%s/autofix/event" , options .Host ))
209
211
if err != nil {
@@ -218,7 +220,7 @@ func (d *DeepCodeLLMBindingImpl) submitAutofixFeedback(ctx context.Context, requ
218
220
}
219
221
220
222
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 )
222
224
logger .Info ().Msg ("Finished obtaining autofix Response" )
223
225
224
226
return err
@@ -257,7 +259,14 @@ func prepareDiffs(diffs []string) []string {
257
259
return encodedDiffs
258
260
}
259
261
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
+ }
261
270
req .Header .Set ("Cache-Control" , "private, max-age=0, no-cache" )
262
271
req .Header .Set ("Content-Type" , "application/json" )
263
272
}
0 commit comments