Formatting
The Jaeger-lib codebase follows a consistent formatting style to ensure readability and maintainability. The following guidelines are used:
General Formatting:
- Code Style: Go code follows the official Go formatting style, which can be enforced using
gofmt
. - Line Length: Code lines should be kept under 120 characters.
- Indentation: Use 4 spaces for indentation, never tabs.
- Imports: Imports should be grouped and sorted alphabetically.
- Comments: Comments should be clear and concise.
Specific Formatting:
Functions:
- Function names use camelCase, starting with a lowercase letter, e.g.
getMetrics
. - Each function should have a brief comment explaining its purpose.
- Function names use camelCase, starting with a lowercase letter, e.g.
Variables:
- Variable names are in camelCase, starting with a lowercase letter, e.g.
serviceName
. - Constants should be in ALL_CAPS, e.g.
CURRENT_YEAR
.
- Variable names are in camelCase, starting with a lowercase letter, e.g.
Structs:
- Struct names use CamelCase, starting with a capital letter, e.g.
Influx
. - Struct fields use camelCase, starting with a lowercase letter, e.g.
serviceName
.
- Struct names use CamelCase, starting with a capital letter, e.g.
Examples:
- Function Definition:
// GetMetrics retrieves all metrics from the specified source.
func GetMetrics(source string) ([]*Metric, error) {
// Implementation of the GetMetrics function.
}
- Variable Declaration:
var currentYear int = 2023
const CURRENT_YEAR = 2023
- Struct Declaration:
// Influx represents a InfluxDB client.
type Influx struct {
client *influxdb2.Client
database string
}
Resources:
- Go Formatting: https://golang.org/doc/effective_go.html#formatting
- Go Code Style Guide: https://github.com/golang/go/wiki/CodeReviewComments
Tools:
gofmt
: Go formatter tool.goimports
: Tool for managing imports.
Enforcement:
- The Jaeger-lib codebase uses automated tools to ensure code formatting consistency.
- All code contributions must pass these checks before being accepted.
Top-Level Directory Explanations
client/ - This directory contains the client-side code for the Jaeger Tracing library.
client/log/ - This subdirectory contains the logging implementation for the client-side code.
client/log/go-kit/ - This subdirectory of the logging implementation contains the Go-Kit logging adapter.
metrics/ - This directory contains the metrics implementation for the Jaeger Tracing library.
metrics/adapters/ - This subdirectory contains the various metric adapters for different backends.
metrics/expvar/ - This subdirectory contains the implementation for exposing metrics as HTTP endpoints using the expvar package.
metrics/go-kit/ - This subdirectory contains the Go-Kit integration for the Jaeger Tracing library.
metrics/go-kit/expvar/ - This subdirectory contains the expvar implementation for the Go-Kit integration.
metrics/go-kit/influx/ - This subdirectory contains the InfluxDB implementation for the Go-Kit integration.
metrics/metricstest/ - This subdirectory contains the testing implementation for the metrics.
metrics/prometheus/ - This subdirectory contains the Prometheus implementation for the Jaeger Tracing library.
metrics/tally/ - This subdirectory contains the implementation for counting metrics using the tally package.
sample/ - This directory contains a sample implementation for the Jaeger Tracing library.
scripts/ - This directory contains various scripts for the project.