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

OpenTelemetry Collector Demo #711

Merged
merged 40 commits into from
May 20, 2020
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
c6c841f
add simple demo for connecting to collector
stefanprisca May 8, 2020
a27a37e
Update main.go
stefanprisca May 8, 2020
ae195db
Merge branch 'master' of https://github.com/open-telemetry/openteleme…
stefanprisca May 11, 2020
7b5aa0c
Merge branch 'otel-collector-demo' of github.com:stefanprisca/opentel…
stefanprisca May 11, 2020
8921ddf
Add readme to the example
stefanprisca May 11, 2020
74347ef
Mention default config
stefanprisca May 11, 2020
be01af5
small rephrasing
stefanprisca May 11, 2020
af769b8
Otel collector demo
stefanprisca May 11, 2020
97f8856
fix readme
stefanprisca May 11, 2020
105e0df
precommit
stefanprisca May 11, 2020
6ba5818
Update example/otel-collector/README.md
stefanprisca May 12, 2020
4c7262b
Update example/otel-collector/README.md
stefanprisca May 12, 2020
e2e4e77
Update example/otel-collector/README.md
stefanprisca May 12, 2020
7db551e
Update example/otel-collector/README.md
stefanprisca May 12, 2020
9c442a0
Update example/otel-collector/README.md
stefanprisca May 12, 2020
95888a7
Update example/otel-collector/README.md
stefanprisca May 12, 2020
a81fb66
Update example/otel-collector/README.md
stefanprisca May 12, 2020
1e878b9
Update example/otel-collector/README.md
stefanprisca May 12, 2020
4c1109b
Update example/otel-collector/README.md
stefanprisca May 12, 2020
41ca31f
Update example/otel-collector/main.go
stefanprisca May 12, 2020
a09fd99
Update example/otel-collector/main.go
stefanprisca May 12, 2020
bbb7763
add full collector config
stefanprisca May 13, 2020
d69386f
add resource attributes to provider
stefanprisca May 13, 2020
5e717aa
Merge branch 'master' of https://github.com/open-telemetry/openteleme…
stefanprisca May 13, 2020
af27b43
Merge branch 'master' of github.com:stefanprisca/opentelemetry-go int…
stefanprisca May 13, 2020
46477e2
fix precommit
stefanprisca May 13, 2020
e9f185c
add k8s files
stefanprisca May 14, 2020
2c71898
Merge branch 'master' of https://github.com/open-telemetry/openteleme…
stefanprisca May 14, 2020
2e6011d
change collector image
stefanprisca May 14, 2020
612e894
fix otlp receiver endpoint
stefanprisca May 14, 2020
d623815
Update README with latest changes
stefanprisca May 15, 2020
107e926
Merge branch 'master' of https://github.com/open-telemetry/openteleme…
stefanprisca May 15, 2020
e31b093
change api/core package to api/kv
stefanprisca May 15, 2020
2a00038
Update example/otel-collector/k8s/namespace.yaml
stefanprisca May 16, 2020
c80ed29
Update example/otel-collector/k8s/otel-collector.yaml
stefanprisca May 16, 2020
8bcefd4
remove unnecessary jaeger files & add licence header
stefanprisca May 16, 2020
7c9f069
Update Makefile
stefanprisca May 19, 2020
1f16b8a
Merge branch 'master' of https://github.com/open-telemetry/openteleme…
stefanprisca May 20, 2020
e1b144e
Wait for batcher to push changes
stefanprisca May 20, 2020
3f24acf
Merge branch 'master' of github.com:stefanprisca/opentelemetry-go int…
stefanprisca May 20, 2020
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ coverage.*
/example/namedtracer/namedtracer
/example/prometheus/prometheus
/example/zipkin/zipkin
/example/otel-collector/otel-collector
92 changes: 92 additions & 0 deletions example/otel-collector/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# OpenTelemetry Collector Traces Example

This example illustrates how to export traces from the OpenTelemetry-Go SDK to the OpenTelemetry Collector, and from there to a Jaeger instance.
The complete flow is:

`otel-collector-demo -> otel-collector -> Jaeger`

