instrumentscan

package
v19.5.2 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package instrumentscan reads the OpenTelemetry instruments a Go package creates from its sources. The sources are parsed, not type-checked, so every creation call must keep one shape: the name a string constant of the package, the description and the unit string literals, the bucket boundaries number literals, and every other option a callback. A call of another shape fails the scan at its position rather than being misread.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParsePackage

func ParsePackage(dir string) (*token.FileSet, []*ast.File, error)

ParsePackage parses every non-test Go file in dir without type checking. Positions carry the paths as dir joined with the file name.

func StringLiteral

func StringLiteral(e ast.Expr) (string, bool)

StringLiteral reports the value of e when it is a string literal.

Types

type Instrument

type Instrument struct {
	Name        string
	NameConst   string
	Constructor string
	Unit        string
	Boundaries  []float64
	Callbacks   int
	Description string
	Pos         token.Position
}

Instrument is one instrument creation call as the sources declare it. NameConst is the constant the name was read from and Pos the position of the call.

func Scan

func Scan(fset *token.FileSet, files []*ast.File, constants []StringConstant) ([]Instrument, error)

Scan reads every call of an instrument constructor in files and returns the instruments sorted by name. constants are the package's string constants, which the names are read from.

func (*Instrument) Kind

func (i *Instrument) Kind() string

Kind is the constructor without its number type: Counter, Histogram, ObservableGauge and so on.

type StringConstant

type StringConstant struct {
	Name  string
	Type  ast.Expr
	Value string
}

StringConstant is a top-level constant whose value is a string literal. Type is the type as written and nil for an untyped constant.

func StringConstants

func StringConstants(files []*ast.File) []StringConstant

StringConstants collects the top-level constants whose value is a string literal, typed or untyped, in declaration order.

Directories

Path Synopsis
cmd
metricsdoc command
Command metricsdoc writes the metrics table of a package, rendered from the OpenTelemetry instruments its sources create.
Command metricsdoc writes the metrics table of a package, rendered from the OpenTelemetry instruments its sources create.

Jump to

Keyboard shortcuts

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