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 ¶
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
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.