otlpclient

package
v0.4.5 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2024 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Overview

Package otlpclient implements a simple OTLP client, directly working with protobuf, gRPC, and net/http with minimal abstractions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnyValueToString added in v0.4.5

func AnyValueToString(v *commonpb.AnyValue) string

AnyValueToString coverts a commonpb.KeyValue attribute to a string.

func GenerateSpanId

func GenerateSpanId() []byte

GenerateSpanId generates a random 8 byte span id

func GenerateTraceId

func GenerateTraceId() []byte

GenerateTraceId generates a random 16 byte trace id

func GetEmptySpanId

func GetEmptySpanId() []byte

GetEmptySpanId returns an 8-byte span id that's all zeroes.

func GetEmptyTraceId

func GetEmptyTraceId() []byte

GetEmptyTraceId returns a 16-byte trace id that's all zeroes.

func NewProtobufSpan

func NewProtobufSpan() *tracepb.Span

NewProtobufSpan returns an initialized OpenTelemetry protobuf Span.

func NewProtobufSpanEvent

func NewProtobufSpanEvent() *tracepb.Span_Event

NewProtobufSpanEvent creates a new span event protobuf struct with reasonable defaults and returns it.

func ResourceAttributesToStringMap

func ResourceAttributesToStringMap(rss *tracepb.ResourceSpans) map[string]string

ResourceAttributesToStringMap converts the ResourceSpan's resource attributes to a string map. Only used by tests for now.

func SaveError

func SaveError(ctx context.Context, t time.Time, err error) (context.Context, error)

SaveError writes the provided error to the ErrorList in ctx, returning an updated ctx.

func SendSpan

func SendSpan(ctx context.Context, client OTLPClient, config OTLPConfig, span *tracepb.Span) (context.Context, error)

SendSpan connects to the OTLP server, sends the span, and disconnects.

func SetSpanStatus

func SetSpanStatus(span *tracepb.Span, status string, message string)

SetSpanStatus checks for status code error in the config and sets the span's 2 values as appropriate. Only set status description when an error status. https://github.com/open-telemetry/opentelemetry-specification/blob/480a19d702470563d32a870932be5ddae798079c/specification/trace/api.md#set-status

func SpanAttributesToStringMap

func SpanAttributesToStringMap(span *tracepb.Span) map[string]string

SpanAttributesToStringMap converts the span's attributes to a string map.

func SpanKindIntToString

func SpanKindIntToString(kind tracepb.Span_SpanKind) string

SpanKindIntToString takes an integer/constant protobuf span kind value and returns the string representation used in otel-cli.

func SpanKindStringToInt

func SpanKindStringToInt(kind string) tracepb.Span_SpanKind

SpanKindIntToString takes a string representation of a span kind and returns the OTel protobuf integer/constant.

func SpanStatusStringToInt

func SpanStatusStringToInt(status string) tracepb.Status_StatusCode

SpanStatusStringToInt takes a supported string span status and returns the otel constant for it. Returns default of Unset on no match.

func SpanToStringMap

func SpanToStringMap(span *tracepb.Span, rss *tracepb.ResourceSpans) map[string]string

SpanToStringMap converts a span with some extra data into a stringmap. Only used by tests for now.

func StringMapAttrsToProtobuf

func StringMapAttrsToProtobuf(attributes map[string]string) []*commonpb.KeyValue

StringMapAttrsToProtobuf takes a map of string:string, such as that from --attrs and returns them in an []*commonpb.KeyValue

func TraceparentFromProtobufSpan

func TraceparentFromProtobufSpan(span *tracepb.Span, recording bool) traceparent.Traceparent

TraceparentFromProtobufSpan builds a Traceparent struct from the provided span.

Types

type ErrorList

type ErrorList []TimestampedError

ErrorList is a list of TimestampedError

func GetErrorList

func GetErrorList(ctx context.Context) ErrorList

GetErrorList retrieves the error list from context and returns it. If the list is uninitialized, it initializes it in the returned context.

type GrpcClient

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

GrpcClient holds the state for gRPC connections.

func NewGrpcClient

func NewGrpcClient(config OTLPConfig) *GrpcClient

NewGrpcClient returns a fresh GrpcClient ready to Start.

func (*GrpcClient) Start

func (gc *GrpcClient) Start(ctx context.Context) (context.Context, error)

Start configures and starts the connection to the gRPC server in the background.

func (*GrpcClient) Stop

func (gc *GrpcClient) Stop(ctx context.Context) (context.Context, error)

Stop closes the connection to the gRPC server.

func (*GrpcClient) UploadTraces

func (gc *GrpcClient) UploadTraces(ctx context.Context, rsps []*tracepb.ResourceSpans) (context.Context, error)

UploadTraces takes a list of protobuf spans and sends them out, doing retries on some errors as needed. TODO: look into grpc.WaitForReady(), esp for status use cases

type HttpClient

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

HttpClient holds state information for HTTP/OTLP.

func NewHttpClient

func NewHttpClient(config OTLPConfig) *HttpClient

NewHttpClient returns an initialized HttpClient.

func (*HttpClient) Start

func (hc *HttpClient) Start(ctx context.Context) (context.Context, error)

Start sets up the client configuration. TODO: see if there's a way to background start http2 connections?

func (*HttpClient) Stop

func (hc *HttpClient) Stop(ctx context.Context) (context.Context, error)

Stop does nothing for HTTP, for now. It exists to fulfill the interface.

func (*HttpClient) UploadTraces

func (hc *HttpClient) UploadTraces(ctx context.Context, rsps []*tracepb.ResourceSpans) (context.Context, error)

UploadTraces sends the protobuf spans up to the HTTP server.

type NullClient

type NullClient struct{}

NullClient is an OTLP client backend for non-recording mode that drops all data and never returns errors.

func NewNullClient

func NewNullClient(config OTLPConfig) *NullClient

NewNullClient returns a fresh NullClient ready to Start.

func (*NullClient) Start

func (nc *NullClient) Start(ctx context.Context) (context.Context, error)

Start fulfills the interface and does nothing.

func (*NullClient) Stop

func (gc *NullClient) Stop(ctx context.Context) (context.Context, error)

Stop fulfills the interface and does nothing.

func (*NullClient) UploadTraces

func (nc *NullClient) UploadTraces(ctx context.Context, rsps []*tracepb.ResourceSpans) (context.Context, error)

UploadTraces fulfills the interface and does nothing.

type OTLPClient

type OTLPClient interface {
	Start(context.Context) (context.Context, error)
	UploadTraces(context.Context, []*tracepb.ResourceSpans) (context.Context, error)
	Stop(context.Context) (context.Context, error)
}

OTLPClient is an interface that allows for StartClient to return either gRPC or HTTP clients.

type OTLPConfig

type OTLPConfig interface {
	GetTlsConfig() *tls.Config
	GetIsRecording() bool
	GetEndpoint() *url.URL
	GetInsecure() bool
	GetTimeout() time.Duration
	GetHeaders() map[string]string
	GetVersion() string
	GetServiceName() string
}

OTLPConfig interface defines all of the methods required to configure OTLP clients.

type SpanConfig

type SpanConfig interface {
}

type TimestampedError

type TimestampedError struct {
	Timestamp time.Time `json:"timestamp"`
	Error     string    `json:"error"`
}

TimestampedError is a timestamp + error string, to be stored in an ErrorList

Jump to

Keyboard shortcuts

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