# Prerequisites

The demo assumes you already have both an instance of the OpenTelemetry Collector and Jaeger up and running.
For information about how to set these up, please follow the corresponding documentation:

* Jaeger: https://www.jaegertracing.io/docs/1.17/getting-started/
* OpenTelemetry Collector: https://opentelemetry.io/docs/collector/about/

Moreover, this demo is built on a Kubernetes cluster running both the OpenTelemetry Collector, and Jaeger.
Therefore, the included OpenTelemetry Collector configuration is a Kubernetes `ConfigMap`.
However, the main concepts should be transferable to any other platform you want to run this demo on.

# Configuring the OTEL Collector

In order to enable our application to send traces to the OpenTelemetry Collector, we need to first configure the OTLP receiver:

```yml
receivers:
otlp: {}
```

This will create the receiver on the Collector side, and open up port `55680` for receiving traces.
The rest of the configuration is quite standard, with the only mention that we need to create the Jaeger exporter:
stefanprisca marked this conversation as resolved.
Show resolved Hide resolved

```yml
exporters:
jaeger:
# Replace with a real endpoint.
endpoint: "<jaeger-service-url>:14250"
```

After this, apply the configuration to your OpenTelemetry Collector instance (with `kubectl apply -f otel-controller-config.yaml` for k8s users).
You should see that the Collector creates the otlp receiver:

```json
{"level":"info","ts":1589184143.206609,"caller":"builder/receivers_builder.go:79","msg":"Receiver started.","component_kind":"receiver","component_type":"otlp","component_name":"otlp"}
```
and the Jaeger exporter:
```json
{"level":"info","ts":1589184143.1535392,"caller":"builder/exporters_builder.go:94","msg":"Exporter started.","component_kind":"exporter","component_type":"jaeger","component_name":"jaeger"}
```

# Writing the demo

Having the OpenTelemetry Collector started with the OTLP port open for traces, and connected to Jaeger, let's look at the go app that will send traces to the Collector.

First, we need to create an exporter using the otlp package:
```go
exp, _ := otlp.NewExporter(otlp.WithInsecure(),
// For debug purposes
otlp.WithGRPCDialOption(grpc.WithBlock()))
defer func() {
_ = exp.Stop()
}()
```
This will initialize the exporter with the default configuration.
In this configuration, it will try to connect to an OTLP receiver at the address `localhost:55680`.
If your OpenTelemetry Collector is running at a different address, use the [`otlp.WithAddress`](https://pkg.go.dev/go.opentelemetry.io/otel/exporters/otlp?tab=doc#WithAddress) function to change the default address.

Feel free to remove the blocking operation, but it might come in handy when testing the connection.
Also, make sure to close the exporter before the app exits.

The next steps are the same as for all other OpenTelemetry-Go SDK uses:
1) Create a trace provider from the `otlp` exporter:
```go
tp, _ := sdktrace.NewProvider(
sdktrace.WithConfig(sdktrace.Config{DefaultSampler: sdktrace.AlwaysSample()}),
sdktrace.WithBatcher(exp, // add following two options to ensure flush
sdktrace.WithScheduleDelayMillis(5),
sdktrace.WithMaxExportBatchSize(2),
))
```

2) Start sending traces:
```go
tracer := tp.Tracer("test-tracer")
ctx, span := tracer.Start(context.Background(), "CollectorExporter-Example")
defer span.End()
```

The traces should now be visible from the Jaeger UI (if you have it installed).

# Notes

* There is an issue with the exporter/Collector which causes Jaeger to throw errors when receiving spans from the OpenTelemetry Collector: https://github.com/open-telemetry/opentelemetry-collector/issues/815
10 changes: 10 additions & 0 deletions example/otel-collector/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module go.opentelemetry.io/otel/example/otel-collector

go 1.14

require (
github.com/open-telemetry/opentelemetry-collector v0.3.0
go.opentelemetry.io/otel v0.4.3
go.opentelemetry.io/otel/exporters/otlp v0.4.3
google.golang.org/grpc v1.29.1
)
Loading