Skip to content

Commit 2b93770

Browse files
feat: add example for beego instrumentation (#243)
* feat: add dockerized example * chore: Update readme * fix: remove tracing on client Co-authored-by: Tyler Yahn <[email protected]>
1 parent 4e75b37 commit 2b93770

File tree

8 files changed

+503
-0
lines changed

8 files changed

+503
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright The OpenTelemetry Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
FROM golang:1.14-alpine AS base
16+
COPY . /src/
17+
WORKDIR /src/instrumentation/github.com/astaxie/beego/example
18+
19+
FROM base AS example-beego-server
20+
RUN go install ./server/server.go
21+
CMD ["/go/bin/server"]
22+
23+
FROM base AS example-http-client
24+
RUN go install ./client/client.go
25+
CMD ["/go/bin/client"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Beego Server Instrumentation Example
2+
3+
An HTTP client connects to a Beego server. They both generate span information to `stdout`.
4+
These instructions expect you have [docker-compose](https://docs.docker.com/compose/) installed.
5+
6+
Bring up the `beego-server` and `http-client` services to run the example:
7+
```sh
8+
docker-compose up -d
9+
```
10+
11+
The `http-client` service sends just one HTTP request to `beego-server` and then exits. View the span generated by `beego-server` in the logs:
12+
```sh
13+
docker-compose logs beego-server
14+
```
15+
16+
You can also visit a webpage hosted by the Beego app by navigating to `http://localhost:7777` in your browser.
17+
Two spans are created this time, one for the HTTP request, and another for rendering the template HTML. You can view the spans the same way as above.
18+
19+
Shut down the services when you are finished with the example:
20+
```sh
21+
docker-compose down
22+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright The OpenTelemetry Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package main
16+
17+
import (
18+
"flag"
19+
"fmt"
20+
"io/ioutil"
21+
"log"
22+
23+
"net/http"
24+
)
25+
26+
func main() {
27+
url := flag.String("server", "http://localhost:7777/hello", "server url")
28+
flag.Parse()
29+
30+
client := http.Client{}
31+
32+
req, err := http.NewRequest("GET", *url, nil)
33+
if err != nil {
34+
log.Fatal(err)
35+
}
36+
37+
fmt.Printf("sending request...\n")
38+
res, err := client.Do(req)
39+
if err != nil {
40+
log.Fatal(err)
41+
}
42+
43+
body, err := ioutil.ReadAll(res.Body)
44+
if err != nil {
45+
log.Fatal(err)
46+
}
47+
_ = res.Body.Close()
48+
49+
fmt.Printf("Response Received: %s\n\n\n", body)
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Copyright The OpenTelemetry Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
version: "3.7"
16+
services:
17+
beego-server:
18+
build:
19+
dockerfile: $PWD/Dockerfile
20+
context: ../../../../..
21+
target: example-beego-server
22+
command: ["/go/bin/server", "-zipkin", "zipkin:9411"]
23+
ports:
24+
- 7777:7777
25+
26+
http-client:
27+
build:
28+
dockerfile: $PWD/Dockerfile
29+
context: ../../../../..
30+
target: example-http-client
31+
command: ["/go/bin/client", "-server", "http://beego-server:7777/hello"]
32+
depends_on:
33+
- beego-server
34+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module go.opentelemetry.io/contrib/instrumentation/astaxie/beego/example
2+
3+
go 1.14
4+
5+
require (
6+
github.com/astaxie/beego v1.12.2
7+
go.opentelemetry.io/contrib/instrumentation/github.com/astaxie/beego v0.0.0-00010101000000-000000000000
8+
go.opentelemetry.io/otel v0.10.0
9+
go.opentelemetry.io/otel/exporters/stdout v0.10.0
10+
go.opentelemetry.io/otel/sdk v0.10.0
11+
)
12+
13+
replace (
14+
go.opentelemetry.io/contrib => ../../../../../
15+
go.opentelemetry.io/contrib/instrumentation/github.com/astaxie/beego => ../
16+
)

0 commit comments

Comments
 (0)