Skip to content

flyer103/otel-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Overview

This is a golang example that uses OpenTelemetry to fulfill observability.

Usage

Build

$ make build-demo

Help

$ ./release/demo -h

Run and exports metrics to stdout

$ ./release/demo --use-stdout-exporter

Run and exports metrics to AlibabaCloud SLS

  1. Download otel-contrib-collector from opentelemetry-collector-contrib releases and make it executable and searchable from $PATH.

  2. 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.

  1. Run otelcontribcol
$ otelcontribcol --config /PATH/TO/<SLS config yaml>
  1. Run app
$ ./release/demo --use-stdout-exporter=false --use-collector --collector-otlp-endpoint 0.0.0.0:4317