Jaeger
The Jaeger Agent embedded in Datakit is used to receive, calculate and analyze Jaeger Tracing protocol data.
Configuration¶
Collector Configuration¶
Info
The current version of Jaeger supports the HTTP and UDP communication protocols and the Apache Thrift encoding specification.
Go to the conf.d/jaeger
directory under the DataKit installation directory, copy jaeger.conf.sample
and name it jaeger.conf
. Examples are as follows:
[[inputs.jaeger]]
# Jaeger endpoint for receiving tracing span over HTTP.
# Default value set as below. DO NOT MODIFY THE ENDPOINT if not necessary.
endpoint = "/apis/traces"
# Jaeger agent host:port address for UDP transport.
# address = "127.0.0.1:6831"
# binary_address = "127.0.0.1:6832"
## ignore_tags will work as a blacklist to prevent tags send to data center.
## Every value in this list is a valid string of regular expression.
# ignore_tags = ["block1", "block2"]
## Keep rare tracing resources list switch.
## If some resources are rare enough(not presend in 1 hour), those resource will always send
## to data center and do not consider samplers and filters.
# keep_rare_resource = false
## delete trace message
# del_message = true
## Ignore tracing resources map like service:[resources...].
## The service name is the full service name in current application.
## The resource list is regular expressions uses to block resource names.
## If you want to block some resources universally under all services, you can set the
## service name as "*". Note: double quotes "" cannot be omitted.
# [inputs.jaeger.close_resource]
# service1 = ["resource1", "resource2", ...]
# service2 = ["resource1", "resource2", ...]
# "*" = ["close_resource_under_all_services"]
# ...
## Sampler config uses to set global sampling strategy.
## sampling_rate used to set global sampling rate.
# [inputs.jaeger.sampler]
# sampling_rate = 1.0
# [inputs.jaeger.tags]
# key1 = "value1"
# key2 = "value2"
# ...
## Threads config controls how many goroutines an agent cloud start to handle HTTP request.
## buffer is the size of jobs' buffering of worker channel.
## threads is the total number fo goroutines at running time.
## timeout is the duration(ms) before a job can return a result.
# [inputs.jaeger.threads]
# buffer = 100
# threads = 8
## Storage config a local storage space in hard dirver to cache trace data.
## path is the local file path used to cache data.
## capacity is total space size(MB) used to store data.
# [inputs.jaeger.storage]
# path = "./jaeger_storage"
# capacity = 5120
Once configured, restart DataKit.
Can be turned on by ConfigMap Injection Collector Configuration or Config ENV_DATAKIT_INPUTS .
Can also be turned on by environment variables, (needs to be added as the default collector in ENV_DEFAULT_ENABLED_INPUTS):
-
ENV_INPUT_JAEGER_HTTP_ENDPOINT
Endpoint for receiving tracing span over HTTP
Type: String
input.conf:
endpoint
Example: /apis/traces
-
ENV_INPUT_JAEGER_UDP_ENDPOINT
Agent URL for UDP transport
Type: String
input.conf:
address
Example: 127.0.0.1:6831
-
ENV_INPUT_JAEGER_IGNORE_TAGS
Ignore tags
Type: JSON
input.conf:
ignore_tags
Example: ["block1","block2"]
-
ENV_INPUT_JAEGER_KEEP_RARE_RESOURCE
Keep rare tracing resources list switch
Type: Boolean
input.conf:
keep_rare_resource
Default: false
-
ENV_INPUT_JAEGER_DEL_MESSAGE
Delete trace message
Type: Boolean
input.conf:
del_message
Default: false
-
ENV_INPUT_JAEGER_CLOSE_RESOURCE
Ignore tracing resources that service (regular)
Type: JSON
input.conf:
close_resource
Example: {"service1":["resource1","other"],"service2":["resource2","other"]}
-
ENV_INPUT_JAEGER_SAMPLER
Global sampling rate
Type: Float
input.conf:
sampler
Example: 0.3
-
ENV_INPUT_JAEGER_THREADS
Total number of threads and buffer
Type: JSON
input.conf:
threads
Example: {"buffer":1000, "threads":100}
-
ENV_INPUT_JAEGER_STORAGE
Local cache file path and size (MB)
Type: JSON
input.conf:
storage
Example: {"storage":"./jaeger_storage", "capacity": 5120}
-
ENV_INPUT_JAEGER_TAGS
Customize tags. If there is a tag with the same name in the configuration file, it will be overwritten
Type: JSON
input.conf:
tags
Example: {"k1":"v1", "k2":"v2", "k3":"v3"}
When using UDP protocol, pay attention to the data format in the protocol. By default, the protocol used for port 6831 is Thrift CompactProtocol
format, while the protocol used for port 6832 is Thrift Binary Protocol
.
Jaeger uses the protocol from port 6831 by default.
Configure Jaeger HTTP Agent¶
endpoint represents Jaeger HTTP Agent routing
[[inputs.jaeger]]
# Jaeger endpoint for receiving tracing span over HTTP.
# Default value set as below. DO NOT MODIFY THE ENDPOINT if not necessary.
endpoint = "/apis/traces"
- Modify the Agent Host Port of Jaeger Client to Datakit Port (default is 9529)
- Modify the Agent endpoint of the Jaeger Client to the endpoint specified in the configuration above
Configure Jaeger UDP Agent¶
Modify the Agent UDP Host: Port of the Jaeger Client to the address specified in the following configuration:
Refer to Datakit Tracing for configuration of data sampling, data filtering, closing resources, and so on.
Sample¶
Golang Sample¶
Here is an example of an HTTP Agent:
package main
import (
"fmt"
"io"
"log"
"net/http"
"net/http/httptest"
"time"
"github.com/opentracing/opentracing-go"
"github.com/opentracing/opentracing-go/ext"
"github.com/uber/jaeger-client-go"
jaegercfg "github.com/uber/jaeger-client-go/config"
jaegerlog "github.com/uber/jaeger-client-go/log"
)
var tracer opentracing.Tracer
func main() {
jgcfg := jaegercfg.Configuration{
ServiceName: "jaeger_sample_http",
Sampler: &jaegercfg.SamplerConfig{
Type: jaeger.SamplerTypeConst,
Param: 1,
},
Reporter: &jaegercfg.ReporterConfig{
CollectorEndpoint: "http://localhost:9529/apis/traces",
HTTPHeaders: map[string]string{"Content-Type": "application/x-thrift"},
BufferFlushInterval: time.Second,
LogSpans: true,
},
}
var (
closer io.Closer
err error
)
tracer, closer, err = jgcfg.NewTracer(jaegercfg.Logger(jaegerlog.StdLogger))
defer func() {
if err := closer.Close(); err != nil {
log.Println(err.Error())
}
}()
if err != nil {
log.Panicln(err.Error())
}
srv := httptest.NewServer(http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
spctx, err := tracer.Extract(opentracing.HTTPHeaders, opentracing.HTTPHeadersCarrier(req.Header))
var span opentracing.Span
if err != nil {
log.Println(err.Error())
span = tracer.StartSpan(req.RequestURI)
} else {
span = tracer.StartSpan(req.RequestURI, ext.RPCServerOption(spctx))
}
defer span.Finish()
span.SetTag("finish_ts", time.Now())
resp.Write([]byte("hello, world"))
}))
for i := 0; i < 100; i++ {
send(srv.URL, i)
time.Sleep(time.Second)
}
}
func send(urlstr string, i int) {
span := tracer.StartSpan(fmt.Sprintf("main_loop->send(%d)", i))
defer span.Finish()
req, err := http.NewRequest(http.MethodGet, urlstr, nil)
if err != nil {
log.Println(err.Error())
return
}
if err = tracer.Inject(span.Context(), opentracing.HTTPHeaders, opentracing.HTTPHeadersCarrier(req.Header)); err != nil {
log.Panicln(err.Error())
return
}
span.SetTag(fmt.Sprintf("send_%d_finish", i), time.Now())
}
Golang UDP Sample¶
Here is an example of a UDP Agent:
package main
import (
"io"
"log"
"time"
"github.com/opentracing/opentracing-go"
"github.com/uber/jaeger-client-go"
jaegercfg "github.com/uber/jaeger-client-go/config"
jaegerlog "github.com/uber/jaeger-client-go/log"
)
var tracer opentracing.Tracer
func main() {
jgcfg := jaegercfg.Configuration{
ServiceName: "jaeger_sample_app",
Sampler: &jaegercfg.SamplerConfig{
Type: jaeger.SamplerTypeConst,
Param: 1,
},
Reporter: &jaegercfg.ReporterConfig{
LocalAgentHostPort: "127.0.0.1:6831",
BufferFlushInterval: time.Second,
LogSpans: true,
},
}
var (
closer io.Closer
err error
)
tracer, closer, err = jgcfg.NewTracer(jaegercfg.Logger(jaegerlog.StdLogger))
defer func() {
if err := closer.Close(); err != nil {
log.Println(err.Error())
}
}()
if err != nil {
log.Panicln(err.Error())
}
for i := 0; i < 10; i++ {
foo()
time.Sleep(time.Second)
}
}
func foo() {
span := tracer.StartSpan("foo")
defer span.Finish()
span.SetTag("finish_ts", time.Now())
}
Metric¶
jaeger
¶
- tag
Tag | Description |
---|---|
container_host |
Container hostname. Available in OpenTelemetry. Optional. |
dk_fingerprint |
DataKit fingerprint is DataKit hostname |
endpoint |
Endpoint info. Available in SkyWalking, Zipkin. Optional. |
env |
Application environment info. Available in Jaeger. Optional. |
host |
Hostname. |
http_method |
HTTP request method name. Available in DDTrace, OpenTelemetry. Optional. |
http_route |
HTTP route. Optional. |
http_status_code |
HTTP response code. Available in DDTrace, OpenTelemetry. Optional. |
http_url |
HTTP URL. Optional. |
operation |
Span name |
project |
Project name. Available in Jaeger. Optional. |
service |
Service name. Optional. |
source_type |
Tracing source type |
span_type |
Span type |
status |
Span status |
version |
Application version info. Available in Jaeger. Optional. |
- metric list
Metric | Description | Type | Unit |
---|---|---|---|
duration |
Duration of span | int | μs |
message |
Origin content of span | string | - |
parent_id |
Parent span ID of current span | string | - |
resource |
Resource name produce current span | string | - |
span_id |
Span id | string | - |
start |
start time of span. | int | usec |
trace_id |
Trace id | string | - |