Skip to content

Commit

Permalink
OSS
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelperel committed May 12, 2021
0 parents commit 9d1eba6
Show file tree
Hide file tree
Showing 15 changed files with 702 additions and 0 deletions.
1 change: 1 addition & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FROM mperel/dev-container
73 changes: 73 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// For format details, see https://aka.ms/vscode-remote/devcontainer.json or the definition README at
// https://github.com/microsoft/vscode-dev-containers/tree/master/containers/docker-existing-dockerfile
{
"name": "Dev Dockerfile",
"dockerFile": "Dockerfile",
// The optional 'runArgs' property can be used to specify additional runtime arguments.
"runArgs": [
// Enable go debugger
"--cap-add=SYS_PTRACE",
"--security-opt",
"seccomp=unconfined",
// map host docker daemon into container for sibling containers
"-v",
"/var/run/docker.sock:/var/run/docker.sock",
"--network",
"host"
],
"settings": {
// General settings
"files.eol": "\n",
"terminal.integrated.shell.linux": "/bin/bash",
// Go settings
"go.lintTool": "golangci-lint",
"go.lintFlags": [
"--fast"
],
"vim.insertModeKeyBindings": [
{
"before": [
"j",
"j"
],
"after": [
"<Esc>"
]
}
],
// Go recommended settings with modules: https://github.com/golang/tools/blob/master/gopls/doc/vscode.md#vscode
"go.useLanguageServer": true,
"[go]": {
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true,
},
// Optional: Disable snippets, as they conflict with completion ranking.
"editor.snippetSuggestions": "none",
},
"[go.mod]": {
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true,
},
},
"gopls": {
// Add parameter placeholders when completing a function.
"usePlaceholders": true,
// Allow multiple modules
"experimentalWorkspaceModule": true,
},
// Python settings
"python.pythonPath": "/usr/bin/python",
"python.formatting.blackPath": "/usr/local/bin/black",
"python.formatting.provider": "black",
"[python]": {
"editor.formatOnSave": true,
}
},
"extensions": [
"golang.go",
"ms-python.python",
"vscodevim.vim",
]
}
70 changes: 70 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# What is this?
This is a demo of Open Telemetry's distributed tracing capabilities.
In `docker-compose.yml` there are variety of services:
* `server` - a service that implements an http server
* `client` - a service that sends a few requests to the server
* `jaeger` - an open source telemetry backend
* `zipkin` - an open source telemetry backend
* `otel-agent` - a service that receives traces from `server` and `client`
* `otel-collector` - a service that receives traces forwarded from `otel-agent`
and exports them to `jaeger` and `zipkin`

# Why is this interesting?
By using Open Telemetry with the agent and collector, backends are swappable
and all services handle tracing in the same way, regardless of language.

Specifically, applications send traces to the agent, which forwards them to the
collector, and the collector defines backends via exporters in yaml.

Here we use 2 exporters, `jaeger` and `zipkin`, but there are many possible
exporters including
[Azure Monitor](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/exporter/azuremonitorexporter).

# How to use?
`docker-compose up --build` brings up all services.
The `client` sends a few requests to `server`. The distributed traces appear in
`jaeger` and `zipkin`.

`jaeger` can be accessed at `http://localhost:16686`.

`zipkin` can be accessed at `http://localhost:9411`.

`docker-compose down` cleans up all resources.

If you would like to manually make requests to the server after the client ends,
navigate to `http://localhost:8080/hello`.

After requests have been made, if you choose the `client` service in `jaeger`,
you should see something similar to:

![Overview](./docs/jaeger.png)

Note that you can see all traces that started from the client. If you click on
a trace, you can see the distributed spans that make up the trace:

![Spans](./docs/jaeger-span.png)

# How to navigate the code?
Start by reading the comments in `src/cmd/client/client.go`.
They describe how to create a trace that propagates to the server over
an http request.

Next, read the comments in `src/cmd/server/server.go`. They describe
how the propagated trace is used in subsequent spans.

Finally, read the comments in `src/pkg/tracer_provider/tracer_provider.go`. They
describe boilerplate code that sets up a tracer provider for each application.

# Development
A dev container has been provided. To use:
* Ensure the `Remote - Containers` extension is installed in VSCode
* Open the project in the container
* Install the Go extension libraries with `Go: Install/Update tools` from
the command palette

