tracemod

package module
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2025 License: Apache-2.0 Imports: 12 Imported by: 1

README

tracemod

Using tracemod takes care of exporting spans to otel endpoint and flushing buffers before the application exits.

package main

import (
	"github.com/go-srvc/mods/tracemod"
	"github.com/go-srvc/srvc"
)

func main() {
	srvc.RunAndExit(
		tracemod.New(),
	)
}

Documentation

Overview

Package tracemod provides OpenTelemetry trace provider as a module.

Index

Examples

Constants

View Source
const (
	ErrMissingProvider = errStr("trace provider not set")
	ErrFlushFailed     = errStr("failed to flush remaining spans")
)
View Source
const ID = "tracemod"

Variables

This section is empty.

Functions

This section is empty.

Types

type Opt

type Opt func(*Provider) error

func WithEnv added in v0.1.5

func WithEnv() Opt

WithEnv uses OTEL_EXPORTER_OTLP_TRACES_PROTO and OTEL_EXPORTER_OTLP_PROTO environment variable to set exporter. Accepted values are:

  • http
  • grpc
  • stdout

If no value is provided, stdout is used.

func WithGRPC

func WithGRPC() Opt

WithGRPC creates meter provider with periodic reader using grpc exporter from OTEL_* env configs. Env variables: https://pkg.go.dev/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc

func WithHTTP

func WithHTTP() Opt

WithHTTP creates meter provider with periodic reader using http exporter from OTEL_* env configs. Env variables: https://pkg.go.dev/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp

func WithPropagator

func WithPropagator(prop propagation.TextMapPropagator) Opt

WithPropagator allows setting custom text map propagator.

func WithProvider

func WithProvider(exp *trace.TracerProvider) Opt

WithProvider sets the underlying trace provider for module.

func WithProviderFn

func WithProviderFn(fn func() (*trace.TracerProvider, error)) Opt

WithProviderFn sets the underlying trace provider for module using given function.

func WithStdout added in v0.1.5

func WithStdout(opt ...stdouttrace.Option) Opt

WithStdout creates trace provider with stdout exporter.

type Provider

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

func New

func New(opts ...Opt) *Provider

New creates tracer provider module with sane defaults. Default options are: WithEnv.

Example
package main

import (
	"github.com/go-srvc/mods/tracemod"
	"github.com/go-srvc/srvc"
)

func main() {
	srvc.RunAndExit(
		tracemod.New(),
	)
}

func (*Provider) ID

func (p *Provider) ID() string

func (*Provider) Init

func (p *Provider) Init() error

func (*Provider) Run

func (p *Provider) Run() error

func (*Provider) Stop

func (p *Provider) Stop() error

Jump to

Keyboard shortcuts

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