utility

package
v0.0.0-...-fe160b4 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2024 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Overview

utility/bedrock.go

utility/genid.go

utility/loki.go

utility/otel.go

utility/prometheus.go

utility/s3.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddSpanAttributes

func AddSpanAttributes(ctx context.Context, attributes ...attribute.KeyValue)

AddSpanAttributes adds attributes to the current span

func EndSpan

func EndSpan(span trace.Span)

EndSpan ends the span in the given context

func GenerateFileID

func GenerateFileID() string

func GenerateID

func GenerateID() string

func GetTracer

func GetTracer(name string) trace.Tracer

GetTracer returns a named tracer

func InitBedrock

func InitBedrock(cfg *config.Config) error

func InitLogger

func InitLogger(l *logrus.Logger)

InitLogger should be called from your main application to set up the logger

func InitLokiLogger

func InitLokiLogger(cfg *config.Config) error

func InitMetrics

func InitMetrics()

InitMetrics initializes Prometheus metrics

func InitS3Client

func InitS3Client(cfg *config.Config) (*s3.Client, error)

func InitTracer

func InitTracer(cfg *config.Config) func()

InitTracer initializes the OpenTelemetry tracer

func LogError

func LogError(ctx *gin.Context, message string, err error)

func LogFatal

func LogFatal(ctx *gin.Context, message string, err error)

func LogInfo

func LogInfo(ctx *gin.Context, message string)

func LogMetrics

func LogMetrics(metrics Metrics)

LogMetrics logs the collected metrics

func LogWarn

func LogWarn(ctx *gin.Context, message string)

func LogWithLoki

func LogWithLoki(ctx *gin.Context, level, message string, err error)

func PrometheusHandler

func PrometheusHandler() gin.HandlerFunc

PrometheusHandler returns a handler for the /metrics endpoint

func RecordError

func RecordError(ctx context.Context, err error)

RecordError records an error in the current span

func RecordFileUpload

func RecordFileUpload(fileType string, sizeBytes float64)

RecordFileUpload records metrics for a file upload

func RecordHTTPRequest

func RecordHTTPRequest(method, endpoint string, status int, duration float64)

RecordHTTPRequest records metrics for an HTTP request

func StartSpan

func StartSpan(ctx context.Context, name string) (context.Context, trace.Span)

StartSpan starts a new span and returns the context with the span

func UploadFileToS3

func UploadFileToS3(ctx context.Context, client *s3.Client, bucket string, key string, file io.Reader) (string, error)

UploadFileToS3 uploads a file to S3 and returns the URL

func WithSpan

func WithSpan(ctx context.Context, name string, fn func(context.Context) error) error

WithSpan wraps a function with a new span

Types

type Message

type Message struct {
	Role    string `json:"role"`
	Content string `json:"content"`
}

type Metrics

type Metrics struct {
	TotalLatency    time.Duration
	UploadLatency   time.Duration
	AnalysisLatency time.Duration
	InputTokens     int
	OutputTokens    int
}

Metrics struct to hold various metrics

func AnalyzeWithBedrock

func AnalyzeWithBedrock(ctx context.Context, content string) (string, Metrics, error)

Jump to

Keyboard shortcuts

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