otelog

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2023 License: MIT Imports: 14 Imported by: 1

README

otelog

Open Telemetry log support for golang. Basically it just provide a missing LogExporter for go.opentelemetry.io/otel. The package also provides a hook for github.com/sirupsen/logrus

This library is just a substitute while waiting on the official implementation of the LogExporter in Open Telemetry. Indeed, in some use case, like long lived batch job, you do not want to export your log as span events, but rather real entries, that may be linked to the span who started the span jobs.

This implementation is far to be error prone or optimized. For example you cannot share your trace and log connection to the opentelemetry connector. If this is a concern, wait or contribute to opentelemetry to add this support.

Currently only tested with SigNoz and logrus.

Example

See examples/logrus-exporter for an example of the API.

Documentation

Overview

Package otelog provides global function to register an Open Telemetry Collector endpoint to export log records to.

This package is meant to be a temporarly replacement while waiting a more thoroughly implemented and tested package provided by https://pkg.go.dev/go.opentelemetry.io/ . Please use it in production only if you really needs it.

Basics

You will need to SetLogExporter() with a NewLogExporter() indicating the Open Telemetry Collector Endpoint.

Then you can use hooks in `github.com/atuleu/otelog/pkg/hooks` to integrate your logging library. Currently only `github.com/sirupsen/logrus` integration is provided.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetLogExporter

func SetLogExporter(exporter LogExporter)

SetLogExporter sets the global LogExporter to exporter. This method is not concurrently safe.

Types

type BatchLogProcessorOption

type BatchLogProcessorOption interface {
	// contains filtered or unexported methods
}

BatchLogProcessorOption is an Option for WithBatchLogProcessor()

func WithBatchTimeout

func WithBatchTimeout(timeout time.Duration) BatchLogProcessorOption

WithBatchTimeout sets the timeout after which a batch will be exported regardless of the number of queued LogRecord.

func WithMaxQueueSize

func WithMaxQueueSize(size int) BatchLogProcessorOption

WithMaxQueueSize sets the max queue size before a batch will be emitted.

type LogExporter

type LogExporter interface {
	Export(log *logs.LogRecord)
}

A LogExporter is used to export log for example, to an Open Telemetry collector.

func GetLogExporter

func GetLogExporter() LogExporter

GetLogExporter gets the global LogExporter registered with SetLogExporter. If none was registered a NoopLogExporter will be returned. It is concurrently safe to call GetLogExporter from multiple go routines.

func NewLogExporter

func NewLogExporter(options ...LogExporterOption) (LogExporter, error)

Creates a new LogExporter that will export LogRecord to the specified endpoint. The endpoint address must be specified with WithEndpoint(). Credential must be specified with either WithInsecure() or WithTLSCredential().

func NoopLogExporter

func NoopLogExporter() LogExporter

Creates a Log exporter that exports nothing.

type LogExporterOption

type LogExporterOption interface {
	// contains filtered or unexported methods
}

LogExporterOption is an option to use with NewLogExporter().

func WithBatchLogProcessor

func WithBatchLogProcessor(options ...BatchLogProcessorOption) LogExporterOption

Sets a LogProcessor that batches logs before exporting them.

func WithEndpoint

func WithEndpoint(endpoint string) LogExporterOption

Sets the Open Telemetry collector endpoint to export logs to.

func WithGRPCConn added in v0.1.3

func WithGRPCConn(conn *grpc.ClientConn) LogExporterOption

func WithInsecure

func WithInsecure() LogExporterOption

Sets no credential for the OpenTelemetry endpoint.

func WithResource

func WithResource(r *resource.Resource) LogExporterOption

Sets the resource associated with the LogExporter

func WithScope

Sets the scope associated with the LogExporter

func WithSyncer

func WithSyncer() LogExporterOption

Sets a LogProcessor that sends every event immediatly. It should be avoided in production.

func WithTLSCredentials

Sets the gRPC TLS credential to use for the OpenTelemetry endpoint.

type LogProcessor

type LogProcessor interface {
	// contains filtered or unexported methods
}

LogProcessor process incoming LogRecord and batches them if needed.

Directories

Path Synopsis
examples
internal
pkg
hooks
Package hooks provide hooks and integration for otelgo to various logging library.
Package hooks provide hooks and integration for otelgo to various logging library.

Jump to

Keyboard shortcuts

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