apmotel

package module
v2.4.4 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2023 License: Apache-2.0 Imports: 21 Imported by: 2

Documentation

Overview

Package apmotel provides helpers for exporting OpenTelemetry data to the Elastic APM Agent.

Example
apmtracer, recorder := transporttest.NewRecorderTracer()
provider, err := NewTracerProvider(WithAPMTracer(apmtracer))
if err != nil {
	log.Fatal(err)
}
otel.SetTracerProvider(provider)
defer apmtracer.Close()
tracer := provider.Tracer("example")

ctx := context.Background()
ctx, parent := tracer.Start(ctx, "parent")

for i := 0; i < 5; i++ {
	id := fmt.Sprintf("span_%d", i)
	_, child := tracer.Start(ctx, id)
	time.Sleep(10 * time.Millisecond)
	child.End()
}
parent.End()
apmtracer.Flush(nil)

payloads := recorder.Payloads()
if len(payloads.Transactions) != 1 {
	panic(fmt.Errorf("expected 1 transaction, got %d", len(payloads.Transactions)))
}
for _, transaction := range payloads.Transactions {
	fmt.Printf("transaction: %s/%s\n", transaction.Name, transaction.Type)
}
for _, span := range payloads.Spans {
	fmt.Printf("span: %s/%s\n", span.Name, span.Type)
}
Output:

transaction: parent/unknown
span: span_0/custom
span: span_1/custom
span: span_2/custom
span: span_3/custom
span: span_4/custom

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewTracerProvider

func NewTracerProvider(opts ...TracerProviderOption) (trace.TracerProvider, error)

NewTracerProvider creates a new tracer provider which acts as a bridge with the Elastic Agent tracer.

Types

type Gatherer

type Gatherer struct {
	metric.Reader
}

Gatherer is a gatherer/exporter which can act as an OpenTelemetry manual reader, to retrieve metrics and expose them to the agent.

func NewGatherer

func NewGatherer(opts ...GathererOption) (Gatherer, error)

NewGatherer creates a new gatherer/exporter to bridge between agent metrics and OpenTelemetry

func (Gatherer) GatherMetrics

func (e Gatherer) GatherMetrics(ctx context.Context, out *apm.Metrics) error

GatherMetrics gathers metrics into out.

type GathererOption

type GathererOption func(gathererConfig) gathererConfig

func WithAggregationSelector

func WithAggregationSelector(agg metric.AggregationSelector) GathererOption

WithAggregationSelector configure the Aggregation Selector the exporter will use. If no AggregationSelector is provided the DefaultAggregationSelector is used.

func WithTemporalitySelector added in v2.4.2

func WithTemporalitySelector(temporality metric.TemporalitySelector) GathererOption

WithTemporalitySelector configure the Aggregation Selector the exporter will use. If no AggregationSelector is provided the DefaultAggregationSelector is used.

type TracerProviderOption

type TracerProviderOption func(tracerProviderConfig) tracerProviderConfig

func WithAPMTracer

func WithAPMTracer(t *apm.Tracer) TracerProviderOption

WithAPMTracer configures a custom apm.Tracer which will be used as the tracing bridge.

func WithResource added in v2.4.2

func WithResource(r *resource.Resource) TracerProviderOption

WithResource configures the provided resource, which will be referenced by all tracers this provider creates.

If this option is not used, the TracerProvider will use the defaultResource() Resource by default.

Jump to

Keyboard shortcuts

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