feat(tracing): Implement Jaeger/OpenTracing provider with configuration options
- Added Punycode encoding implementation for cookie handling. - Introduced serialization for cookie jar with JSON support. - Created a comprehensive README for the tracing provider, detailing configuration and usage. - Developed a configuration structure for tracing, including sampler and reporter settings. - Implemented the provider logic to initialize Jaeger tracer with logging capabilities. - Ensured graceful shutdown of the tracer on application exit.
This commit is contained in:
@@ -1,43 +1,67 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"text/template"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
"github.com/iancoleman/strcase"
|
||||
"github.com/spf13/cobra"
|
||||
"go.ipao.vip/atomctl/v2/templates"
|
||||
"github.com/iancoleman/strcase"
|
||||
"github.com/spf13/cobra"
|
||||
"go.ipao.vip/atomctl/v2/templates"
|
||||
)
|
||||
|
||||
// CommandNewProvider 注册 new_provider 命令
|
||||
func CommandNewProvider(root *cobra.Command) {
|
||||
cmd := &cobra.Command{
|
||||
Use: "provider",
|
||||
Short: "创建新的 provider",
|
||||
Long: `在 providers/<name> 目录下渲染创建 Provider 模板。
|
||||
cmd := &cobra.Command{
|
||||
Use: "provider",
|
||||
Short: "创建新的 provider",
|
||||
Long: `在 providers/<name> 目录下渲染创建 Provider 模板。
|
||||
|
||||
行为:
|
||||
- 从内置模板 templates/provider 渲染相关文件
|
||||
- 当 name 与内置预置目录同名时,渲染该目录;否则回退渲染 providers/default
|
||||
- 从内置模板 templates/providers 渲染相关文件
|
||||
- 使用 name 的 CamelCase 作为导出名
|
||||
- --dry-run 仅打印渲染与写入动作;--dir 指定输出基目录(默认 .)
|
||||
|
||||
不带名称直接运行时,将列出可用预置 provider 列表供选择。
|
||||
|
||||
示例:
|
||||
atomctl new provider email
|
||||
atomctl new --dry-run --dir ./demo provider cache`,
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: commandNewProviderE,
|
||||
}
|
||||
Args: cobra.MaximumNArgs(1),
|
||||
RunE: commandNewProviderE,
|
||||
}
|
||||
|
||||
root.AddCommand(cmd)
|
||||
}
|
||||
|
||||
func commandNewProviderE(cmd *cobra.Command, args []string) error {
|
||||
providerName := args[0]
|
||||
// no-arg: list available preset providers
|
||||
if len(args) == 0 {
|
||||
entries, err := templates.Providers.ReadDir("providers")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var names []string
|
||||
for _, e := range entries {
|
||||
if e.IsDir() {
|
||||
names = append(names, e.Name())
|
||||
}
|
||||
}
|
||||
sort.Strings(names)
|
||||
fmt.Println("可用预置 providers:")
|
||||
for _, n := range names {
|
||||
fmt.Printf(" - %s\n", n)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
providerName := args[0]
|
||||
// shared flags
|
||||
dryRun, _ := cmd.Flags().GetBool("dry-run")
|
||||
baseDir, _ := cmd.Flags().GetString("dir")
|
||||
@@ -56,32 +80,38 @@ func commandNewProviderE(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
}
|
||||
|
||||
err := fs.WalkDir(templates.Provider, "provider", func(path string, d fs.DirEntry, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if d.IsDir() {
|
||||
return nil
|
||||
}
|
||||
// choose template source: providers/<name> or providers/default
|
||||
srcDir := filepath.Join("providers", providerName)
|
||||
if _, err := templates.Providers.ReadDir(srcDir); err != nil {
|
||||
srcDir = filepath.Join("providers", "default")
|
||||
}
|
||||
|
||||
relPath, err := filepath.Rel("provider", path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err := fs.WalkDir(templates.Providers, srcDir, func(path string, d fs.DirEntry, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if d.IsDir() {
|
||||
return nil
|
||||
}
|
||||
|
||||
destPath := filepath.Join(targetPath, strings.TrimSuffix(relPath, ".tpl"))
|
||||
if dryRun {
|
||||
fmt.Printf("[dry-run] mkdir -p %s\n", filepath.Dir(destPath))
|
||||
} else {
|
||||
if err := os.MkdirAll(filepath.Dir(destPath), os.ModePerm); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
relPath, err := filepath.Rel(srcDir, path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
tmpl, err := template.ParseFS(templates.Provider, path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
destPath := filepath.Join(targetPath, strings.TrimSuffix(relPath, ".tpl"))
|
||||
if dryRun {
|
||||
fmt.Printf("[dry-run] mkdir -p %s\n", filepath.Dir(destPath))
|
||||
} else {
|
||||
if err := os.MkdirAll(filepath.Dir(destPath), os.ModePerm); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
tmpl, err := template.ParseFS(templates.Providers, path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if dryRun {
|
||||
fmt.Printf("[dry-run] render > %s\n", destPath)
|
||||
|
||||
Reference in New Issue
Block a user