You've already forked sap-jenkins-library
mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-07-15 01:34:38 +02:00
feat(splunk) Sending telemetry and logging information to Splunk (#2796)
* Adds inital splunk hook and logCollector * Adds documentation of the Splunk hook * Fixes markdown lint issues and removes comment from telemetry.go file * Fixes markdown lint issues and adds missing generated file * Markdown linting * Changes documentation according to review, adds Splunk token automatically during init * Adds error handling for marshalling hook config * Markdown lint und correct Splunk token in httpclient * Registeres Splunk token as secret and adjusts test cases * Adds missing error handling and removes unnecessary comments * Creates new function readPipelineEnvironment, adds tests * Moves MonitoringData struct, edits defaults for json fields * Adds gitRepository and gitOwner to telemetry information * Simplifies readCommonPipelineEnvironment function, adds more descriptive errors, adds automated adding of Splunk prefix token * Adjusts error handling * Cleaner error logging
This commit is contained in:
@ -9,6 +9,7 @@ import (
|
||||
|
||||
"github.com/SAP/jenkins-library/pkg/config"
|
||||
"github.com/SAP/jenkins-library/pkg/log"
|
||||
"github.com/SAP/jenkins-library/pkg/splunk"
|
||||
"github.com/SAP/jenkins-library/pkg/telemetry"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
@ -31,6 +32,7 @@ func NpmExecuteScriptsCommand() *cobra.Command {
|
||||
metadata := npmExecuteScriptsMetadata()
|
||||
var stepConfig npmExecuteScriptsOptions
|
||||
var startTime time.Time
|
||||
var logCollector *log.CollectorHook
|
||||
|
||||
var createNpmExecuteScriptsCmd = &cobra.Command{
|
||||
Use: STEP_NAME,
|
||||
@ -56,6 +58,11 @@ func NpmExecuteScriptsCommand() *cobra.Command {
|
||||
log.RegisterHook(&sentryHook)
|
||||
}
|
||||
|
||||
if len(GeneralConfig.HookConfig.SplunkConfig.Dsn) > 0 {
|
||||
logCollector = &log.CollectorHook{CorrelationID: GeneralConfig.CorrelationID}
|
||||
log.RegisterHook(logCollector)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
Run: func(_ *cobra.Command, _ []string) {
|
||||
@ -66,10 +73,20 @@ func NpmExecuteScriptsCommand() *cobra.Command {
|
||||
telemetryData.Duration = fmt.Sprintf("%v", time.Since(startTime).Milliseconds())
|
||||
telemetryData.ErrorCategory = log.GetErrorCategory().String()
|
||||
telemetry.Send(&telemetryData)
|
||||
if len(GeneralConfig.HookConfig.SplunkConfig.Dsn) > 0 {
|
||||
splunk.Send(&telemetryData, logCollector)
|
||||
}
|
||||
}
|
||||
log.DeferExitHandler(handler)
|
||||
defer handler()
|
||||
telemetry.Initialize(GeneralConfig.NoTelemetry, STEP_NAME)
|
||||
if len(GeneralConfig.HookConfig.SplunkConfig.Dsn) > 0 {
|
||||
splunk.Initialize(GeneralConfig.CorrelationID,
|
||||
GeneralConfig.HookConfig.SplunkConfig.Dsn,
|
||||
GeneralConfig.HookConfig.SplunkConfig.Token,
|
||||
GeneralConfig.HookConfig.SplunkConfig.Index,
|
||||
GeneralConfig.HookConfig.SplunkConfig.SendLogs)
|
||||
}
|
||||
npmExecuteScripts(stepConfig, &telemetryData)
|
||||
telemetryData.ErrorCode = "0"
|
||||
log.Entry().Info("SUCCESS")
|
||||
|
Reference in New Issue
Block a user