@@ -28,10 +28,9 @@ import (
2828 "net/url"
2929 "strings"
3030
31- "github.com/snyk/code-client-go/scan"
32-
3331 codeClientHTTP "github.com/snyk/code-client-go/http"
3432 "github.com/snyk/code-client-go/sarif"
33+ "github.com/snyk/code-client-go/scan"
3534)
3635
3736// Legacy analysis types and constants
@@ -76,15 +75,21 @@ type FailedError struct {
7675func (e FailedError ) Error () string { return e .Msg }
7776
7877// Legacy analysis helper functions
79- func (a * analysisOrchestrator ) newRequestContext () requestContext {
78+ func (a * analysisOrchestrator ) newRequestContext (ctx context. Context ) requestContext {
8079 unknown := "unknown"
8180 orgId := unknown
8281 if a .config .Organization () != "" {
8382 orgId = a .config .Organization ()
8483 }
8584
85+ initiator := unknown
86+ contextInitiator , ok := scan .ScanSourceFromContext (ctx )
87+ if ok {
88+ initiator = string (contextInitiator )
89+ }
90+
8691 return requestContext {
87- Initiator : "IDE" ,
92+ Initiator : initiator ,
8893 Flow : "language-server" ,
8994 Org : requestContextOrg {
9095 Name : unknown ,
@@ -94,15 +99,15 @@ func (a *analysisOrchestrator) newRequestContext() requestContext {
9499 }
95100}
96101
97- func (a * analysisOrchestrator ) createRequestBody (bundleHash , shardKey string , limitToFiles []string , severity int ) ([]byte , error ) {
102+ func (a * analysisOrchestrator ) createRequestBody (ctx context. Context , bundleHash , shardKey string , limitToFiles []string , severity int ) ([]byte , error ) {
98103 request := Request {
99104 Key : RequestKey {
100105 Type : "file" ,
101106 Hash : bundleHash ,
102107 LimitToFiles : limitToFiles ,
103108 },
104109 Legacy : false ,
105- AnalysisContext : a .newRequestContext (),
110+ AnalysisContext : a .newRequestContext (ctx ),
106111 }
107112 if len (shardKey ) > 0 {
108113 request .Key .Shard = shardKey
@@ -144,7 +149,7 @@ func (a *analysisOrchestrator) RunLegacyTest(ctx context.Context, bundleHash str
144149 a .logger .Debug ().Str ("method" , method ).Str ("bundleHash" , bundleHash ).Msg ("API: Retrieving analysis for bundle" )
145150 defer a .logger .Debug ().Str ("method" , method ).Str ("bundleHash" , bundleHash ).Msg ("API: Retrieving analysis done" )
146151
147- requestBody , err := a .createRequestBody (bundleHash , shardKey , limitToFiles , severity )
152+ requestBody , err := a .createRequestBody (ctx , bundleHash , shardKey , limitToFiles , severity )
148153 if err != nil {
149154 a .logger .Err (err ).Str ("method" , method ).Str ("requestBody" , string (requestBody )).Msg ("error creating request body" )
150155 return nil , scan.LegacyScanStatus {}, err
@@ -158,12 +163,13 @@ func (a *analysisOrchestrator) RunLegacyTest(ctx context.Context, bundleHash str
158163
159164 // Create HTTP request
160165 analysisUrl := baseUrl + "/analysis"
161- req , err := http .NewRequestWithContext (span .Context (), http .MethodPost , analysisUrl , bytes .NewBuffer (requestBody ))
166+ httpMethod := http .MethodPost
167+ req , err := http .NewRequestWithContext (span .Context (), httpMethod , analysisUrl , bytes .NewBuffer (requestBody ))
162168 if err != nil {
163169 a .logger .Err (err ).Str ("method" , method ).Msg ("error creating HTTP request" )
164170 return nil , scan.LegacyScanStatus {}, err
165171 }
166- codeClientHTTP .AddDefaultHeaders (req , span .GetTraceId (), a .config .Organization ())
172+ codeClientHTTP .AddDefaultHeaders (req , span .GetTraceId (), a .config .Organization (), httpMethod )
167173
168174 // Make HTTP call
169175 resp , err := a .httpClient .Do (req )
0 commit comments