Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added README file for instabeego package #487

Merged
merged 2 commits into from
Nov 20, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
added review changes
Angith committed Nov 20, 2023
commit a8f00578d076afb3bce35e954f2963eb89d264d4
12 changes: 9 additions & 3 deletions instrumentation/instabeego/README.md
Original file line number Diff line number Diff line change
@@ -21,10 +21,13 @@ Usage

```go
// create a sensor
sensor := instana.NewSensor("beego-server")
t := instana.InitCollector(&instana.Options{
Service: "beego-server",
EnableAutoProfile: true,
})

// instrument the web server
instabeego.InstrumentWebServer(sensor)
instabeego.InstrumentWebServer(t)

// define API
beego.Get("/foo", func(ctx *beecontext.Context) {/* ... */})
@@ -39,7 +42,10 @@ beego.Run()

```go
// create a sensor
sensor := instana.NewSensor("my-http-client")
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 */)
9 changes: 6 additions & 3 deletions instrumentation/instabeego/example_http_client_test.go
Original file line number Diff line number Diff line change
@@ -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 {
7 changes: 5 additions & 2 deletions instrumentation/instabeego/example_web_server_test.go
Original file line number Diff line number Diff line change
@@ -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()