diff --git a/instrumentation/instabeego/README.md b/instrumentation/instabeego/README.md new file mode 100644 index 000000000..51fdb1e56 --- /dev/null +++ b/instrumentation/instabeego/README.md @@ -0,0 +1,71 @@ +Instana instrumentation for Beego framework +============================================= + +This module contains middleware to instrument HTTP services written with [`https://github.com/beego/beego`](https://github.com/beego/beego). + +[![PkgGoDev](https://pkg.go.dev/badge/github.com/instana/go-sensor/instrumentation/instabeego)][godoc] + +Installation +------------ + +To add the module to your `go.mod` file run the following command in your project directory: + +```bash +$ go get github.com/instana/go-sensor/instrumentation/instabeego +``` + +Usage +----- + +## Web server instrumentation + +```go +// create a sensor +t := instana.InitCollector(&instana.Options{ + Service: "beego-server", + EnableAutoProfile: true, +}) + +// instrument the web server +instabeego.InstrumentWebServer(t) + +// define API +beego.Get("/foo", func(ctx *beecontext.Context) {/* ... */}) + +// Run beego application +beego.Run() +// ... +``` +[Full example][serverInstrumentationExample] + +## HTTP client instrumentation + +```go +// create a sensor +t := instana.InitCollector(&instana.Options{ + Service: "my-http-client", + EnableAutoProfile: true, +}) + +// get the parent span and inject into the request context +ctx := instana.ContextWithSpan(context.Background(), /* parent span */) + +// create a new http request using beego +req := httplib.NewBeegoRequestWithCtx(ctx, "https://www.instana.com", http.MethodGet) + +// instrument the client request +instabeego.InstrumentRequest(sensor, req) + +// execute the client request and get the response +_, err := req.Response() +// ... +``` + +[Full example][clientInstrumentationExample] + + + + +[godoc]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instabeego +[serverInstrumentationExample]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instabeego#example-package-ServerInstrumentation +[clientInstrumentationExample]: https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instabeego#example-package-HttpClientInstrumentation diff --git a/instrumentation/instabeego/example_http_client_test.go b/instrumentation/instabeego/example_http_client_test.go index adc74ae4f..576f9f386 100644 --- a/instrumentation/instabeego/example_http_client_test.go +++ b/instrumentation/instabeego/example_http_client_test.go @@ -18,12 +18,15 @@ import ( // This example shows how to instrument beego httplib module (HTTP client) with Instana tracing func Example_httpClientInstrumentation() { - sensor := instana.NewSensor("my-http-client") + 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 := sensor.Tracer().StartSpan("client-call") + sp := t.StartSpan("client-call") sp.SetTag(string(ext.SpanKind), "entry") defer sp.Finish() @@ -32,7 +35,7 @@ func Example_httpClientInstrumentation() { ctx := instana.ContextWithSpan(context.Background(), sp) req := httplib.NewBeegoRequestWithCtx(ctx, "https://www.instana.com", http.MethodGet) - instabeego.InstrumentRequest(sensor, req) + instabeego.InstrumentRequest(t, req) _, err := req.Response() if err != nil { diff --git a/instrumentation/instabeego/example_web_server_test.go b/instrumentation/instabeego/example_web_server_test.go index d5f4ab6d5..668026e9c 100644 --- a/instrumentation/instabeego/example_web_server_test.go +++ b/instrumentation/instabeego/example_web_server_test.go @@ -23,9 +23,12 @@ func (u *UserController) GetUserById() { // This example shows how to instrument a beego web server. func Example_serverInstrumentation() { - sensor := instana.NewSensor("my-web-server") + t := instana.InitCollector(&instana.Options{ + Service: "beego-server", + EnableAutoProfile: true, + }) // This will add instana.TracingHandlerFunc() function as middleware for every API. - instabeego.InstrumentWebServer(sensor) + instabeego.InstrumentWebServer(t) beego.CtrlGet("api/user/:id", (*UserController).GetUserById) beego.Run()