In opentelemetry, there is something called as span
and trace
.
-
Basically think of one http request. The whole lifetime of request and response can be called
trace
. And things done along the way is calledspan
. Lets say when request comes, and we want to create some file or read something for that request that will be onespan
. And so on. That is how we know the whole lifetime of request. -
Now when we collect the data we might want to send it to external system to display for that we want what we call as
exporters
. -
On the other hand we need
collectors
to collect the data :
The Collector consists of four components that access telemetry data:
Receivers - receive data from application like span/traces/metrics
Processors - do some processing on it like excluding some part of data
Exporters - send it to systems to visualise, log like prometheus, newrelic, jaeger
Connectors - it can work as both receiver and exporter
https://github.com/open-telemetry/opentelemetry-collector/blob/main/connector/README.md
Collector is the place where application sends its traces / metric. This should be agnostic.
- Below is open telemetry demo config
receivers:
otlp:
protocols:
http:
endpoint: "0.0.0.0:4318"
exporters:
jaeger:
endpoint: "jaeger:14250"
tls:
insecure: true
service:
pipelines:
traces:
receivers: [otlp]
exporters: [jaeger]
It has :
- receiver configured on 4318 : Basically this is where application send its traces
- exporters : Once traces are collected it can export it to destination system, in this case it is jaeger. By default it accepts on model.proto format. More details can be found here : https://www.jaegertracing.io/docs/1.47/deployment/#collector
- service: Now to tell receiver and exporter about each other. We do that in service under pipelines. Pipelines can i have multiple options like
traces
,logs
,metrics
Command to start running otlm collector :
docker run -p 4311:4318 --network=opentelem -v $(pwd)/my-values-file.yaml:/etc/otelcol-contrib/config.yaml otel/opentelemetry-collector-contrib:0.82.0
Now as we have collector running where application can send traces. We need to export it. And as we have configured it in above config, we are using jaeger to visualise, collect this traces. Jaeger can be run using :
docker run --rm --name jaeger --network=opentelem \
-e COLLECTOR_OTLP_ENABLED=true \
-p 14250:14250 \
-p 16686:16686 \
-p 4318:4318 \
jaegertracing/all-in-one:latest
This page has very basic example for sending traces but its good start. https://opentelemetry.io/docs/instrumentation/go/getting-started/
- HTTP Exporter client can be created with below code. As its not mentioned :
func httpExportPipeline(ctx context.Context) (*otlptrace.Exporter, error) {
client := otlptracehttp.NewClient(otlptracehttp.WithInsecure())
exporter, err := otlptrace.New(ctx, client)
if err != nil {
return nil, fmt.Errorf("creating OTLP trace exporter: %w", err)
}
return exporter, err
}
And add it to the pipeline
tp := trace.NewTracerProvider(
trace.WithBatcher(exp),
trace.WithBatcher(httpExp),
trace.WithResource(newResource()),
)