autometrics

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2024 License: Apache-2.0, MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AutometricsLinkCommentGenerator

type AutometricsLinkCommentGenerator interface {
	GenerateAutometricsComment(ctx GeneratorContext, funcName, moduleName string) []string
	// Generated Links returns the list of text from links created by
	// GenerateAutometricsComment.
	//
	// As gofmt will move the links outside the fences for Autometrics
	// documentation, we add a helper to track the links to delete/recreate
	// in the links section when calling the generator multiple times.
	GeneratedLinks() []string
}

type GeneratorContext

type GeneratorContext struct {
	// RuntimeCtx holds the information about the runtime context to build from in the generated code.
	RuntimeCtx RuntimeCtxInfo
	// FuncCtx holds the function specific information for the detected autometrics directive.
	//
	// Notably, it contains all the data relative to the parsing of the arguments in the directive.
	FuncCtx GeneratorFunctionContext
	// Implementation is the metrics library we expect to use in the instrumented code.
	Implementation autometrics.Implementation
	// DocumentationGenerator is the generator to use to generate comments.
	DocumentationGenerator AutometricsLinkCommentGenerator
	// Allow the autometrics directive to have latency targets outside the default buckets.
	AllowCustomLatencies bool
	// Flag to disable/remove the documentation links when calling the generator.
	//
	// This can be set in the command for the generator or through the environment.
	DisableDocGeneration bool
	// Flag to ask the generator to process all function declaration even if they
	// do not have any annotation. The flag is overriden by the RemoveEverything one.
	InstrumentEverything bool
	// Flag to ask the generator to only remove all autometrics generated code in the
	// file.
	RemoveEverything bool
	// ImportMap maps the alias to import in the current file, to canonical names associated with that name.
	ImportsMap map[string]string
}

GeneratorContext contains the complete command-line and environment context from the generator invocation.

This context contains all the information necessary to properly process the `autometrics` directives over each instrumented function in the file.

func NewGeneratorContext

func NewGeneratorContext(implementation autometrics.Implementation, prometheusUrl string, allowCustomLatencies, disableDocGeneration, instrumentEverything, removeEverything bool) (GeneratorContext, error)

func (*GeneratorContext) ResetFuncCtx

func (c *GeneratorContext) ResetFuncCtx()

func (*GeneratorContext) SetCommentIdx

func (c *GeneratorContext) SetCommentIdx(i int)

type GeneratorFunctionContext

type GeneratorFunctionContext struct {
	CommentIndex         int
	FunctionName         string
	ModuleName           string
	ImplImportName       string
	DisableDocGeneration bool
}

type Prometheus

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

func NewPrometheusDoc

func NewPrometheusDoc(instanceUrl url.URL) Prometheus

NewPrometheusDoc builds a documentation comment generator that creates Prometheus links.

The document generator implements the AutometricsLinkCommentGenerator interface.

func (Prometheus) GenerateAutometricsComment

func (p Prometheus) GenerateAutometricsComment(ctx GeneratorContext, funcName, moduleName string) []string
func (p Prometheus) GeneratedLinks() []string

type RuntimeCtxInfo added in v0.6.0

type RuntimeCtxInfo struct {
	// Name of the variable to use as context.Context when building the autometrics.Context.
	// The string will be empty if 'nil' must be used as autometrics.NewContext() argument.
	ContextVariableName string
	// Name of the variable to assign to the context returned by autometrics.PreInstrument
	// The string will be empty if a new variable must be used as autometrics.PreInstrument() return value assignment.
	NewContextVariableName string
	// Verbatim code to use to fetch the TraceID.
	// For example, if the instrumented function is detected to use Gin, like
	// `func ginHandler(ginVarName *gin.Context)`
	// then the code in that variable should be something like
	// `"autometrics.DecodeString(ginVarName.GetString(\"TraceID\"))"`
	// This getter should return []byte to allow PreInstrument to
	// log warnings and fill the data manually if the getter returns nil.
	TraceIDGetter        string
	SpanIDGetter         string
	TrackConcurrentCalls bool
	TrackCallerName      bool
	AlertConf            *autometrics.AlertConfiguration
}

This is almost a carbon copy of the autometrics.Context structure, except that non-literal types are transcribed to strings to make it possible to reason about the runtime context within generator logic. Also, all the information that only gets filled at runtime is simply ignored, as only statically-known information is useful at this point.

func DefaultRuntimeCtxInfo added in v0.6.0

func DefaultRuntimeCtxInfo() RuntimeCtxInfo

func (RuntimeCtxInfo) Validate added in v0.6.0

func (c RuntimeCtxInfo) Validate(allowCustomLatencies bool) error

Jump to

Keyboard shortcuts

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