This is a golang example that uses OpenTelemetry to fulfill observability.
$ make build-demo
$ ./release/demo -h
$ ./release/demo --use-stdout-exporter
Run and exports metrics to AlibabaCloud SLS
-
Download
otel-contrib-collector
from opentelemetry-collector-contrib releases and make it executable and searchable from$PATH
. -
Prepare a yaml file of collector configuration:
receivers:
otlp:
protocols:
grpc:
endpoint: "0.0.0.0:4317"
processors:
batch:
send_batch_size: 10000
send_batch_max_size: 11000
timeout: 10s
metricstransform:
transforms:
- include: request
action: update
new_name: demo_request
- include: throughput
action: update
operations:
- action: add_label
new_label: my_label
new_value: demo
exporters:
alibabacloud_logservice/metrics:
# LogService's Endpoint, https://www.alibabacloud.com/help/doc-detail/29008.htm
# for AlibabaCloud Kubernetes(or ECS), set {region-id}-intranet.log.aliyuncs.com, eg cn-hangzhou-intranet.log.aliyuncs.com;
# others set {region-id}.log.aliyuncs.com, eg cn-hangzhou.log.aliyuncs.com
endpoint: "cn-hangzhou.log.aliyuncs.com"
# LogService's Project Name
project: ""
# LogService's Logstore Name
logstore: ""
# AlibabaCloud access key id
access_key_id: ""
# AlibabaCloud access key secret
access_key_secret: ""
file:
path: ./metrics.json
service:
pipelines:
metrics:
receivers: [otlp]
processors: [batch, metricstransform]
exporters: [alibabacloud_logservice/metrics, file]
You can find the detailed configuration of AlibabaCloud SLS here.
- Run
otelcontribcol
$ otelcontribcol --config /PATH/TO/<SLS config yaml>
- Run app
$ ./release/demo --use-stdout-exporter=false --use-collector --collector-otlp-endpoint 0.0.0.0:4317