metrics

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2024 License: MIT Imports: 18 Imported by: 1

README

go-kit/metrics - Metrics Module

Go Reference Last Commit Open Issues Open Pull Requests

The metrics module provides a set of tools to collect and expose metrics for a Go application.

About this module

This module provides two wrappers around OpenTelemetry and Prometheus to initialize a trace provider and a prometheus registry.

Installation

To install, run:

go get github.com/lvlcn-t/go-kit/metrics

And import the package in your code:

import "github.com/lvlcn-t/go-kit/metrics"

Usage

The documentation for this module can be found on pkg.go.dev.

To see how to use this module, you can check the examples directory of the repository.

Code of Conduct

This project has adopted the Contributor Covenant in version 2.1 as our code of conduct. Please see the details in our CODE_OF_CONDUCT.md. All contributors must abide by the code of conduct.

Working Language

We decided to apply English as the primary project language.

Consequently, all content will be made available primarily in English. We also ask all interested people to use English as the preferred language to create issues, in their code (comments, documentation, etc.) and when you send requests to us. The application itself and all end-user facing content will be made available in other languages as needed.

Support and Feedback

The following channels are available for discussions, feedback, and support requests:

Type Channel
Issues General Discussion

How to Contribute

Contribution and feedback is encouraged and always welcome. For more information about how to contribute, the project structure, as well as additional contribution information, see our Contribution Guidelines. By participating in this project, you agree to abide by its Code of Conduct at all times.

Licensing

Copyright (c) 2024 lvlcn-t.

Licensed under the MIT (the "License"); you may not use this file except in compliance with the License.

You may obtain a copy of the License at https://www.mit.edu/~amini/LICENSE.md.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an " AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the LICENSE for the specific language governing permissions and limitations under the License.

Documentation

Overview

Package metrics provides a way to initialize OpenTelemetry metrics and Prometheus collectors.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(config Config) *manager

New creates a new metrics instance with the given configuration. This instance can be used to initialize the OpenTelemetry metrics and Prometheus collectors.

Types

type Collector

type Collector interface {
	// GetRegistry returns the prometheus registry instance containing the registered prometheus collectors
	GetRegistry() *prometheus.Registry
}

Collector is the interface that wraps the basic methods of the Prometheus collector

type Config

type Config struct {
	// Exporter is the otlp exporter used to export the traces
	Exporter Exporter `yaml:"exporter" mapstructure:"exporter"`
	// Url is the Url of the collector to which the traces are exported
	Url string `yaml:"url" mapstructure:"url"`
	// Token is the token used to authenticate with the collector
	Token string `yaml:"token" mapstructure:"token"`
	// CertPath is the path to the tls certificate file
	CertPath string `yaml:"certPath" mapstructure:"certPath"`
}

Config holds the configuration for OpenTelemetry

func (Config) IsEmpty

func (c Config) IsEmpty() bool

IsEmpty returns true if the configuration is empty

func (*Config) Validate

func (c *Config) Validate() error

Validate validates the configuration.

type ErrAlreadyInitialized

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

ErrAlreadyInitialized is an error that is returned when the metrics are already initialized. This error is returned when the Initialize method is called more than once.

func (*ErrAlreadyInitialized) Error

func (e *ErrAlreadyInitialized) Error() string

Error returns the error message.

func (*ErrAlreadyInitialized) Is

func (e *ErrAlreadyInitialized) Is(target error) bool

Is reports whether the error is an ErrAlreadyInitialized.

type Exporter

type Exporter string

Exporter is the protocol used to export the traces

const (
	// HTTP is the protocol used to export the traces via HTTP/1.1
	HTTP Exporter = "http"
	// GRPC is the protocol used to export the traces via HTTP/2 (gRPC)
	GRPC Exporter = "grpc"
	// STDOUT is the protocol used to export the traces to the standard output
	STDOUT Exporter = "stdout"
	// NOOP is the protocol used to not export the traces
	NOOP Exporter = ""
)

func (Exporter) Create

func (e Exporter) Create(ctx context.Context, config *Config) (sdktrace.SpanExporter, error)

Create creates a new exporter based on the configuration

func (Exporter) RegisterExporter added in v0.3.0

func (e Exporter) RegisterExporter(factory exporterFactory) error

RegisterExporter registers the exporter with the factory function. Not safe for concurrent use.

func (Exporter) String

func (e Exporter) String() string

String returns the string representation of the protocol

func (Exporter) Validate

func (e Exporter) Validate() error

Validate validates the protocol

type Tracer

type Tracer interface {
	// Initialize initializes the OpenTelemetry metrics with the given service name and version
	Initialize(ctx context.Context, serviceName, serviceVersion string) error
	// Shutdown shuts down the OpenTelemetry tracer
	Shutdown(ctx context.Context) error
}

Tracer is the interface that wraps the basic methods of the OpenTelemetry tracer

Jump to

Keyboard shortcuts

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