Documentation ¶
Overview ¶
Package usagerecorder provides a graphql extension to record graphql usage. This extension records graphql queries and variables from any service.
Index ¶
- type GraphqlUsage
- type GraphqlUsageRecorder
- func (g *GraphqlUsageRecorder) CollectGraphqlUsage(ctx context.Context, oc *graphql.OperationContext) *GraphqlUsage
- func (g *GraphqlUsageRecorder) ExtensionName() string
- func (g *GraphqlUsageRecorder) GetUserAgent(oc *graphql.OperationContext) string
- func (g *GraphqlUsageRecorder) InterceptResponse(ctx context.Context, next graphql.ResponseHandler) *graphql.Response
- func (g *GraphqlUsageRecorder) Validate(schema graphql.ExecutableSchema) error
- type LogEmitter
- type ReferenceType
- type UsageEmitter
- type UsageRecorderOption
- func WithClock(clock func() time.Time) UsageRecorderOption
- func WithEmitVariables(emitVariables bool) UsageRecorderOption
- func WithEmitter(emitter UsageEmitter) UsageRecorderOption
- func WithEmitterErrorHandler(handler func(err error)) UsageRecorderOption
- func WithExternalValuesExtractor(...) UsageRecorderOption
- func WithLogger(logger *slog.Logger) UsageRecorderOption
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 ¶
func New(options ...UsageRecorderOption) *GraphqlUsageRecorder
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 ¶
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 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.