Documentation ¶
Overview ¶
Package instabeego provides Instana instrumentation for the beego framework.
Example (HttpClientInstrumentation) ¶
This example shows how to instrument beego httplib module (HTTP client) with Instana tracing
package main import ( "context" "log" "net/http" "github.com/beego/beego/v2/client/httplib" instana "github.com/instana/go-sensor" "github.com/instana/go-sensor/instrumentation/instabeego" "github.com/opentracing/opentracing-go/ext" ) func main() { t := instana.InitCollector(&instana.Options{ Service: "my-http-client", EnableAutoProfile: true, }) // Every call should start with an entry span (https://docs.instana.io/quick_start/custom_tracing/#always-start-new-traces-with-entry-spans) // Normally this would be your HTTP/GRPC/message queue request span, but here we need to create it explicitly, since an HTTP client call is // an exit span. And all exit spans must have a parent entry span. sp := t.StartSpan("client-call") sp.SetTag(string(ext.SpanKind), "entry") defer sp.Finish() // Inject the parent span into request context ctx := instana.ContextWithSpan(context.Background(), sp) req := httplib.NewBeegoRequestWithCtx(ctx, "https://www.instana.com", http.MethodGet) instabeego.InstrumentRequest(t, req) _, err := req.Response() if err != nil { log.Fatalf("failed to GET https://www.instana.com: %s", err) } }
Output:
Example (ServerInstrumentation) ¶
This example shows how to instrument a beego web server.
// (c) Copyright IBM Corp. 2023 //go:build go1.18 // +build go1.18 package main import ( beego "github.com/beego/beego/v2/server/web" instana "github.com/instana/go-sensor" "github.com/instana/go-sensor/instrumentation/instabeego" ) // UserController represents the router for user APIs in the given example type UserController struct { beego.Controller } // GetUserById is a sample handler function for the example func (u *UserController) GetUserById() { u.Ctx.WriteString("GetUserById") } // This example shows how to instrument a beego web server. func main() { t := instana.InitCollector(&instana.Options{ Service: "beego-server", EnableAutoProfile: true, }) // This will add instana.TracingHandlerFunc() function as middleware for every API. instabeego.InstrumentWebServer(t) beego.CtrlGet("api/user/:id", (*UserController).GetUserById) beego.Run() }
Output:
Index ¶
Examples ¶
Constants ¶
View Source
const Version = "0.7.1"
Version is the instrumentation module semantic version
Variables ¶
This section is empty.
Functions ¶
func InstrumentRequest ¶
func InstrumentRequest(sensor instana.TracerLogger, req *httplib.BeegoHTTPRequest)
InstrumentRequest wrap the original BeegoHTTPRequest transport with instana.RoundTripper().
func InstrumentWebServer ¶
func InstrumentWebServer(sensor instana.TracerLogger)
InstrumentWebServer wraps beego's handlers execution. Adds tracing context and handles entry span. It should be added as a first Middleware to the beego, before defining handlers.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.