ddtags

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2024 License: MIT Imports: 5 Imported by: 0

README

Go DataDog Tagging Helper

godoc License Go Report Card

Building up a slice of tags every time you want to do a Datadog metric is tedious.

This library makes passing tags to datadog much easier

Installation

go get -u github.com/webdestroya/ddtags

Usage

package example

import (
  "github.com/webdestroya/ddtags"
	ddlambda "github.com/DataDog/datadog-lambda-go"
)

type DDTags struct {
  Service          string `ddtag:"service_name"`
  AvailabilityZone string `ddtag:"availability-zone"`
  Tier             string `ddtag:"tier"`
}

func Something() {

  ddlambda.Metric("some.metric.name", 123, ddtags.Extract(&DDTags{
    Service: "some_service",
    Tier:    "gold",
  })...)

}

All scalar types are supported (as well as their pointer variants). The zero value is ignored. If you want to explicitly tag the zero value of a type, you'll need to make it a pointer

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Configure

func Configure(cfg *Config)

func Extract

func Extract(struc any) []string

Extracts a list of datadog tags using the "ddtag" struct member tags

Example
package main

import (
	"fmt"
	"strings"

	"github.com/webdestroya/ddtags"
)

type SimpleTags struct {
	Service   string `ddtag:"service_name"`
	AvailZone string `ddtag:"availability-zone"`
	Tier      string `ddtag:"tier"`
}

func main() {
	tags := &SimpleTags{
		Service: "dummy-service",
		Tier:    "gold",
	}

	fmt.Println(strings.Join(ddtags.Extract(tags), ","))
}
Output:

service_name:dummy-service,tier:gold

func Metric

func Metric(metric string, value float64, tags any)

func MetricWithTimestamp

func MetricWithTimestamp(metric string, value float64, timestamp time.Time, tags any)

func Validate

func Validate(struc any) error

Returns an error if any fields in the struct (tagged with ddtag) are invalid and will be ignored You can use this inside your test suite

Types

type Config

type Config struct {
	// Datadog's MetricWithTimestamp function
	// it's probably ddlambda.MetricWithTimestamp
	MetricWithTimestamp func(string, float64, time.Time, ...string)

	// The string format passed to fmt.Sprintf for integer values
	// Default: '%d'
	IntegerFormat string

	// The string format passed to fmt.Sprintf for float values
	// Default: '%0.5f'
	FloatFormat string
}

Jump to

Keyboard shortcuts

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