telemetry

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2023 License: MIT Imports: 11 Imported by: 2

README

Telemetry

Telemetry is a lib to simplify Telemetry Agents instalations.

Installation

go get github.com/facily-tech/go-core/telemetry

Implementation Examples

  1. Implement it instance; (Ex: https://github.com/facily-tech/go-scaffold/blob/main/internal/container/container.go)
  2. Implement it's close function into Main; (Ex: https://github.com/facily-tech/go-scaffold/blob/main/cmd/api/main.go)
  3. Implement the traces. (Ex: https://github.com/facily-tech/go-scaffold/blob/main/internal/api/handler.go)

Documentation

Overview

Package telemetry is responsible to handle telemetry usage.

Index

Constants

View Source
const TracerKey string = "tracer"

TracerKey is the key used to define tracer key name when adding it on logging.

Variables

This section is empty.

Functions

func Client added in v0.3.1

func Client(parent *http.Client) *http.Client

Client receive *http.Client and return a *http.Client with datadog tracer wrapped in it.

Types

type Command added in v1.3.0

type Command func(ctx context.Context) []CommandResultParam

Command is a callback function to be implemented with block segment that should be covered.

type CommandResultParam added in v1.3.0

type CommandResultParam struct {
	Key   string
	Value interface{}
}

CommandResultParam are the metrics to be attached as span's attributes.

type DataDog

type DataDog struct{}

DataDog implements Tracer.

func NewDatadog added in v1.1.0

func NewDatadog() (*DataDog, error)

NewDatadog returns a new Datadog implementation.

func (DataDog) Client

func (DataDog) Client(parent *http.Client) *http.Client

Client wraps datadog tracer into http.Client.

func (DataDog) Close

func (DataDog) Close()

Close datadog tracer.

func (*DataDog) Middleware

func (d *DataDog) Middleware(next http.Handler) http.Handler

Middleware add into http framework datadog tracer to track each requisition.

func (DataDog) Name added in v0.3.0

func (DataDog) Name() Name

Name return Logger implementation name.

func (DataDog) SpanFromContext added in v0.3.0

func (DataDog) SpanFromContext(ctx context.Context) (Span, bool)

SpanFromContext return span from context.Context.

func (DataDog) StartSpanForCommand added in v1.3.0

func (DataDog) StartSpanForCommand(ctx context.Context, action string, resolver Command)

StartSpanForCommand start a new span for a command.

type DataDogConfig

type DataDogConfig struct {
	Env     string `env:"ENV,required"`
	Service string `env:"SERVICE,required"`
	Version string

	// WithProfiler enables application profiling with Datadog's Profiler, reads
	// directly from optional environment variable WITH_PROFILER.
	// Although datadog claims low overhead with negligible impact in performance
	// for production workloads, beaware enabling it may cause performance impacts
	// in your application. We recommend enabling only when needed.
	WithProfiler bool `env:"WITH_PROFILER"`
}

DataDogConfig is the struct of config given to NewDataDog.

type Name added in v0.3.0

type Name string

Name is a string type to hold the name of Tracer implemantation.

const (
	// DataDogConfigPrefix is the prefix of datadog Environment.
	DataDogConfigPrefix = "DD_"

	// DataDogName is a string of type Name with holds the telemetry tool, which is "datadog".
	DataDogName Name = "datadog"
)
const NewRelicName Name = "newrelic"

NewRelicName is a string of type Name, which is "newrelic".

type NewRelic

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

NewRelic implements Tracer.

func NewNewRelic

func NewNewRelic() (*NewRelic, error)

NewNewRelic Create a new NewRelic instance.

func (NewRelic) Client

func (NewRelic) Client(parent *http.Client) *http.Client

Client wraps into http client Newrelic span.

func (*NewRelic) Close added in v0.2.0

func (relic *NewRelic) Close()

Close does nothing because it is not required to close connection with NewRelic Agent.

func (*NewRelic) Middleware

func (relic *NewRelic) Middleware(next http.Handler) http.Handler

Middleware add into http framework request tracing.

func (NewRelic) Name added in v0.3.0

func (NewRelic) Name() Name

Name returns the name of telemetry implementation used, this case is newrelic.

func (*NewRelic) SpanFromContext added in v0.3.0

func (relic *NewRelic) SpanFromContext(ctx context.Context) (Span, bool)

SpanFromContext does nothing it is a mock method.

func (*NewRelic) StartSpanForCommand added in v1.3.0

func (*NewRelic) StartSpanForCommand(ctx context.Context, action string, resolver Command)

StartSpanForCommand start a new span for a command.

type Span added in v0.3.0

type Span interface {
	Context() SpanContext
}

Span interface handle span usage.

type SpanContext added in v0.3.0

type SpanContext interface {
	// SpanID Return the SpanID
	SpanID() interface{}

	// TraceID returns the trace ID that this context is carrying.
	TraceID() interface{}

	ToMap() map[string]interface{}
}

SpanContext handle spans in context.

type Tracer

type Tracer interface {
	// Middleware must return a new handler with cross application tracing (CAT) or distributed tracing.
	Middleware(next http.Handler) http.Handler
	// Client wraps parent with tracing capabilities, parent is modified during this process.
	Client(parent *http.Client) *http.Client
	// Close should be called when the application end.
	Close()
	// Return the Name of Which implementation is using ex: DataDog, NewRelic
	Name() Name
	// Get SpanFromContext given
	SpanFromContext(ctx context.Context) (Span, bool)
	// StartSpanForCommand start a new span for a command.
	StartSpanForCommand(ctx context.Context, action string, resolver Command)
}

A Tracer has methods to help tracer instrumentation of our services.

Jump to

Keyboard shortcuts

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