usagerecorder

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package usagerecorder provides a graphql extension to record graphql usage. This extension records graphql queries and variables from any service.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GraphqlUsage

type GraphqlUsage struct {
	OperationTime         time.Time                   `json:"requestedTimestamp"`
	QueryOperationName    string                      `json:"queryOperationName"`
	QueryComplexity       extension.ComplexityStats   `json:"queryComplexity"`
	QueryVariables        map[string]interface{}      `json:"queryVariables"`
	Query                 string                      `json:"query"`
	ReferencedTypes       map[string][]*ReferenceType `json:"referencedTypes"`
	OperationMilliseconds int64                       `json:"operationMilliseconds"`
	ExtraValues           map[string]interface{}      `json:"extraValues"`
}

type GraphqlUsageRecorder

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

GraphqlUsageRecorder records usages of graphql API calls. That is used to investigate API usages.

func New

New creates a new GraphqlUsageRecorder.

func (*GraphqlUsageRecorder) CollectGraphqlUsage

func (g *GraphqlUsageRecorder) CollectGraphqlUsage(ctx context.Context, oc *graphql.OperationContext) *GraphqlUsage

func (*GraphqlUsageRecorder) ExtensionName

func (g *GraphqlUsageRecorder) ExtensionName() string

func (*GraphqlUsageRecorder) GetUserAgent

func (g *GraphqlUsageRecorder) GetUserAgent(oc *graphql.OperationContext) string

func (*GraphqlUsageRecorder) InterceptResponse

func (g *GraphqlUsageRecorder) InterceptResponse(ctx context.Context, next graphql.ResponseHandler) *graphql.Response

func (*GraphqlUsageRecorder) Validate

func (g *GraphqlUsageRecorder) Validate(schema graphql.ExecutableSchema) error

type LogEmitter

type LogEmitter struct {
	Logger               *slog.Logger
	SamplingRate         int
	RandomValueGenerator func() int
}

func NewLogEmitter

func NewLogEmitter(logger *slog.Logger, samplingRate int) *LogEmitter

func (*LogEmitter) Emit

func (x *LogEmitter) Emit(usage *GraphqlUsage) error

func (*LogEmitter) Sampling

func (x *LogEmitter) Sampling() bool

Sampling returns true if the sampling rate is 100 or the random value is less than the sampling rate.

type ReferenceType

type ReferenceType struct {
	TypeName string   `json:"typeName"`
	Fields   []string `json:"fields"`
}

type UsageEmitter

type UsageEmitter interface {
	Emit(usage *GraphqlUsage) error
}

type UsageRecorderOption

type UsageRecorderOption func(*GraphqlUsageRecorder)

func WithClock

func WithClock(clock func() time.Time) UsageRecorderOption

WithClock sets the clock to the recorder.

func WithEmitVariables

func WithEmitVariables(emitVariables bool) UsageRecorderOption

WithEmitVariables sets the emitVariables flag to the recorder.

func WithEmitter

func WithEmitter(emitter UsageEmitter) UsageRecorderOption

WithEmitter sets the emitter to the recorder.

func WithEmitterErrorHandler

func WithEmitterErrorHandler(handler func(err error)) UsageRecorderOption

WithEmitterErrorHandler sets the emitter error handler to the recorder.

func WithExternalValuesExtractor

func WithExternalValuesExtractor(extractor func(ctx context.Context, oc *graphql.OperationContext) map[string]interface{}) UsageRecorderOption

WithExternalValuesExtractor sets the external values extractor to the recorder.

func WithLogger

func WithLogger(logger *slog.Logger) UsageRecorderOption

WithLogger sets the logger to the recorder.

Jump to

Keyboard shortcuts

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