Skip to content
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,11 @@ $RECYCLE.BIN/
*.lnk

# End of https://www.toptal.com/developers/gitignore/api/go,visualstudiocode,osx,linux,windows

### Additional IDEs/Editors. ###
/.idea/
/*.iml

/.vimrc
*.swp
*.tmp
13 changes: 7 additions & 6 deletions inits.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ var now = time.Now()

func startAPM(ctx context.Context, cfg *configs.Configs) *apm.APM {
ap, err := apm.New(ctx, &apm.Options{
Debug: cfg.Environment == configs.EnvLocal,
Environment: cfg.Environment.String(),
ServiceName: cfg.AppName,
ServiceVersion: cfg.AppVersion,
TracesSampleRate: 50.00,
UseStdOut: cfg.Environment == configs.EnvLocal,
Debug: cfg.Environment == configs.EnvLocal,
Environment: cfg.Environment.String(),
ServiceName: cfg.AppName,
ServiceVersion: cfg.AppVersion,
PrometheusScrapePort: 9090,
TracesSampleRate: 50.00,
UseStdOut: cfg.Environment == configs.EnvLocal,
})
if err != nil {
panic(errors.Wrap(err, "failed to start APM"))
Expand Down
12 changes: 8 additions & 4 deletions internal/pkg/apm/apm.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func New(ctx context.Context, opts *Options) (*APM, error) {
s.meterProvider = mProvider
SetGlobal(s)

return s, nil
return Global(), nil
}

// Shutdown gracefully switch off apm, flushing any data it have
Expand Down Expand Up @@ -140,9 +140,9 @@ func SetGlobal(apm *APM) {
// Global gets global apm instance
func Global() *APM {
if global == nil {
apm, _ := New(context.Background(), &Options{UseStdOut: false})
global = apm
return apm
message := "Attempt to use APM before it's been initialised."
fmt.Printf(message)
panic(message)
Comment thread
bnkamalesh marked this conversation as resolved.
Outdated
}
return global
}
Expand Down Expand Up @@ -187,6 +187,10 @@ func newTracer(ctx context.Context, opts *Options) (trace.TracerProvider, *Trace

if opts.UseStdOut {
exporter, err = stdouttrace.New()
} else if opts.CollectorURL == "" {
fmt.Printf("Using no-op tracer as CollectorURL is not set.")
Comment thread
bnkamalesh marked this conversation as resolved.
Outdated
s.tracerProvider = nil
s.appTracer = nil
} else if httpCollector {
exporter, err = otlptracehttp.New(
ctx,
Expand Down
16 changes: 3 additions & 13 deletions internal/pkg/apm/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,10 @@ func prometheusScraper(opts *Options) {
ReadHeaderTimeout: 5 * time.Second,
}

// logger.Info(
// "[otel/http] starting prometheus scrape endpoint",
// zap.String(
// "addr",
// fmt.Sprintf("localhost:%d/-/metrics", opts.PrometheusScrapePort),
// ),
// )
fmt.Printf("[otel/http] starting prometheus metrics on :%d/-/metrics", opts.PrometheusScrapePort)
Comment thread
bnkamalesh marked this conversation as resolved.
Outdated
err := server.ListenAndServe()
if err != nil {
// logger.Error(
// "[otel/http] failed to serve metrics at:",
// zap.Error(err),
// zap.Uint16("port", opts.PrometheusScrapePort),
// )
return
fmt.Printf("[otel/http] failed to start prometheus metrics on :%d/-/metrics ; %+v", opts.PrometheusScrapePort, err)
panic(err)
Comment thread
bnkamalesh marked this conversation as resolved.
Outdated
}
}
3 changes: 2 additions & 1 deletion internal/pkg/sysignals/sysignals.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ func NotifyErrorOnQuit(errs chan<- error, otherSignals ...syscall.Signal) {

for signalType := range interrupt {
switch signalType {
case syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGTSTP:
// syscall.SIGTSTP not supported on Windows.
Comment thread
bnkamalesh marked this conversation as resolved.
Outdated
case syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT/*, syscall.SIGTSTP*/:
errs <- errors.Wrapf(ErrSigQuit, "%v", signalType)
return
}
Expand Down
9 changes: 8 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ func main() {
}),
)

ap := startAPM(ctx, cfgs)mesg
if ap == nil {
message := "Failed to start APM!"
fmt.Printf(message)
panic(message)
Comment thread
bnkamalesh marked this conversation as resolved.
Outdated
}

healthResponder, err := startHealthResponder(ctx, probestatus, fatalErr)
if err != nil {
panic(err)
Expand All @@ -93,7 +100,7 @@ func main() {
healthResponder,
hserver,
gserver,
startAPM(ctx, cfgs),
ap,
)
exitErr = <-fatalErr
}