otel

package
v0.2.0-alpha Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2022 License: MIT Imports: 17 Imported by: 1

Documentation

Overview

Package otel implements conversion from Telemetry API events into OpenTelemetry trace spans. https://docs.aws.amazon.com/lambda/latest/dg/telemetry-otel-spans.html

Package otel can be used with OpenTelemetry compatible exporter to send traces to any destinations. https://github.com/open-telemetry/opentelemetry-go/tree/main/exporters

End-to-end example is available in examples/telemetry-otel-trace-exporter

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EventTriplet

type EventTriplet struct {
	Type        telemetryapi.Phase
	Start       telemetryapi.Event
	RuntimeDone telemetryapi.Event
	Report      telemetryapi.Event
	PrevSC      trace.SpanContext
}

EventTriplet contains chain of events from single Lambda function invocation.

func (EventTriplet) IsValid

func (t EventTriplet) IsValid() bool

IsValid checks that received events match and in-order.

type Option

type Option interface {
	// contains filtered or unexported methods
}

func WithLogger

func WithLogger(log logr.Logger) Option

type Processor

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

Processor implements telemetryapi.Processor interface to export Telemetry API events as OpenTelemetry spans through a given exporter. Processor should be passed into telemetryapi.Run instead of direct usage.

Example
package main

import (
	"context"
	"log"

	"github.com/zakharovvi/aws-lambda-extensions/telemetryapi"
	"github.com/zakharovvi/aws-lambda-extensions/telemetryapi/otel"
	"go.opentelemetry.io/otel/exporters/stdout/stdouttrace"
)

func main() {
	exporter, err := stdouttrace.New(stdouttrace.WithPrettyPrint())
	if err != nil {
		log.Panic(err)
	}

	ctx := context.Background()
	processor := otel.NewProcessor(ctx, exporter)

	if err := telemetryapi.Run(ctx, processor); err != nil {
		log.Panic(err)
	}
}
Output:

func NewProcessor

func NewProcessor(ctx context.Context, exporter sdktrace.SpanExporter, opts ...Option) *Processor

NewProcessor creates Processor with provided sdktrace.SpanExporter.

func (*Processor) Init

func (proc *Processor) Init(ctx context.Context, registerResp *extapi.RegisterResponse) error

func (*Processor) Process

func (proc *Processor) Process(ctx context.Context, event telemetryapi.Event) error

func (*Processor) Shutdown

func (proc *Processor) Shutdown(ctx context.Context, reason extapi.ShutdownReason, err error) error

type SpanConverter

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

SpanConverter creates OpenTelemetry spans from Telemetry API events. SpanConverter is low-level, consider using Processor instead.

Example
ctx := context.Background()
// 1. get metadata
// In real-world it is done in telemetryapi.Processor.Process()
registerResp := &extapi.RegisterResponse{}

// 2. create span spanConverter
spanConverter := otel.NewSpanConverter(ctx, registerResp)

// 3. receive events.
// In real-world it is done in telemetryapi.Processor.Process()
triplet := getInvokeTriplet()

// 4. convert events into opentelemetry spans
spans, _, err := spanConverter.ConvertIntoSpans(triplet)
if err != nil {
	log.Panic(err)
}

// 5. send events to sdktrace.SpanExporter
// https://github.com/open-telemetry/opentelemetry-go/tree/main/exporters
exporter, err := stdouttrace.New(stdouttrace.WithPrettyPrint())
if err != nil {
	log.Panic(err)
}
if err := exporter.ExportSpans(ctx, spans); err != nil {
	log.Panic(err)
}
if err := exporter.Shutdown(ctx); err != nil {
	log.Panic(err)
}
Output:

func NewSpanConverter

func NewSpanConverter(ctx context.Context, registerResp *extapi.RegisterResponse, opts ...Option) *SpanConverter

NewSpanConverter creates SpanConverter.

func (*SpanConverter) ConvertIntoSpans

func (sc *SpanConverter) ConvertIntoSpans(triplet EventTriplet) ([]sdktrace.ReadOnlySpan, trace.SpanContext, error)

ConvertIntoSpans creates OpenTelemetry spans from provided triplet of Telemetry API events. https://docs.aws.amazon.com/lambda/latest/dg/telemetry-otel-spans.html

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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