Documentation ¶
Overview ¶
Package otlpclient implements a simple OTLP client, directly working with protobuf, gRPC, and net/http with minimal abstractions.
Index ¶
- func AnyValueToString(v *commonpb.AnyValue) string
- func GenerateSpanId() []byte
- func GenerateTraceId() []byte
- func GetEmptySpanId() []byte
- func GetEmptyTraceId() []byte
- func NewProtobufSpan() *tracepb.Span
- func NewProtobufSpanEvent() *tracepb.Span_Event
- func ResourceAttributesToStringMap(rss *tracepb.ResourceSpans) map[string]string
- func SaveError(ctx context.Context, t time.Time, err error) (context.Context, error)
- func SendSpan(ctx context.Context, client OTLPClient, config OTLPConfig, span *tracepb.Span) (context.Context, error)
- func SetSpanStatus(span *tracepb.Span, status string, message string)
- func SpanAttributesToStringMap(span *tracepb.Span) map[string]string
- func SpanKindIntToString(kind tracepb.Span_SpanKind) string
- func SpanKindStringToInt(kind string) tracepb.Span_SpanKind
- func SpanStatusStringToInt(status string) tracepb.Status_StatusCode
- func SpanToStringMap(span *tracepb.Span, rss *tracepb.ResourceSpans) map[string]string
- func StringMapAttrsToProtobuf(attributes map[string]string) []*commonpb.KeyValue
- func TraceparentFromProtobufSpan(span *tracepb.Span, recording bool) traceparent.Traceparent
- type ErrorList
- type GrpcClient
- type HttpClient
- type NullClient
- type OTLPClient
- type OTLPConfig
- type SpanConfig
- type TimestampedError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AnyValueToString ¶ added in v0.4.5
AnyValueToString coverts a commonpb.KeyValue attribute to a string.
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
SpanToStringMap converts a span with some extra data into a stringmap. Only used by tests for now.
func StringMapAttrsToProtobuf ¶
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 ¶
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 ¶
Start configures and starts the connection to the gRPC server in the background.
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 ¶
Start sets up the client configuration. TODO: see if there's a way to background start http2 connections?
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) 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 ¶
TimestampedError is a timestamp + error string, to be stored in an ErrorList