genstrument

command module
v0.0.0-...-6da336c Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2023 License: MIT Imports: 8 Imported by: 0

README

Genstrument

Generate code to instrument an interface.

Supported Interfaces

Genstrument always needs a go interface to generate an instrumented wrapper around that given interface. Currently Genstrument supports the following kinds of interfaces for code generation. Depending on the use case the GeneratorMode must be passed via the --mode=<mode> flag to the Genstrument binary.

	// Binary mode can generate instrumented code for an interface which methods return an error as the last argument.
	// With respect to the value of the error (nil or not nil), the corresponding counter in the counter vector will be increased.
	Binary GeneratorMode = "binary"
	// Handler can generate instrumented wrappers around a typical http server interface.
	// Each method is a http.HandlerFunc `func(w http.ResponseWriter, r *http.Request)`.
	// Extensions with more parameters after the `*http.Request` are also possible.
	// This way server code generated by https://github.com/deepmap/oapi-codegen can be instrumented.
	Handler GeneratorMode = "handler"
	// OapiCodeGenClient mode generates instrumented code from the client interface generated by https://github.com/deepmap/oapi-codegen.
	// See https://github.com/deepmap/oapi-codegen#generated-client-boilerplate.
	OapiCodeGenClient GeneratorMode = "oapi-codegen-client"

Install

Install with

go install github.com/leonnicolas/genstrument@latest

or add github.com/leonnicolas/genstrument to your tools.go file.

Usage

Run

genstrument --file-path <file-path-to-interface> -p <interface-name> --metric-help <help text> --metric-name <metric-name> -o -

to print the generated code to stdout.

Or add something like

//go:generate go run github.com/leonnicolas/genstrument --file-path <file-name> -p <interface-name> --metric-help <help text> --metric-name <metric-name> -o gen.go

into the go file, that contains the interface you want to instrument.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
examples
pkg

Jump to

Keyboard shortcuts

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