MCPcopy Create free account
hub / github.com/subtrace/subtrace / entrypoint

Method entrypoint

cmd/proxy/proxy.go:82–177  ·  view source on GitHub ↗
(ctx context.Context, args []string)

Source from the content-addressed store, hash-verified

80}
81
82func (c *Command) entrypoint(ctx context.Context, args []string) error {
83 if err := logging.Init(); err != nil {
84 return fmt.Errorf("init logging: %w", err)
85 }
86
87 slog.Debug("starting subtrace proxy", "release", version.Release, slog.Group("commit", "hash", version.CommitHash, "time", version.CommitTime), "build", version.BuildTime)
88
89 if len(args) == 0 {
90 fmt.Fprintf(os.Stderr, "error: missing FROM:TO port numbers\n")
91 return flag.ErrHelp
92 }
93
94 from, to, ok := strings.Cut(args[0], ":")
95 if !ok {
96 fmt.Fprintf(os.Stderr, "error: invalid FROM:TO port format\n")
97 return flag.ErrHelp
98 }
99
100 var err error
101 if c.from, err = strconv.Atoi(from); err != nil {
102 fmt.Fprintf(os.Stderr, "error: invalid FROM port: parse as number: %v\n", err)
103 return flag.ErrHelp
104 }
105 if c.to, err = strconv.Atoi(to); err != nil {
106 fmt.Fprintf(os.Stderr, "error: invalid FROM port: parse as number: %v\n", err)
107 return flag.ErrHelp
108 }
109
110 c.global = new(global.Global)
111
112 if c.flags.log == nil {
113 c.flags.log = new(bool)
114 if os.Getenv("SUBTRACE_TOKEN") == "" {
115 *c.flags.log = true
116 } else {
117 *c.flags.log = false
118 }
119 } else if *c.flags.log == false && os.Getenv("SUBTRACE_TOKEN") == "" {
120 exists := false
121 for _, arg := range os.Args {
122 if strings.Contains(arg, "-log") {
123 exists = true
124 break
125 }
126 if arg == "--" {
127 break
128 }
129 }
130
131 if exists {
132 slog.Warn("subtrace proxy was started with -log=false but SUBTRACE_TOKEN is empty")
133 }
134 }
135
136 tracer.DefaultManager.SetLog(*c.flags.log)
137
138 if os.Getenv("SUBTRACE_TOKEN") != "" && os.Getenv("SUBTRACE_LINK_ID_OVERRIDE") != "" {
139 slog.Debug("SUBTRACE_LINK_ID_OVERRIDE is ignored when SUBTRACE_TOKEN is set")

Callers

nothing calls this directly

Calls 9

startMethod · 0.95
InitFunction · 0.92
NewFunction · 0.92
NewServerFunction · 0.92
SetLogMethod · 0.80
LoopMethod · 0.80
StartBackgroundFlushMethod · 0.80
LoadMethod · 0.80
FlushMethod · 0.45

Tested by

no test coverage detected