Skip to content

Commit

Permalink
feat(instrumentation): add snyk-request-id header to interaction request
Browse files Browse the repository at this point in the history
  • Loading branch information
mgyorke committed May 17, 2024
1 parent 4c795e0 commit 0fe3ec8
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions cliv2/cmd/cliv2/main.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package main

// !!! This import needs to be the first import, please do not change this !!!
import _ "github.com/snyk/go-application-framework/pkg/networking/fips_enable"

import (
"context"
"encoding/json"
Expand All @@ -14,10 +12,8 @@ import (
"strings"
"time"

"github.com/hashicorp/go-uuid"
"github.com/rs/zerolog"
"github.com/spf13/cobra"
"github.com/spf13/pflag"

"github.com/snyk/cli-extension-dep-graph/pkg/depgraph"
"github.com/snyk/cli-extension-iac-rules/iacrules"
"github.com/snyk/cli-extension-sbom/pkg/sbom"
Expand All @@ -26,6 +22,10 @@ import (
"github.com/snyk/go-application-framework/pkg/app"
"github.com/snyk/go-application-framework/pkg/auth"
"github.com/snyk/go-application-framework/pkg/configuration"
_ "github.com/snyk/go-application-framework/pkg/networking/fips_enable"
"github.com/spf13/cobra"
"github.com/spf13/pflag"

localworkflows "github.com/snyk/go-application-framework/pkg/local_workflows"
"github.com/snyk/go-application-framework/pkg/local_workflows/content_type"
"github.com/snyk/go-application-framework/pkg/local_workflows/json_schemas"
Expand All @@ -35,12 +35,12 @@ import (
"github.com/snyk/go-application-framework/pkg/workflow"
"github.com/snyk/go-httpauth/pkg/httpauth"
"github.com/snyk/snyk-iac-capture/pkg/capture"
snykls "github.com/snyk/snyk-ls/ls_extension"

"github.com/snyk/go-application-framework/pkg/ui"

"github.com/snyk/cli/cliv2/internal/cliv2"
"github.com/snyk/cli/cliv2/internal/constants"
"github.com/snyk/go-application-framework/pkg/ui"
snykls "github.com/snyk/snyk-ls/ls_extension"

cli_errors "github.com/snyk/cli/cliv2/internal/errors"
"github.com/snyk/cli/cliv2/pkg/basic_workflows"
)
Expand Down Expand Up @@ -463,6 +463,15 @@ func MainWithErrorCode() int {
networking.UaWithOS(internalOS)).String(),
)

// Generate interaction UUID
interactionId, err := uuid.GenerateUUID()
if err != nil {
globalLogger.Print("Failed to generate interaction UUID!", err)
} else {
// Add interaction id to request header
networkAccess.AddHeaderField("snyk-request-id", interactionId)
}

if debugEnabled {
writeLogHeader(globalConfiguration, networkAccess)
}
Expand Down

0 comments on commit 0fe3ec8

Please sign in to comment.