datadog

module
v0.0.0-...-c33968a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 16, 2021 License: MIT

README

Kratos datadog plugin

NOTICE: This repository has already been archived. Please check the link below

Requirements

  • install datadog agent https://docs.datadoghq.com/agent/
  • install datadog go library:
    go get github.com/DataDog/datadog-go/statsd
    
  • set datadog environment variables
    DD_AGENT_HOST=127.0.0.1
    DD_DOGSTATSD_PORT=8125
    

Usage

Server
// grpc sever
grpcSrv := grpc.NewServer(
    grpc.Address(":9000"),
    grpc.Middleware(
        metrics.Server(
          metrics.WithSeconds(statsd.NewTiming("name", statsd.WithLabels("kind", "operation"), statsd.WithClient(client))),
          metrics.WithRequests(statsd.NewCounter("name", statsd.WithLabels("kind", "operation", "code", "reason"), statsd.WithClient(client))),
        )
    ),
)

// http server
httpSrv := http.NewServer(
    http.Address(":8000"),
    http.Middleware(
        metrics.Server(
          metrics.WithSeconds(statsd.NewTiming("name", statsd.WithLabels("kind", "operation"), statsd.WithClient(client))),
          metrics.WithRequests(statsd.NewCounter("name", statsd.WithLabels("kind", "operation", "code", "reason"), statsd.WithClient(client))),
        )
    ),
)
Client
// grpc client
conn, err := grpc.DialInsecure(
    context.Background(),
    grpc.WithEndpoint("127.0.0.1:9000"),
    grpc.WithMiddleware(
        metrics.Client(
            metrics.WithSeconds(statsd.NewTiming("name", statsd.WithLabels("kind", "operation"), statsd.WithClient(client))),
            metrics.WithRequests(statsd.NewCounter("name", statsd.WithLabels("kind", "operation", "code", "reason"), statsd.WithClient(client))),
        ),
    ),
)

// http client
conn, err := http.NewClient(
    context.Background(),
    http.WithEndpoint("127.0.0.1:8000"),
    http.WithMiddleware(
        metrics.Client(
            metrics.WithSeconds(statsd.NewTiming("name", statsd.WithLabels("kind", "operation"), statsd.WithClient(client))),
            metrics.WithRequests(statsd.NewCounter("name", statsd.WithLabels("kind", "operation", "code", "reason"), statsd.WithClient(client))),
        ),
    ),
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL