• Stars
    star
    10
  • Rank 1,807,489 (Top 36 %)
  • Language
    Go
  • License
    MIT License
  • Created over 1 year ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

๐Ÿšจ slog: Datadog handler

slog: Datadog handler

tag Go Version GoDoc Build Status Go report Coverage Contributors License

A Datadog Handler for slog Go library.

See also:

HTTP middlewares:

Loggers:

Log sinks:

๐Ÿš€ Install

go get github.com/samber/slog-datadog/v2

Compatibility: go >= 1.21

No breaking changes will be made to exported APIs before v3.0.0.

๐Ÿ’ก Usage

GoDoc: https://pkg.go.dev/github.com/samber/slog-datadog/v2

Handler options

type Option struct {
	// log level (default: debug)
	Level slog.Leveler

	// datadog endpoint
	Client  *datadog.APIClient
	Context context.Context
	Timeout time.Duration	// default: 10s

	// source parameters
	Service    string
	Hostname   string
	GlobalTags map[string]string

	// optional: customize Datadog message builder
	Converter Converter
	// optional: custom marshaler
	Marshaler func(v any) ([]byte, error)

	// optional: see slog.HandlerOptions
	AddSource   bool
	ReplaceAttr func(groups []string, a slog.Attr) slog.Attr
}

Attributes will be injected in log payload.

Other global parameters:

slogdatadog.SourceKey = "source"
slogdatadog.ErrorKeys = []string{"error", "err"}

Example

import (
	"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
	slogdatadog "github.com/samber/slog-datadog/v2"
	"log/slog"
)

func newDatadogClient(endpoint string, apiKey string) (*datadog.APIClient, context.Context) {
	ctx := datadog.NewDefaultContext(context.Background())
	ctx = context.WithValue(
		ctx,
		datadog.ContextAPIKeys,
		map[string]datadog.APIKey{"apiKeyAuth": {Key: apiKey}},
	)
	ctx = context.WithValue(
		ctx,
		datadog.ContextServerVariables,
		map[string]string{"site": endpoint},
	)
	configuration := datadog.NewConfiguration()
	apiClient := datadog.NewAPIClient(configuration)

	return apiClient, ctx
}

func main() {
	host := "1.2.3.4"
	service := "api"
	endpoint := slogdatadog.DatadogHostEU
	apiKey := "xxx"
	apiClient, ctx := newDatadogClient(endpoint, apiKey)

	logger := slog.New(slogdatadog.Option{Level: slog.LevelDebug, Client: apiClient, Context: ctx, Timeout: 5*time.Second, Hostname: host, Service: service}.NewDatadogHandler())
	logger = logger.
		With("environment", "dev").
		With("release", "v1.0.0")

	// log error
	logger.
		With("category", "sql").
		With("query.statement", "SELECT COUNT(*) FROM users;").
		With("query.duration", 1*time.Second).
		With("error", fmt.Errorf("could not count users")).
		Error("caramba!")

	// log user signup
	logger.
		With(
			slog.Group("user",
				slog.String("id", "user-123"),
				slog.Time("created_at", time.Now()),
			),
		).
		Info("user registration")
}

๐Ÿค Contributing

Don't hesitate ;)

# Install some dev dependencies
make tools

# Run tests
make test
# or
make watch-test

๐Ÿ‘ค Contributors

Contributors

๐Ÿ’ซ Show your support

Give a โญ๏ธ if this project helped you!

GitHub Sponsors

๐Ÿ“ License

Copyright ยฉ 2023 Samuel Berthe.

This project is MIT licensed.

More Repositories

1

lo

๐Ÿ’ฅ A Lodash-style Go library based on Go 1.18+ Generics (map, filter, contains, find...)
Go
17,419
star
2

awesome-prometheus-alerts

๐Ÿšจ Collection of Prometheus alerting rules
HTML
6,502
star
3

mo

๐Ÿฆ„ Monads and popular FP abstractions, powered by Go 1.18+ Generics (Option, Result, Either...)
Go
2,587
star
4

do

โš™๏ธ A dependency injection toolkit based on Go 1.18+ Generics.
Go
1,807
star
5

oops

๐Ÿ”ฅ Error handling library with context, assertion, stack trace and source fragments
Go
384
star
6

slog-multi

