datadogwriter

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2025 License: GPL-3.0 Imports: 5 Imported by: 0

README

datadog-writer

A module that enables go programs to write observability data directly to DataDog endpoints rather than depending on the DataDog Agent

Using this module

package main

import (
	"io"
	"os"

	"github.com/rs/zerolog"
	"github.com/rs/zerolog/log"
	"github.com/trevorrobertsjr/datadogwriter"
)

func main() {

	// Configure logger
	datadogWriter := &datadogwriter.DatadogWriter{
		Service:  "your-service",
		Hostname: "your-server",
		Tags:     "env:staging,version:1.0",
		Source:   "your-source",
	}
	log.Logger = zerolog.New(io.MultiWriter(os.Stdout, datadogWriter)).With().Timestamp().Logger()

	log.Info().Msg("Reading config...")

}

Your program needs to provide your API key and assigned datadog site as environment variables. If your datadog site is the default (datadoghq.com), you do not need to set the DD_SITE environment variable.

DD_API_KEY=YourApiKey DD_SITE=us5.datadoghq.com go run main.go

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DatadogWriter

type DatadogWriter struct {
	Service  string
	Hostname string
	Tags     string
	Source   string
	Encoding string
}

DatadogWriter is a custom writer that sends logs to Datadog

func (*DatadogWriter) Write

func (w *DatadogWriter) Write(p []byte) (n int, err error)

Jump to

Keyboard shortcuts

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