apmot

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2018 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package apmot provides an Elastic APM implementation of the OpenTracing API.

Things not implemented by this tracer:

  • binary propagation format
  • baggage
  • logging

TODO(axw)

  • update spanContext to stop storing objects once we have completed support for distributed tracing; we should only store trace context
  • investigate injecting native APM transactions/spans as the parent when starting an OT span. This probably requires extending the OT API.
Example
tracer, apmtracer, recorder := newTestTracer()
defer apmtracer.Close()
opentracing.SetGlobalTracer(tracer)
defer opentracing.SetGlobalTracer(nil)

parent := opentracing.StartSpan("Parent")
for i := 0; i < 5; i++ {
	id := fmt.Sprintf("span_%d", i)
	parent.LogEvent(fmt.Sprintf("Starting %s", id))
	child := opentracing.StartSpan(id, opentracing.ChildOf(parent.Context()))
	time.Sleep(10 * time.Millisecond)
	child.Finish()
}
parent.LogEvent("A Log")
parent.Finish()
apmtracer.Flush(nil)

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

transaction: Parent/unknown
spans:
 - span_0/unknown
 - span_1/unknown
 - span_2/unknown
 - span_3/unknown
 - span_4/unknown

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(opts ...Option) opentracing.Tracer

New returns a new opentracing.Tracer backed by the supplied Elastic APM tracer.

By default, the returned tracer will use elasticapm.DefaultTracer. This can be overridden by using a WithTracer option.

Types

type Option

type Option func(*otTracer)

Option sets options for the OpenTracing Tracer implementation.

func WithTracer

func WithTracer(t *elasticapm.Tracer) Option

WithTracer returns an Option which sets t as the underlying elasticapm.Tracer for constructing an OpenTracing Tracer.

Notes

Bugs

  • spanContext must not hold onto any transaction or span objects, as an opentracing.SpanContext may outlive the span to which it relates. To fix this, we need spans at the top level, and a means of creating them from a TraceContext.

    In most cases this is *probably* OK, because a child-of relation means that the parent span cannot be ended before the child. However, there's no guarantee that the ordering of operations on the OpenTracing API follows the ordering of the events exactly (e.g. you could complete the entire business transaction before emitting events, and then emit events for the transaction and then its spans.)

Jump to

Keyboard shortcuts

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