๐Ÿšจ Design workflows of slog handlers: pipeline, middleware, fanout, routing, failover, load balancing...
Go
342
star
7

invoice-as-a-service

๐Ÿ’ฐ Simple invoicing service (REST API): from JSON to PDF
PHP
181
star
8

sync-ssh-keys

๐Ÿ” Sync public ssh keys to ~/.ssh/authorized_keys, based on Github/Gitlab organization membership.
Go
138
star
9

slog-gin

๐Ÿšจ Gin middleware for slog logger
Go
109
star
10

chartjs-plugin-datasource-prometheus

๐Ÿ“Š Chart.js plugin for Prometheus
TypeScript
107
star
11

slog-formatter

๐Ÿšจ slog: Attribute formatting
Go
107
star
12

slog-echo

๐Ÿšจ Echo middleware for slog logger
Go
100
star
13

go-gpt-3-encoder

Go BPE tokenizer (Encoder+Decoder) for GPT2 and GPT3
Go
78
star
14

the-great-gpt-firewall

๐Ÿค– A curated list of websites that restrict access to AI Agents, AI crawlers and GPTs
Python
75
star
15

prometheus-query-js

๐Ÿ“Š A Javascript client for Prometheus query API
TypeScript
58
star
16

hot

๐ŸŒถ๏ธ In-memory caching library for Go
Go
58
star
17

github-actions-runner

โœ… Docker images for starting self-hosted Github Actions runner(s).
Dockerfile
57
star
18

slog-fiber

๐Ÿšจ Fiber middleware for slog logger
Go
52
star
19

slog-sampling

๐Ÿšจ slog sampling: drop repetitive log records
Go
49
star
20

slog-chi

๐Ÿšจ Chi middleware for slog logger
Go
43
star
21

slog-sentry

๐Ÿšจ slog: Sentry handler
Go
43
star
22

awesome-olap

A curated list of awesome Online Analytical Processing databases, frameworks, ressources and other awesomeness.
37
star
23

grafana-flamegraph-panel

๐Ÿ“Š Flame graph panels for Grafana
JavaScript
37
star
24

slog-loki

๐Ÿšจ slog: Loki handler
Go
36
star
25

slog-http

๐Ÿšจ net/http middleware for slog logger
Go
32
star
26

slog-zerolog

๐Ÿšจ slog: Zerolog handler
Go
30
star
27

workshop-prometheus-grafana

๐Ÿ“Š Prometheus and Grafana 101
JavaScript
30
star
28

slog-zap

๐Ÿšจ slog: Zap handler
Go
23
star
29

go-metered-io

๐Ÿ“ A drop-in replacement to io.Reader and io.Writer with the total number of bytes transfered.
Go
23
star
30

go-amqp-pubsub

Fault tolerant Pub/Sub library for RabbitMQ
Go
21
star
31

go-singleflightx

๐Ÿงฌ x/sync/singleflight but with generics, batching, sharding and nullable result
Go
19
star
32

slog-logrus

๐Ÿšจ slog: Logrus handler
Go
18
star
33

slog-slack

๐Ÿšจ slog: Slack handler
Go
18
star
34

arp-spoofing

๐Ÿ’ฅ Simple implementation of arp poisoning attack ;)
C
16
star
35

pg_cron

โฐ PostgreSQL extension for running periodic jobs
C
15
star
36

go-tcp-pool

โœจ Drop-in replacement to net.Conn with pooling and auto-reconnect
Go
14
star
37

go-type-to-string

๐Ÿ•ต๏ธโ€โ™‚๏ธ Extract a string representation of Go type
Go
14
star
38

slog-syslog

๐Ÿšจ slog: Syslog handler
Go
13
star
39

refined-hn

JavaScript
11
star
40

git-contrib-graph

๐Ÿ“Š Displays a github-like contribution graph, of every contributors of a repository
Go
10
star
41

slog-nats

๐Ÿšจ slog: NATS handler
Go
10
star
42

slog-parquet

๐Ÿšจ slog: Parquet handler + Object Storage
Go
10
star
43

free_proxy_list

Free proxy list [NOT MAINTAINED ANYMORE - please fork]
Shell
9
star
44

slog-otel

OTEL toolchain for slog
Makefile
8
star
45

slog-graylog

๐Ÿšจ slog: Graylog handler
Go
7
star
46

powEUr

Python
7
star
47

