Git Product home page Git Product logo

otlpr's Introduction

otlpr

Go Reference

This repository provides a logr.Logger that exports recorded messages as OpenTelemetry logs to an OTLP receiving endpoint.

๐Ÿšง This repository is a work in progress and not production ready.

Getting Started

A working gRPC connection to an OTLP receiving endpoint is needed to setup the logger.

conn, _ := grpc.NewClient(otlpTarget)

Create a logr.Logger with this connection.

logger := otlpr.New(conn)

See the example for a working example application.

Batching

By default the logger will batch the log messages as they are received. It will wait to batch 2048 messages before exporting.

A Batcher can be used to change this behavior.

opts := otlpr.Options{
	Batcher: otlpr.Batcher{
		// Only queue at most 100 messages.
		Messages: 100,
		// Only wait 3 seconds for the queue to fill.
		Timeout: 3 * time.Second,
	},
}
logger := otlpr.NewWithOptions(conn, opts)

Max messages in export

The Batcher can be configured to limit the number of messages it sends for each export with the ExportN setting.

opts := otlpr.Options{
	Batcher: otlpr.Batcher{
		// Only send at most 100 messages per export.
		ExportN: 100,
	},
}
logger := otlpr.NewWithOptions(conn, opts)

Annotating Span Context

OTLP is able to associate span context with log messages. Use the WithContext function to associate a context.Context that contains an active span with all logs the logger creates.

logger = otlpr.WithContext(logger, ctx)

The function can also be used to clear any span context from the logger.

logger = otlpr.WithContext(logger, context.Background())

Adding a Resource

The system a log message is produced in can be described with a Resource. Use the WithResource function to include this information with the exported OTLP data.

logger = otlpr.WithResource(logger, resource)

The function can also be used to clear any resource from the logger.

logger = otlpr.WithResource(logger, nil)

Adding Scope

The portion of a system a log message is produced in can be described with Scope. Use the WithScope function to include this information with the exported OTLP data.

logger = otlpr.WithScope(logger, resource)

The function can also be used to clear any scope from the logger.

logger = otlpr.WithScope(logger, instrumentation.Scope{})

otlpr's People

Contributors

dependabot[bot] avatar mralias avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.