Skip to content

Commit

Permalink
fix: Sending instrumentation data from VS and IntelliJ (#5287)
Browse files Browse the repository at this point in the history
* fix: Send all instrumentation data from report workflow

* chore: update gaf

* chore: update gaf

* chore: update final gaf version
  • Loading branch information
PeterSchafer authored Jun 5, 2024
1 parent f82b0e8 commit 58d4fc9
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 16 deletions.
2 changes: 1 addition & 1 deletion cliv2/cmd/cliv2/instrumentation.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func shallSendInstrumentation(config configuration.Configuration, instrumentor a
isSnykIde := utils.IsSnykIde(integration)
isReportCommand := strings.Contains(category, instrumentationCommand)

if isSnykIde && !isReportCommand {
if isSnykIde || isReportCommand {
return false
}

Expand Down
2 changes: 1 addition & 1 deletion cliv2/cmd/cliv2/instrumentation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ func Test_shallSendInstrumentation(t *testing.T) {
// case: analytics report command called from an IDE
instrumentor.SetCategory([]string{"analytics", "report", "inputData"})
actual = shallSendInstrumentation(config, instrumentor)
assert.True(t, actual)
assert.False(t, actual)
}
14 changes: 3 additions & 11 deletions cliv2/cmd/cliv2/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ func sendAnalytics(analytics analytics.Analytics, debugLogger *zerolog.Logger) {
func sendInstrumentation(eng workflow.Engine, instrumentor analytics.InstrumentationCollector, logger *zerolog.Logger) {
// Avoid duplicate data to be sent for IDE integrations that use the CLI
if !shallSendInstrumentation(eng.GetConfiguration(), instrumentor) {
logger.Print("Called from IDE, not sending instrumentation")
logger.Print("This CLI call is not instrumented!")
return
}

Expand All @@ -266,21 +266,13 @@ func sendInstrumentation(eng workflow.Engine, instrumentor analytics.Instrumenta
}

v2InstrumentationData := utils.ValueOf(json.Marshal(data))
logger.Trace().Msgf("Instrumentation: %v", string(v2InstrumentationData))

inputData := workflow.NewData(
workflow.NewTypeIdentifier(localworkflows.WORKFLOWID_REPORT_ANALYTICS, "reportAnalytics"),
"application/json",
v2InstrumentationData,
)

localConfiguration := globalConfiguration.Clone()
// the report analytics workflow needs --experimental to run
// we pass the flag here so that we report at every interaction
localConfiguration.Set(configuration.FLAG_EXPERIMENTAL, true)
_, err = eng.InvokeWithInputAndConfig(
localConfiguration.Set("inputData", string(v2InstrumentationData))
_, err = eng.InvokeWithConfig(
localworkflows.WORKFLOWID_REPORT_ANALYTICS,
[]workflow.Data{inputData},
localConfiguration,
)

Expand Down
2 changes: 1 addition & 1 deletion cliv2/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/snyk/cli-extension-sbom v0.0.0-20240523084359-a2830fadb001
github.com/snyk/container-cli v0.0.0-20240322120441-6d9b9482f9b1
github.com/snyk/error-catalog-golang-public v0.0.0-20240527112826-2b77438d25f1
github.com/snyk/go-application-framework v0.0.0-20240603174251-84f6ded78c8f
github.com/snyk/go-application-framework v0.0.0-20240605102342-67b064c1e417
github.com/snyk/go-httpauth v0.0.0-20240307114523-1f5ea3f55c65
github.com/snyk/snyk-iac-capture v0.6.5
github.com/snyk/snyk-ls v0.0.0-20240603144138-b7b4b7626a10
Expand Down
4 changes: 2 additions & 2 deletions cliv2/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -731,8 +731,8 @@ github.com/snyk/container-cli v0.0.0-20240322120441-6d9b9482f9b1 h1:9RKY9NdX5DrJ
github.com/snyk/container-cli v0.0.0-20240322120441-6d9b9482f9b1/go.mod h1:38w+dcAQp9eG3P5t2eNS9eG0reut10AeJjLv5lJ5lpM=
github.com/snyk/error-catalog-golang-public v0.0.0-20240527112826-2b77438d25f1 h1:49X/bTeiWdi+DrkTbTSw5BePpQ6LiucIt++/Z+MB95U=
github.com/snyk/error-catalog-golang-public v0.0.0-20240527112826-2b77438d25f1/go.mod h1:Ytttq7Pw4vOCu9NtRQaOeDU2dhBYUyNBe6kX4+nIIQ4=
github.com/snyk/go-application-framework v0.0.0-20240603174251-84f6ded78c8f h1:GucVC2OeSXfWVkHxZJ2xFRl2uXWk2YDl0SsF45HZt/Y=
github.com/snyk/go-application-framework v0.0.0-20240603174251-84f6ded78c8f/go.mod h1:1T6hnPUgT0lJPO0g3VjwvW0fCKDcgst8bgXs+wCfmW8=
github.com/snyk/go-application-framework v0.0.0-20240605102342-67b064c1e417 h1:piXelZOB/V+kfUGouG/nm6F2YKNCXH993bC0YqtW+gc=
github.com/snyk/go-application-framework v0.0.0-20240605102342-67b064c1e417/go.mod h1:1T6hnPUgT0lJPO0g3VjwvW0fCKDcgst8bgXs+wCfmW8=
github.com/snyk/go-httpauth v0.0.0-20240307114523-1f5ea3f55c65 h1:CEQuYv0Go6MEyRCD3YjLYM2u3Oxkx8GpCpFBd4rUTUk=
github.com/snyk/go-httpauth v0.0.0-20240307114523-1f5ea3f55c65/go.mod h1:88KbbvGYlmLgee4OcQ19yr0bNpXpOr2kciOthaSzCAg=
github.com/snyk/policy-engine v0.30.11 h1:wUy5LMar2vccMbNM62MSBRdjAQAhAbIm7aNXXO+g2tk=
Expand Down

0 comments on commit 58d4fc9

Please sign in to comment.