Hi, I find Elastic APM is a very good feature. I want to instrument my go program with the Elastic APM native API or opentracing API.
I read the article here:
- https://www.elastic.co/guide/en/apm/agent/go/current/custom-instrumentation.html
- https://www.elastic.co/guide/en/apm/agent/go/1.x/opentracing.html#opentracing-apm-tags
I am still a little confused, I have configured the apm-server, es, kibana, when I run the code:
package main
import (
"context"
"go.elastic.co/apm"
"go.elastic.co/apm/module/apmot"
"github.com/opentracing/opentracing-go"
)
func main() {
opentracing.SetGlobalTracer(apmot.New())
parent, ctx := opentracing.StartSpanFromContext(context.Background(), "parent")
child, _ := opentracing.StartSpanFromContext(ctx, "child")
child.Finish()
parent.Finish()
// Transaction created through native API.
transaction := apm.DefaultTracer.StartTransaction("GET /", "request")
ctx = apm.ContextWithTransaction(context.Background(), transaction)
// Span created through OpenTracing API will be a child of the transaction.
otSpan, ctx := opentracing.StartSpanFromContext(ctx, "ot-span")
_ = otSpan
// Span created through the native API will be a child of the span created
// above via the OpenTracing API.
apmSpan, ctx := apm.StartSpan(ctx, "apm-span", "apm-span")
_ = apmSpan
}
apm-server can receive request, while the APM page in kibana show nothing.
Can someone show me a runnable example? Thanks!