in tools/go-agent/instrument/reporter/instrument.go [63:112]
func (i *GRPCInstrument) WriteExtraFiles(dir string) ([]string, error) {
// copy reporter api files
results := make([]string, 0)
copiedFiles, err := tools.CopyGoFiles(core.FS, "reporter", dir, func(entry fs.DirEntry, f *dst.File) (*tools.DebugInfo, error) {
if i.compileOpts.DebugDir == "" {
return nil, nil
}
debugPath := filepath.Join(i.compileOpts.DebugDir, "plugins", "core", "reporter", entry.Name())
return tools.BuildDSTDebugInfo(debugPath, nil)
}, func(file *dst.File) {
})
if err != nil {
return nil, err
}
results = append(results, copiedFiles...)
// copy reporter implementations
// Force the use of '/' delimiter on all platforms
reporterDirName := strings.ReplaceAll(filepath.Join("reporter", "grpc"), `\`, `/`)
copiedFiles, err = tools.CopyGoFiles(core.FS, reporterDirName, dir, func(entry fs.DirEntry, f *dst.File) (*tools.DebugInfo, error) {
if i.compileOpts.DebugDir == "" {
return nil, nil
}
debugPath := filepath.Join(i.compileOpts.DebugDir, "plugins", "core", reporterDirName, entry.Name())
return tools.BuildDSTDebugInfo(debugPath, f)
}, func(file *dst.File) {
file.Name = dst.NewIdent("reporter")
pkgUpdates := make(map[string]string)
for _, p := range agentcore.CopiedSubPackages {
key := strings.ReplaceAll(filepath.Join(agentcore.EnhanceFromBasePackage, p), `\`, `/`)
val := strings.ReplaceAll(filepath.Join(agentcore.EnhanceBasePackage, p), `\`, `/`)
pkgUpdates[key] = val
}
tools.ChangePackageImportPath(file, pkgUpdates)
tools.DeletePackageImports(file, "github.com/apache/skywalking-go/plugins/core/reporter")
})
if err != nil {
return nil, err
}
results = append(results, copiedFiles...)
// generate the file for export the reporter
file, err := i.generateReporterInitFile(dir)
if err != nil {
return nil, err
}
results = append(results, file)
return results, nil
}