Skip to content

Commit

Permalink
feat: add example for beego instrumentation (#243)
Browse files Browse the repository at this point in the history
* feat: add dockerized example

* chore: Update readme

* fix: remove tracing on client

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
  • Loading branch information
reggiemcdonald and MrAlias authored Aug 20, 2020
1 parent 4e75b37 commit 2b93770
Show file tree
Hide file tree
Showing 8 changed files with 503 additions and 0 deletions.
25 changes: 25 additions & 0 deletions instrumentation/github.com/astaxie/beego/example/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright The OpenTelemetry Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

FROM golang:1.14-alpine AS base
COPY . /src/
WORKDIR /src/instrumentation/github.com/astaxie/beego/example

FROM base AS example-beego-server
RUN go install ./server/server.go
CMD ["/go/bin/server"]

FROM base AS example-http-client
RUN go install ./client/client.go
CMD ["/go/bin/client"]
22 changes: 22 additions & 0 deletions instrumentation/github.com/astaxie/beego/example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Beego Server Instrumentation Example

An HTTP client connects to a Beego server. They both generate span information to `stdout`.
These instructions expect you have [docker-compose](https://docs.docker.com/compose/) installed.

Bring up the `beego-server` and `http-client` services to run the example:
```sh
docker-compose up -d
```

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:
```sh
docker-compose logs beego-server
```

You can also visit a webpage hosted by the Beego app by navigating to `http://localhost:7777` in your browser.
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.

Shut down the services when you are finished with the example:
```sh
docker-compose down
```
50 changes: 50 additions & 0 deletions instrumentation/github.com/astaxie/beego/example/client/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package main

import (
"flag"
"fmt"
"io/ioutil"
"log"

"net/http"
)

func main() {
url := flag.String("server", "http://localhost:7777/hello", "server url")
flag.Parse()

client := http.Client{}

req, err := http.NewRequest("GET", *url, nil)
if err != nil {
log.Fatal(err)
}

fmt.Printf("sending request...\n")
res, err := client.Do(req)
if err != nil {
log.Fatal(err)
}

body, err := ioutil.ReadAll(res.Body)
if err != nil {
log.Fatal(err)
}
_ = res.Body.Close()

fmt.Printf("Response Received: %s\n\n\n", body)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright The OpenTelemetry Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

version: "3.7"
services:
beego-server:
build:
dockerfile: $PWD/Dockerfile
context: ../../../../..
target: example-beego-server
command: ["/go/bin/server", "-zipkin", "zipkin:9411"]
ports:
- 7777:7777

http-client:
build:
dockerfile: $PWD/Dockerfile
context: ../../../../..
target: example-http-client
command: ["/go/bin/client", "-server", "http://beego-server:7777/hello"]
depends_on:
- beego-server

16 changes: 16 additions & 0 deletions instrumentation/github.com/astaxie/beego/example/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module go.opentelemetry.io/contrib/instrumentation/astaxie/beego/example

go 1.14

require (
github.com/astaxie/beego v1.12.2
go.opentelemetry.io/contrib/instrumentation/github.com/astaxie/beego v0.0.0-00010101000000-000000000000
go.opentelemetry.io/otel v0.10.0
go.opentelemetry.io/otel/exporters/stdout v0.10.0
go.opentelemetry.io/otel/sdk v0.10.0
)

replace (
go.opentelemetry.io/contrib => ../../../../../
go.opentelemetry.io/contrib/instrumentation/github.com/astaxie/beego => ../
)
Loading

0 comments on commit 2b93770

Please sign in to comment.