# Citations
The collector code is adapted from
[this official otel example](https://github.com/open-telemetry/opentelemetry-collector/tree/main/examples/demo).

The client / server code is adapted from
[this official otel example](https://github.com/open-telemetry/opentelemetry-go-contrib/tree/main/instrumentation/net/http/otelhttp/example).
44 changes: 44 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
version: "3"
services:
jaeger:
image: jaegertracing/all-in-one@sha256:710ddea40c84ce01acdb9fdb4c0a76ac11990e425a666968a3ae360dabc4e15f
ports:
- "16686:16686"
zipkin:
image: openzipkin/zipkin@sha256:1ae0572be3d26fd9ab3fd2da5e8feaa0ca0078dbc31e2ddfb881b1a56bc332b1
ports:
- "9411:9411"
otel-collector:
image: otel/opentelemetry-collector@sha256:6f1c53a611091402f0403b628554621591effc7cf88e94be1f9141be007d11c7
command: ["--config=/etc/otel-collector-config.yaml"]
volumes:
- ./otel-collector-config.yaml:/etc/otel-collector-config.yaml
depends_on:
- jaeger
- zipkin
otel-agent:
image: otel/opentelemetry-collector@sha256:6f1c53a611091402f0403b628554621591effc7cf88e94be1f9141be007d11c7
command: ["--config=/etc/otel-agent-config.yaml"]
volumes:
- ./otel-agent-config.yaml:/etc/otel-agent-config.yaml
depends_on:
- otel-collector
client:
command: ["/app/client"]
build:
context: ./src
args:
CMD: client
depends_on:
- otel-agent
- server
server:
command: ["/app/server"]
build:
context: ./src
args:
CMD: server
ports:
- "8080:8080"
depends_on:
- otel-agent
58 changes: 58 additions & 0 deletions docker-lock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"composefiles": {
"docker-compose.yaml": [
{
"name": "golang",
"tag": "latest",
"digest": "04b95d37ab61bd05b6f163383dbd54da4553be2b427b8980a72f778be4edec6b",
"dockerfile": "src/Dockerfile",
"service": "client"
},
{
"name": "scratch",
"tag": "",
"digest": "",
"dockerfile": "src/Dockerfile",
"service": "client"
},
{
"name": "jaegertracing/all-in-one",
"tag": "latest",
"digest": "710ddea40c84ce01acdb9fdb4c0a76ac11990e425a666968a3ae360dabc4e15f",
"service": "jaeger"
},
{
"name": "otel/opentelemetry-collector",
"tag": "latest",
"digest": "6f1c53a611091402f0403b628554621591effc7cf88e94be1f9141be007d11c7",
"service": "otel-agent"
},
{
"name": "otel/opentelemetry-collector",
"tag": "latest",
"digest": "6f1c53a611091402f0403b628554621591effc7cf88e94be1f9141be007d11c7",
"service": "otel-collector"
},
{
"name": "golang",
"tag": "latest",
"digest": "04b95d37ab61bd05b6f163383dbd54da4553be2b427b8980a72f778be4edec6b",
"dockerfile": "src/Dockerfile",
"service": "server"
},
{
"name": "scratch",
"tag": "",
"digest": "",
"dockerfile": "src/Dockerfile",
"service": "server"
},
{
"name": "openzipkin/zipkin",
"tag": "latest",
"digest": "1ae0572be3d26fd9ab3fd2da5e8feaa0ca0078dbc31e2ddfb881b1a56bc332b1",
"service": "zipkin"
}
]
}
}
Binary file added docs/jaeger-span.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/jaeger.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions otel-agent-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
receivers:
otlp:
protocols:
grpc:
jaeger:
protocols:
grpc:
zipkin:

exporters:
otlp:
endpoint: "otel-collector:4317"
insecure: true
logging:
loglevel: debug

processors:
batch:

service:
pipelines:
traces:
receivers: [otlp, jaeger, zipkin]
processors: [batch]
exporters: [otlp, logging]
25 changes: 25 additions & 0 deletions otel-collector-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
receivers:
otlp:
protocols:
grpc:

exporters:
logging:

zipkin:
endpoint: "http://zipkin:9411/api/v2/spans"
format: proto

jaeger:
endpoint: "jaeger:14250"
insecure: true

processors:
batch:

service:
pipelines:
traces:
receivers: [otlp]
processors: [batch]
exporters: [logging, jaeger, zipkin]
14 changes: 14 additions & 0 deletions src/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM golang@sha256:04b95d37ab61bd05b6f163383dbd54da4553be2b427b8980a72f778be4edec6b AS builder
WORKDIR /app
COPY go.mod .
COPY go.sum .
RUN go mod download
COPY . .

FROM builder AS prodBuilder
ARG CMD
RUN CGO_ENABLED=0 go build -ldflags="-w -s" "./cmd/${CMD}"

FROM scratch AS prod
ARG CMD
COPY --from=prodBuilder "/app/${CMD}" "/app/${CMD}"
Loading

0 comments on commit 9d1eba6

Please sign in to comment.