highlight

package module
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 3, 2022 License: MIT Imports: 14 Imported by: 0

README

Go Report Card GoDoc codecov

highlight-go

Official implementation of the Highlight backend client in Go.

Usage

First, import the package

go get -u github.com/highlight-run/highlight-go

Then, add the following lines to your applications main function:

import (
	"github.com/highlight-run/highlight-go"
)

func main() {
	//...application logic...
	highlight.Start()
	defer highlight.Stop()
	//...application logic...
}

Then, use a highlight middleware in your apps router:

if you're using go-chi/chi:

import (
	highlightChi "github.com/highlight-run/highlight-go/middleware/chi"
)

func main() {
	//...
	r := chi.NewMux()
	r.Use(highlightChi.Middleware)
	//...
}

if you're using gin-gonic/gin:

import (
	highlightGin "github.com/highlight-run/highlight-go/middleware/gin"
)

func main() {
	//...
	r := gin.New()
	r.Use(highlightGin.Middleware())
	//...
}

Finally, it's time to consume errors. Add the following line to your error handling:

func someEndpoint() {
	err := someFuntionCall()
	if err != nil {
		highlight.ConsumeError(err)
		// including optional tags:
		highlight.ConsumeError(err, "environment:dev", "important")
	}
}

Documentation

Index

Constants

View Source
const (
	Highlight       contextKey = "highlight"
	RequestID                  = Highlight + "RequestID"
	SessionSecureID            = Highlight + "SessionSecureID"
)

Variables

View Source
var (
	ContextKeys = struct {
		RequestID       contextKey
		SessionSecureID contextKey
	}{
		RequestID:       RequestID,
		SessionSecureID: SessionSecureID,
	}
)

Functions

func ConsumeError

func ConsumeError(ctx context.Context, errorInput interface{}, tags ...string)

ConsumeError adds an error to the queue of errors to be sent to our backend. the provided context must have the injected highlight keys from InterceptRequestWithContext.

func InterceptRequest

func InterceptRequest(r *http.Request) context.Context

InterceptRequest calls InterceptRequestWithContext using the request object's context

func InterceptRequestWithContext

func InterceptRequestWithContext(ctx context.Context, r *http.Request) context.Context

InterceptRequestWithContext captures the highlight session and request ID for a particular request from the request headers, adding the values to the provided context.

func MarkBackendSetup added in v0.5.0

func MarkBackendSetup(ctx context.Context)

func RecordMetric added in v0.5.0

func RecordMetric(ctx context.Context, name string, value float64)

RecordMetric is used to record arbitrary metrics in your golang backend. Highlight will process these metrics in the context of your session and expose them through dashboards. For example, you may want to record the latency of a DB query as a metric that you would like to graph and monitor. You'll be able to view the metric in the context of the session and network request and recorded it.

func SetDebugMode added in v0.4.0

func SetDebugMode(l Logger)

func SetFlushInterval

func SetFlushInterval(newFlushInterval time.Duration)

SetFlushInterval allows you to override the amount of time in which the Highlight client will collect errors before sending them to our backend. - newFlushInterval is an integer representing seconds

func SetGraphqlClientAddress added in v0.3.0

func SetGraphqlClientAddress(newGraphqlClientAddress string)

SetGraphqlClientAddress allows you to override the graphql client address, in case you are running Highlight on-prem, and need to point to your on-prem instance.

func Start

func Start()

Start is used to start the Highlight client's collection service.

func StartWithContext added in v0.3.0

func StartWithContext(ctx context.Context)

StartWithContext is used to start the Highlight client's collection service, but allows the user to pass in their own context.Context. This allows the user kill the highlight worker by canceling their context.CancelFunc.

func Stop added in v0.3.0

func Stop()

Stop sends an interrupt signal to the main process, closing the channels and returning the goroutines.

Types

type BackendErrorObjectInput added in v0.3.0

type BackendErrorObjectInput struct {
	SessionSecureID graphql.String  `json:"session_secure_id"`
	RequestID       graphql.String  `json:"request_id"`
	Event           graphql.String  `json:"event"`
	Type            graphql.String  `json:"type"`
	URL             graphql.String  `json:"url"`
	Source          graphql.String  `json:"source"`
	StackTrace      graphql.String  `json:"stackTrace"`
	Timestamp       time.Time       `json:"timestamp"`
	Payload         *graphql.String `json:"payload"`
}

type GraphqlTracer added in v0.5.1

func NewGraphqlTracer added in v0.5.1

func NewGraphqlTracer(graphName string) GraphqlTracer

type Logger added in v0.4.0

type Logger interface {
	Error(v ...interface{})
	Errorf(format string, v ...interface{})
}

Logger is an interface that implements Log and Logf

type MetricInput added in v0.5.0

type MetricInput struct {
	SessionSecureID graphql.String  `json:"session_secure_id"`
	Group           *graphql.String `json:"group"`
	Name            graphql.String  `json:"name"`
	Value           graphql.Float   `json:"value"`
	Category        *graphql.String `json:"category"`
	Timestamp       time.Time       `json:"timestamp"`
}

type Requester added in v0.3.5

type Requester interface {
	// contains filtered or unexported methods
}

Requester is used for making graphql requests in testing, a mock requester with an overwritten trigger function may be used

type Tracer added in v0.5.1

type Tracer struct {
	// contains filtered or unexported fields
}

func (Tracer) ExtensionName added in v0.5.1

func (t Tracer) ExtensionName() string

func (Tracer) InterceptField added in v0.5.1

func (t Tracer) InterceptField(ctx context.Context, next graphql.Resolver) (interface{}, error)

InterceptField instruments timing of individual fields resolved.

func (Tracer) InterceptResponse added in v0.5.1

func (t Tracer) InterceptResponse(ctx context.Context, next graphql.ResponseHandler) *graphql.Response

InterceptResponse instruments timing, payload size, and error information of the response handler. The metric is grouped by the corresponding operation name.

func (Tracer) Validate added in v0.5.1

func (t Tracer) Validate(graphql.ExecutableSchema) error

Directories

Path Synopsis
middleware
chi
gin

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL