highlight

package module
v0.10.2 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2024 License: MIT Imports: 24 Imported by: 30

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/highlight/sdk/highlight-go

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

import (
	"github.com/highlight/highlight/sdk/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/highlight/sdk/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/highlight/sdk/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"
)
View Source
const DeprecatedProjectIDAttribute = "highlight_project_id"
View Source
const DeprecatedRequestIDAttribute = "highlight_trace_id"
View Source
const DeprecatedSessionIDAttribute = "highlight_session_id"
View Source
const DeprecatedSourceAttribute = "Source"
View Source
const ErrorURLAttribute = "URL"
View Source
const LogEvent = "log"
View Source
const LogMessageAttribute = "log.message"
View Source
const LogSeverityAttribute = "log.severity"
View Source
const MetricEvent = "metric"
View Source
const MetricEventName = "metric.name"
View Source
const MetricEventValue = "metric.value"
View Source
const OTLPDefaultEndpoint = "https://otel.highlight.io:4318"
View Source
const ProjectIDAttribute = "highlight.project_id"
View Source
const RequestIDAttribute = "highlight.trace_id"
View Source
const SessionIDAttribute = "highlight.session_id"
View Source
const SourceAttribute = "highlight.source"
View Source
const TraceKeyAttribute = "highlight.key"
View Source
const TraceTypeAttribute = "highlight.type"

Variables

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

Functions

func EndTrace added in v0.8.7

func EndTrace(span trace.Span)

func GetMetricSamplingRate added in v0.10.1

func GetMetricSamplingRate() float64

func GetProjectID added in v0.9.3

func GetProjectID() string

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 IsRunning added in v0.9.5

func IsRunning() bool

func RecordError

func RecordError(ctx context.Context, err error, tags ...attribute.KeyValue) context.Context

RecordError processes `err` to be recorded as a part of the session or network request. Highlight session and trace are inferred from the context. If no sessionID is set, then the error is associated with the project without a session context.

func RecordMetric

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

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 RecordSpanError added in v0.8.7

func RecordSpanError(span trace.Span, err error, tags ...attribute.KeyValue)

func RecordSpanErrorWithStack added in v0.8.9

func RecordSpanErrorWithStack(span trace.Span, err ErrorWithStack)

func SetDebugMode

func SetDebugMode(l Logger)

func SetFlushInterval

func SetFlushInterval(_ 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 Deprecated - this is managed by the opentelemetry SDK.

func SetOTLPEndpoint

func SetOTLPEndpoint(newOtlpEndpoint string)

SetOTLPEndpoint allows you to override the otlp address used for sending errors and traces. Use the root http url. Eg: https://otel.highlight.io:4318

func SetProjectID

func SetProjectID(id string)

func Start

func Start(opts ...Option)

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

func StartTrace

func StartTrace(ctx context.Context, name string, tags ...attribute.KeyValue) (trace.Span, context.Context)

func StartTraceWithTimestamp added in v0.9.13

func StartTraceWithTimestamp(ctx context.Context, name string, t time.Time, opts []trace.SpanStartOption, tags ...attribute.KeyValue) (trace.Span, context.Context)

func StartTraceWithoutResourceAttributes added in v0.9.12

func StartTraceWithoutResourceAttributes(ctx context.Context, name string, opts []trace.SpanStartOption, tags ...attribute.KeyValue) (trace.Span, context.Context)

func StartWithContext

func StartWithContext(ctx context.Context, opts ...Option)

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

func Stop()

Stop flushes and shuts down the SDK.

Types

type ErrorWithStack added in v0.8.9

type ErrorWithStack interface {
	Error() string
	StackTrace() errors.StackTrace
}

type Logger

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

Logger is an interface that implements Log and Logf

type OTLP

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

func StartOTLP

func StartOTLP() (*OTLP, error)

type Option added in v0.9.10

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

func WithEnvironment added in v0.9.14

func WithEnvironment(environment string) Option

func WithMetricSamplingRate added in v0.10.1

func WithMetricSamplingRate(samplingRate float64) Option

func WithProjectID added in v0.10.1

func WithProjectID(projectID string) Option

func WithSamplingRate added in v0.10.1

func WithSamplingRate(samplingRate float64) Option

func WithSamplingRateMap added in v0.10.2

func WithSamplingRateMap(rates map[trace.SpanKind]float64) Option

func WithServiceName added in v0.9.10

func WithServiceName(serviceName string) Option

func WithServiceVersion added in v0.9.10

func WithServiceVersion(serviceVersion string) Option

type TraceType added in v0.9.13

type TraceType string
const TraceTypeHighlightInternal TraceType = "highlight.internal"
const TraceTypeNetworkRequest TraceType = "http.request"

Directories

Path Synopsis
chi
gin

Jump to

Keyboard shortcuts

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