-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Franco Ferraguti
committed
Oct 25, 2023
1 parent
9d732d3
commit ba51632
Showing
11 changed files
with
352 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,3 +21,6 @@ | |
|
||
# Data generated by Prometheus (I think?) | ||
data/ | ||
|
||
# MacOS | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package middleware | ||
|
||
import "github.com/sirupsen/logrus" | ||
|
||
type LoggerI interface { | ||
Info(args ...interface{}) | ||
Warn(args ...interface{}) | ||
Error(args ...interface{}) | ||
Fatalf(format string, args ...interface{}) | ||
} | ||
|
||
func NewLogger() LoggerI { | ||
logger := logrus.New() | ||
logger.SetFormatter(&logrus.JSONFormatter{}) | ||
logger.SetLevel(logrus.InfoLevel) | ||
return logger | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package middleware | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/gilperopiola/go-rest-example/pkg/common/config" | ||
"github.com/gin-gonic/gin" | ||
|
||
"github.com/newrelic/go-agent/v3/integrations/nrgin" | ||
"github.com/newrelic/go-agent/v3/newrelic" | ||
) | ||
|
||
func NewNewRelicMiddleware(app *newrelic.Application) gin.HandlerFunc { | ||
return nrgin.Middleware(app) | ||
} | ||
|
||
func NewMonitoringNewRelic(config config.Monitoring) *newrelic.Application { | ||
|
||
// If monitoring is not enabled, return empty middleware | ||
if !config.Enabled { | ||
return nil | ||
} | ||
|
||
// If monitoring is enabled, use license to create New Relic app | ||
license := config.Secret | ||
if license == "" { | ||
log.Fatalf("New Relic license not found") | ||
} | ||
|
||
// Create app | ||
newRelicApp, err := newrelic.NewApplication( | ||
newrelic.ConfigAppName(config.AppName), | ||
newrelic.ConfigLicense(license), | ||
newrelic.ConfigAppLogForwardingEnabled(true), | ||
) | ||
|
||
// Panic on failure | ||
if err != nil { | ||
log.Fatalf("Failed to start New Relic: %v", err) | ||
} | ||
|
||
return newRelicApp | ||
} |
Oops, something went wrong.