in tool/preprocess/preprocess.go [761:827]
func Preprocess() error {
// Make sure the project is modularized otherwise we cannot proceed
err := precheck()
if err != nil {
return err
}
dp := newDepProcessor()
err = dp.init()
if err != nil {
return err
}
defer func() { dp.postProcess() }()
{
defer util.PhaseTimer("Preprocess")()
// Backup go.mod and add additional repalce directives for the
// alibaba-otel pkg module
err = dp.rectifyMod()
if err != nil {
return err
}
// Add otel dependencies as part of the project dependencies
dp.newRuleImporter()
dp.runModTidy()
// Match rules based on the source files plus added otel imports
err = dp.matchRules()
if err != nil {
return err
}
// Add hook rule dependency as part of the project dependencies
dp.addRuleImporter()
// Update go.mod with the all additional dependencies
dp.runModTidy()
// Rectify file rules to make sure we can find them locally
err = dp.rectifyRule()
if err != nil {
return err
}
// From this point on, we no longer modify the rules
err = dp.storeRuleBundles()
if err != nil {
return err
}
// Retain otel rules and modified user files for debugging
dp.saveDebugFiles()
}
{
defer util.PhaseTimer("Instrument")()
// Run go build with toolexec to start instrumentation
err = runBuildWithToolexec(dp.goBuildCmd)
if err != nil {
return err
}
}
util.Log("Build completed successfully")
return nil
}