otel

package module
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2026 License: MIT Imports: 19 Imported by: 0

README

Package otel v0.9.0

Usage

Collect a metric synchronously (with a counter instrument)

See the directory docs/examples/int64-sync-counter for a complete example.

Collect a metric asynchronously (with a gauge instrument)

See the directory docs/examples/int64-async-gauge for a complete example.

Development of this package

Generate mocks

We first need to vendor the dependencies (go mod vendor) in order to generate the external dependencies mocks.

Run the following command to generate mocks for the otel package inside the otelmock package:

gomock_generator

[!IMPORTANT] And then, please make sure that on each mock file, that each struct embed the original interface.

For example, the gomock library underneath generates the following code for the metric.Int64Gauge interface:

// MockInt64Gauge is a mock of Int64Gauge interface.
type MockInt64Gauge struct {
	ctrl     *gomock.Controller
	recorder *MockInt64GaugeMockRecorder
}

Please make sure that the MockInt64Gauge struct embeds the metric.Int64Gauge interface like this, otherwise the generated mocks will not be usable:

type MockInt64Gauge struct {
	metric.Int64Gauge

	ctrl     *gomock.Controller
	recorder *MockInt64GaugeMockRecorder
}

This is actually a missing feature of gomock that is not yet implemented, see this issue.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init(ctx context.Context, opts ...InitOpt) func() error

Types

type Config

type Config struct {
	ServiceInstanceId string `default:"" split_words:"true"` // nolint:revive
	HostName          string `default:"" split_words:"true"`
	Debug             bool   `default:"false"`
	DebugPrettyPrint  bool   `default:"true" split_words:"true"`
	ExporterType      string `default:"grpc" split_words:"true"`

	// OpenTelemetry official env vars
	// https://opentelemetry.io/docs/specs/otel/configuration/sdk-environment-variables/#general-sdk-configuration
	ServiceName string `required:"true" split_words:"true"`
	SdkDisabled bool   `default:"false" split_words:"true"`

	// https://opentelemetry.io/docs/languages/sdk-configuration/otlp-exporter/#otel_exporter_otlp_endpoint
	// https://opentelemetry.io/docs/specs/otel/protocol/exporter/#configuration-options
	ExporterOtlpEndpoint          string `default:"" split_words:"true"`
	ExporterOtlpCertificate       string `default:"" split_words:"true"` // CA Certificate
	ExporterOtlpClientKey         string `default:"" split_words:"true"`
	ExporterOtlpClientCertificate string `default:"" split_words:"true"`

	// https://opentelemetry.io/docs/specs/otel/configuration/sdk-environment-variables/#periodic-exporting-metricreader
	MetricExportInterval time.Duration `default:"10s" split_words:"true"`
}

type InitOpt added in v0.8.0

type InitOpt func(defaultAptions *initDefaultOptions)

func WithDefaultAttributes added in v0.8.0

func WithDefaultAttributes(attrs ...attribute.KeyValue) InitOpt

func WithServiceVersionAttribute added in v0.8.0

func WithServiceVersionAttribute(version string) InitOpt

Directories

Path Synopsis
Package otelmock is a generated GoMock package.
Package otelmock is a generated GoMock package.

Jump to

Keyboard shortcuts

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