Skip to content

Commit 6d1fdd5

Browse files
authored
fix: remove request id header for explain API (#82)
1 parent ad847a7 commit 6d1fdd5

File tree

2 files changed

+6
-21
lines changed

2 files changed

+6
-21
lines changed

llm/api_client.go

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,18 @@ import (
77
"io"
88
"net/http"
99
"net/url"
10-
11-
"github.com/snyk/code-client-go/observability"
1210
)
1311

1412
var (
15-
completeStatus = "COMPLETE"
16-
failedToObtainRequestIdString = "Failed to obtain request id. "
17-
defaultEndpointURL = "http://localhost:10000/explain"
13+
completeStatus = "COMPLETE"
14+
defaultEndpointURL = "http://localhost:10000/explain"
1815
)
1916

2017
func (d *DeepCodeLLMBindingImpl) runExplain(ctx context.Context, options ExplainOptions) (Explanations, error) {
2118
span := d.instrumentor.StartSpan(ctx, "code.RunExplain")
2219
defer span.Finish()
2320

24-
requestId, err := observability.GetTraceId(ctx)
25-
logger := d.logger.With().Str("method", "code.RunExplain").Str("requestId", requestId).Logger()
26-
if err != nil {
27-
logger.Err(err).Msg(failedToObtainRequestIdString + err.Error())
28-
return Explanations{}, err
29-
}
21+
logger := d.logger.With().Str("method", "code.RunExplain").Logger()
3022

3123
logger.Debug().Msg("API: Retrieving explain for bundle")
3224
defer logger.Debug().Msg("API: Retrieving explain done")
@@ -52,7 +44,7 @@ func (d *DeepCodeLLMBindingImpl) runExplain(ctx context.Context, options Explain
5244
return Explanations{}, err
5345
}
5446

55-
d.addDefaultHeaders(req, requestId)
47+
d.addDefaultHeaders(req)
5648

5749
resp, err := d.httpClientFunc().Do(req) //nolint:bodyclose // this seems to be a false positive
5850
if err != nil {
@@ -111,8 +103,7 @@ func (d *DeepCodeLLMBindingImpl) explainRequestBody(options *ExplainOptions) ([]
111103
return requestBody, marshalErr
112104
}
113105

114-
func (d *DeepCodeLLMBindingImpl) addDefaultHeaders(req *http.Request, requestId string) {
115-
req.Header.Set("snyk-request-id", requestId)
106+
func (d *DeepCodeLLMBindingImpl) addDefaultHeaders(req *http.Request) {
116107
req.Header.Set("Cache-Control", "private, max-age=0, no-cache")
117108
req.Header.Set("Content-Type", "application/json")
118109
}

llm/api_client_test.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,19 +166,13 @@ func testLogger(t *testing.T) *zerolog.Logger {
166166
func TestAddDefaultHeadersWithExistingHeaders(t *testing.T) {
167167
d := &DeepCodeLLMBindingImpl{} // Initialize your struct if needed
168168
req := &http.Request{Header: http.Header{"Existing-Header": {"existing-value"}}}
169-
requestId := "test-request-id"
170169

171-
d.addDefaultHeaders(req, requestId)
170+
d.addDefaultHeaders(req)
172171

173-
snykRequestId := req.Header.Get("snyk-request-id")
174172
cacheControl := req.Header.Get("Cache-Control")
175173
contentType := req.Header.Get("Content-Type")
176174
existingHeader := req.Header.Get("Existing-Header")
177175

178-
if snykRequestId != requestId {
179-
t.Errorf("Expected snyk-request-id header to be %s, got %s", requestId, snykRequestId)
180-
}
181-
182176
if cacheControl != "private, max-age=0, no-cache" {
183177
t.Errorf("Expected Cache-Control header to be 'private, max-age=0, no-cache', got %s", cacheControl)
184178
}

0 commit comments

Comments
 (0)