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.
@hitzhangjie welcome to the forum, and thanks for trying out Elastic APM!
apm-server can receive request, while the APM page in kibana show nothing.
That's probably because your program exits before the events are sent to the server. Spans are buffered and sent in the background. You can force them to be sent by calling apm.DefaultTracer.Flush(nil) at the end of your main function.
Can someone show me a runnable example? Thanks!
package main
import (
"context"
"github.com/opentracing/opentracing-go"
"go.elastic.co/apm"
"go.elastic.co/apm/module/apmot"
)
func main() {
opentracing.SetGlobalTracer(apmot.New())
defer apm.DefaultTracer.Flush(nil)
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")
defer otSpan.Finish()
// 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")
defer apmSpan.End()
}
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.