1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-02-03 13:11:53 +02:00

Merge branch 'master' of github.com:stefanprisca/opentelemetry-go into sp-master

This commit is contained in:
Stefan Prisca 2020-05-13 12:40:02 +02:00
commit af27b4381a
2 changed files with 23 additions and 10 deletions

View File

@ -1,21 +1,25 @@
# OpenTelemetry Collector Traces Example
This example illustrates how to export traces from the otel-go sdk to the Open Telemetry Collector, and from there to a Jaeger instance.
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 OpenTelemetry Collector and Jaeger up and running. For setting these up, please follow the corresponding documentations:
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 build against a microk8s cluster running both the OpenTelemetry Collector, and Jaeger. Therefor, the OpenTelemetry Collector configuration illustrated is a K8S ConfigurationMap. But the gist of it is there, so it shouldn't matter too much.
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 open up the OTLP receiver:
In order to enable our application to send traces to the OpenTelemetry Collector, we need to first configure the OTLP receiver:
```yml
receivers:
@ -24,6 +28,7 @@ receivers:
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:
```yml
exporters:
jaeger:
@ -31,7 +36,9 @@ exporters:
endpoint: "<jaeger-service-url>:14250"
```
After this, apply the configuration to your OpenTelemetry Collector instance (with `k apply -f otel-controller-config.yaml` for k8s users). You should see that the Collector creates the otlp receiver:
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"}
```
@ -53,11 +60,14 @@ 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.
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.
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 otel-go sdk uses:
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(

View File

@ -37,10 +37,13 @@ func main() {
log.Fatalf("Failed to create the collector exporter: %v", err)
}
defer func() {
_ = exp.Stop()
err := exp.Stop()
if err != nil {
log.Fatalf("Failed to stop the exporter: %v", err)
}
}()
tp, _ := sdktrace.NewProvider(
tp, err := sdktrace.NewProvider(
sdktrace.WithConfig(sdktrace.Config{DefaultSampler: sdktrace.AlwaysSample()}),
sdktrace.WithResourceAttributes(
core.Key(conventions.AttributeServiceName).String("test-service"),