slog-telegram

๐Ÿšจ slog: Telegram handler
Go
7
star
48

node-promfiler

Expose a http endpoint for exporting node.js v8 profiling
JavaScript
7
star
49

slog-webhook

๐Ÿšจ slog: Webhook handler
Go
7
star
50

slog-betterstack

๐Ÿšจ slog: Betterstack handler
Go
7
star
51

slog-common

Common toolchain for slog
Go
6
star
52

slog-kafka

๐Ÿšจ slog: Kafka handler
Go
6
star
53

slog-channel

๐Ÿšจ slog: Go channel handler
Go
6
star
54

slog-logstash

๐Ÿšจ slog: Logstash handler
Go
5
star
55

ansible-role-airbyte

Ansible role for Airbyte
5
star
56

slog-fluentd

๐Ÿšจ slog: Fluentd handler
Go
4
star
57

remote-dev-environment

๐Ÿ‘จโ€๐Ÿ’ป My development environment is too slow, let's fix that !
4
star
58

GoogleCalendarNotifier-FitbitTracker

Google Calendar notifier for Fitbit Tracker
Gosu
4
star
59

slog-mock

๐Ÿšจ slog: mock handler
Go
4
star
60

slog-quickwit

๐Ÿšจ slog: Quickwit handler
Go
4
star
61

criterion-rpm-package

RPM package for Criterion (C unit testing)
Shell
3
star
62

dagobert

A simple Go client for the clip-as-service server
Go
3
star
63

rabbitmq-flooding

Cluster recovery testing. Floods RabbitMQ with random data.
Python
3
star
64

go-psi

๐Ÿฅต Pressure Stall Informations (PSI) and starvation notifier
Go
3
star
65

slog-microsoft-teams

๐Ÿšจ slog: Microsoft Teams handler
Go
3
star
66

llvm_dart_binding

Binding Dart/LLVM (using LLVM bytecode from Dart)
Dart
3
star
67

lab-langchain-getting-started

Python
2
star
68

BTCC_api

A basic API wrapper for the BTCC Trading and Market FIX API.
JavaScript
2
star
69

ngx-domarrow

Declarative and template-driven DOMArrow integration for Angular2+
TypeScript
2
star
70

github-stackoverflow-email-scrapping

Scrape top Github and Stack-Overflow users to find email address
Go
2
star
71

nft-http-api

๐Ÿšฆ NFT over HTTP API
Go
2
star
72

go-quickwit

๐Ÿฑ A Go ingestion client for Quickwit
Go
2
star
73

celery_demonstration

Async worker + scheduling
Python
2
star
74

dockerfiles

Dockerfile
1
star
75

SaaS-Cookbook-List

List of Cookbook about SaaS development (ENG/FR)
1
star
76

dotfiles

@samber's dotfiles
JavaScript
1
star
77

grafana-dashboard-nomad

Grafana dashboards for Nomad (Docker orchestrator from Hashicorp)
1
star
78

go-clevercloud-api

Go library for Clever-Cloud api
Go
1
star
79

lab-langchain

Python
1
star
80

slog-mattermost

๐Ÿšจ slog: Mattermost handler
Go
1
star
81

jitsi-virtual-background

JavaScript
1
star
82

raw-ip-udp-sockets-chap

Simple implementation of CHAP protocol, with raw socket layers (3+4)
C
1
star
83

lab-parquet

Go
1
star
84

canvas-to-bmp

TypeScript
1
star
85

refined-cycle-app

JavaScript
1
star
86

azure-ad-oauth2-proxy

Dockerfile
1
star
87

packer-qemu-debian

Builds Debian 8 image for Qemu
Shell
1
star
88

poc-selenium-unit-test-css

Python
1
star
89

maxscale-experiments

Demonstration step-by-step of MaxScale for master/slave query spliting/routing #mysql #docker
Shell
1
star
90

google-takeout-to-s3

๐Ÿšจ Simple script to upload encrypted Google Takeout archives to S3.
1
star
91

messenger-bot-clock

Messenger bot replying with current time
JavaScript
1
star
92

fb-messenger-bot-psychologist

๐Ÿค– A Messenger bot talking like a psychologist
Emacs Lisp
1
star
93

promql-exporter

Prometheus exporter for PromQL endpoints (replacing federation and remote-write)
Go
1
star