otlp

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2023 License: Apache-2.0 Imports: 29 Imported by: 0

README

OTLP Translator

This module provides an easy to use way of converting OTLP requests into easily ingestible data structures (eg []map[string]interface{}). This makes consuming the OTLP wire format easier and more consistent.

### Traces

You can either provide the OTLP trace request directly or a HTTP request object that contains the request in the body.

// HTTP Request
ri := GetRequestInfoFromHttpHeaders(request.header) // (request.header http.Header)
res, err := TranslateHttpTraceRequest(request.body, ri) //(request.body io.Reader, ri RequestInfo)

// OTLP Trace gRPC
res, err := TranslateGrpcTraceRequest(request) // (request *collectorTrace.ExportTraceServiceRequest)
Common

The library also includes generic ways to extract request information (API Key, Dataset, etc).

// HTTP request
requestInfo := GetRequestInfoFromHttpHeaders(header) // (header http.Header)

// gRPC request context
requestInfo := GetRequestInfoFromGrpcMetadata(ctx) // (ctx context.Context)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidContentType   = OTLPError{"unsupported content-type, valid types are: " + strings.Join(GetSupportedContentTypes(), ", "), http.StatusUnsupportedMediaType, codes.Unimplemented}
	ErrFailedParseBody      = OTLPError{"failed to parse OTLP request body", http.StatusBadRequest, codes.Internal}
	ErrMissingAPIKeyHeader  = OTLPError{"missing 'x-honeycomb-team' header", http.StatusUnauthorized, codes.Unauthenticated}
	ErrMissingDatasetHeader = OTLPError{"missing 'x-honeycomb-dataset' header", http.StatusUnauthorized, codes.Unauthenticated}
)

Functions

func AsGRPCError

func AsGRPCError(e error) error

func AsJson

func AsJson(e error) string

func BytesToTraceID

func BytesToTraceID(traceID []byte) string

BytesToTraceID returns an ID suitable for use for spans and traces. Before encoding the bytes as a hex string, we want to handle cases where we are given 128-bit IDs with zero padding, e.g. 0000000000000000f798a1e7f33c8af6. There are many ways to achieve this, but careful benchmarking and testing showed the below as the most performant, avoiding memory allocations and the use of flexible but expensive library functions. As this is hot code, it seemed worthwhile to do it this way.

func GetSupportedContentEncodings

func GetSupportedContentEncodings() []string

List of HTTP Content Encodings supported for OTLP ingest.

func GetSupportedContentTypes

func GetSupportedContentTypes() []string

List of HTTP Content Types supported for OTLP ingest.

func IsContentTypeSupported

func IsContentTypeSupported(contentType string) bool

Check whether we support a given HTTP Content Type for OTLP.

Types

type Batch

type Batch struct {
	Dataset   string
	SizeBytes int
	Events    []Event
}

Batch represents Honeycomb events grouped by their target dataset SizeBytes is the total byte size of the OTLP structure that represents this batch

type Event

type Event struct {
	Attributes   map[string]interface{}
	Timestamp    time.Time
	SampleRate   int32
	ResourceSpan *v1.ResourceSpans
}

Event represents a single Honeycomb event

type OTLPError

type OTLPError struct {
	Message        string
	HTTPStatusCode int
	GRPCStatusCode codes.Code
}

func (OTLPError) Error

func (e OTLPError) Error() string

type RequestInfo

type RequestInfo struct {
	ApiKey  string
	Dataset string

	UserAgent          string
	ContentType        string
	ContentEncoding    string
	GRPCAcceptEncoding string
}

RequestInfo represents information parsed from either HTTP headers or gRPC metadata

func GetRequestInfoFromGrpcMetadata

func GetRequestInfoFromGrpcMetadata(ctx context.Context) RequestInfo

GetRequestInfoFromGrpcMetadata parses relevant gRPC metadata from an incoming request context

func GetRequestInfoFromHttpHeaders

func GetRequestInfoFromHttpHeaders(header http.Header) RequestInfo

GetRequestInfoFromHttpHeaders parses relevant incoming HTTP headers

func (*RequestInfo) ValidateLogsHeaders

func (ri *RequestInfo) ValidateLogsHeaders() error

ValidateLogsHeaders validates required headers/metadata for a logs OTLP request

func (*RequestInfo) ValidateMetricsHeaders

func (ri *RequestInfo) ValidateMetricsHeaders() error

ValidateMetricsHeaders validates required headers/metadata for a metric OTLP request

func (*RequestInfo) ValidateTracesHeaders

func (ri *RequestInfo) ValidateTracesHeaders() error

ValidateTracesHeaders validates required headers/metadata for a trace OTLP request

type TranslateOTLPRequestResult

type TranslateOTLPRequestResult struct {
	RequestSize int
	Batches     []Batch
}

TranslateOTLPRequestResult represents an OTLP request translated into Honeycomb-friendly structure RequestSize is total byte size of the entire OTLP request Batches represent events grouped by their target dataset

func TranslateLogsRequest

TranslateLogsRequest translates an OTLP proto log request into Honeycomb-friendly structure RequestInfo is the parsed information from the gRPC metadata

func TranslateLogsRequestFromReader

func TranslateLogsRequestFromReader(body io.ReadCloser, ri RequestInfo) (*TranslateOTLPRequestResult, error)

TranslateLogsRequestFromReader translates an OTLP log request into Honeycomb-friendly structure from a reader (eg HTTP body) RequestInfo is the parsed information from the gRPC metadata

func TranslateTraceRequest

TranslateTraceRequest translates an OTLP/gRPC request into Honeycomb-friendly structure RequestInfo is the parsed information from the gRPC metadata

func TranslateTraceRequestFromReader

func TranslateTraceRequestFromReader(body io.ReadCloser, ri RequestInfo) (*TranslateOTLPRequestResult, error)

TranslateTraceRequestFromReader translates an OTLP/HTTP request into Honeycomb-friendly structure RequestInfo is the parsed information from the HTTP headers

Jump to

Keyboard shortcuts

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