@@ -63,7 +63,7 @@ func RunServer(config *myconfig.ServerConfig, version string) error {
6363 return err
6464 }
6565 if config .Telemetry .Enabled {
66- oltpShutdown , err := initProviders (config , version )
66+ oltpShutdown , err := initProviders (config , version , config . Telemetry . ExtraMetrics )
6767 if err != nil {
6868 return err
6969 }
@@ -82,15 +82,25 @@ func RunServer(config *myconfig.ServerConfig, version string) error {
8282 router .HandleFunc ("/api/" , service .WelcomeMsg ).Methods (http .MethodGet )
8383 router .HandleFunc ("/api/" , service .HeadResponse ).Methods (http .MethodHead )
8484 router .HandleFunc ("/api/health" , service .HealthCheck ).Methods (http .MethodGet )
85+ router .HandleFunc ("/health" , service .HealthCheck ).Methods (http .MethodGet )
8586 router .HandleFunc ("/api/health" , service .HeadResponse ).Methods (http .MethodHead )
87+ router .HandleFunc ("/health" , service .HeadResponse ).Methods (http .MethodHead )
8688 router .HandleFunc ("/api/health-check" , service .HealthCheck ).Methods (http .MethodGet )
89+ router .HandleFunc ("/health-check" , service .HealthCheck ).Methods (http .MethodGet )
8790 router .HandleFunc ("/api/health-check" , service .HeadResponse ).Methods (http .MethodHead )
91+ router .HandleFunc ("/health-check" , service .HeadResponse ).Methods (http .MethodHead )
8892 router .HandleFunc ("/api/metrics/{type}" , service .MetricsHandler ).Methods (http .MethodGet )
93+ router .HandleFunc ("/metrics/{type}" , service .MetricsHandler ).Methods (http .MethodGet )
8994 router .HandleFunc ("/api/file_contents/{md5}" , apiService .FileContents ).Methods (http .MethodGet )
95+ router .HandleFunc ("/file_contents/{md5}" , apiService .FileContents ).Methods (http .MethodGet )
9096 router .HandleFunc ("/api/kb/details" , apiService .KBDetails ).Methods (http .MethodGet )
97+ router .HandleFunc ("/kb/details" , apiService .KBDetails ).Methods (http .MethodGet )
9198 router .HandleFunc ("/api/license/obligations/{license}" , apiService .LicenseDetails ).Methods (http .MethodGet )
99+ router .HandleFunc ("/license/obligations/{license}" , apiService .LicenseDetails ).Methods (http .MethodGet )
92100 router .HandleFunc ("/api/scan/direct" , apiService .ScanDirect ).Methods (http .MethodPost )
101+ router .HandleFunc ("/scan/direct" , apiService .ScanDirect ).Methods (http .MethodPost )
93102 router .HandleFunc ("/api/sbom/attribution" , apiService .SbomAttribution ).Methods (http .MethodPost )
103+ router .HandleFunc ("/sbom/attribution" , apiService .SbomAttribution ).Methods (http .MethodPost )
94104 // Setup Open Telemetry (OTEL)
95105 if config .Telemetry .Enabled {
96106 router .Use (otelmux .Middleware ("scanoss-api" ))
@@ -309,22 +319,26 @@ func loadFiltering(config *myconfig.ServerConfig) ([]string, []string, error) {
309319}
310320
311321// initProviders sets up the OLTP Meter and Trace providers and the OLTP gRPC exporter.
312- func initProviders (config * myconfig.ServerConfig , version string ) (func (), error ) {
322+ func initProviders (config * myconfig.ServerConfig , version string , extraAttributes bool ) (func (), error ) {
313323 zlog .L .Info ("Setting up Open Telemetry providers." )
314324 // Setup resource for the providers
315325 ctx := context .Background ()
316- res , err := resource .New (ctx ,
317- resource .WithFromEnv (),
318- resource .WithProcess (),
319- resource .WithTelemetrySDK (),
320- resource .WithHost (),
321- resource .WithAttributes (
322- // the service name & version used to display traces in backends
323- semconv .ServiceName (config .App .Name ),
324- semconv .ServiceNamespace ("scanoss-api" ),
325- semconv .ServiceVersion (strings .TrimSpace (version )),
326- ),
326+ var opts []resource.Option
327+ // Extra service level attributes to report
328+ if extraAttributes {
329+ opts = append (opts , resource .WithFromEnv ())
330+ opts = append (opts , resource .WithProcess ())
331+ opts = append (opts , resource .WithTelemetrySDK ())
332+ }
333+ opts = append (opts , resource .WithHost ())
334+ // the service name & version used to display traces in backends
335+ opts = append (opts , resource .WithAttributes (
336+ semconv .ServiceName (config .App .Name ),
337+ semconv .ServiceNamespace ("scanoss-api" ),
338+ semconv .ServiceVersion (strings .TrimSpace (version )),
339+ ),
327340 )
341+ res , err := resource .New (ctx , opts ... )
328342 if err != nil {
329343 zlog .S .Errorf ("Failed to create oltp resource: %v" , err )
330344 return nil , err
0 commit comments