Golang Datadog APM package with traces and a connected logger
Description
This package makes it possible to add Datadog spans to your code and connect logs to your traces inside datadog based on the following parts:
- Datadog tracer
- Zap logger
Usage
go get github.com/YourSurpriseCom/go-datadog-apm
import(
github.com/YourSurpriseCom/go-datadog-apm/apm
)
apm := apm.NewApm()
currentContext := context.Background()
//Start a span
span, spanContext := apm.StartSpanFromContext(currentContext, "GetSignedUrl")
defer span.Finish()
//Create debug log message
apm.Logger.Debug(spanContext, "This log message will be linked to the span based on the spanContext")
Configuration
The log level can be configure by setting the environment variable LOG_LEVEL
with the following values:
When not set, it will fall back to the value info
Serverless Config
To use the Serverless Datadog agent, build the application based on the following Dockerfile
.
FROM alpine:3.20
ARG ARG_VERSION=dev
ENV DD_VERSION=${ARG_VERSION}
ENV DD_SITE=datadoghq.eu
COPY --from=datadog/serverless-init:1.2.8-alpine /datadog-init /datadog/datadog-init
COPY --from=builder /go/bin/main /go/bin/main
ENTRYPOINT ["/datadog/datadog-init"]
CMD ["/go/bin/main"]