repositorypackage
1.0.1
Repository: https://github.com/scout-inc/scout-go.git
Documentation: pkg.go.dev
# Packages
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# README
scout-go
The official Go SDK for Scout. Read the docs at https://docs.getscout.dev/sdks/go/overview
Usage
Require package:
go get github.com/scout-inc/scout-go
In your entrypoint function:
import "github.com/scout-inc/scout-go"
func main() {
// some code
scout.Init(
scout.WithProjectID(SCOUT_PROJECT_ID)
)
defer scout.Stop()
// some code
}
Scout provides middleware for the more common Go server frameworks:
go-chi/chi
:
import (
"github.com/scout-inc/scout-go"
s "github.com/scout-inc/scout-go/middleware/chi"
)
func main() {
// some code
scout.Init(
scout.WithProjectID(SCOUT_PROJECT_ID)
)
defer scout.Stop()
r := chi.NewMux()
r.Use(s.Middleware)
// some code
}
gin-gonic/gin
:
import (
"github.com/scout-inc/scout-go"
s "github.com/scout-inc/scout-go/middleware/gin"
)
func main() {
// some code
scout.Init(
scout.WithProjectID(SCOUT_PROJECT_ID)
)
defer scout.Stop()
r := chi.NewMux()
r.Use(s.Middleware())
// some code
}
See https://docs.getscout.dev/sdks/go/frameworks for more examples.
To manually record an error:
import (
...
"go.opentelemetry.io/otel/attribute"
)
func LoginWithOAuth(ctx context.Context, email string) {
value, err := doSomething()
if err != nil {
// tags can be used to enrich errors and traces with additional information
errorTags := []attribute.KeyValue{
{
Key: attribute.Key("user.email"),
Value: attribute.StringValue(email)
}
}
scout.RecordError(ctx, err, errorTags...)
}
// some code
}