Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Add support for Datadog APM tracing #189

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 119 additions & 6 deletions weaver/Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions weaver/Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@
name = "gopkg.in/alexcesaro/statsd.v2"
version = "2.0.0"

[[constraint]]
name = "github.com/stretchr/testify"
version = "1.3.0"

[prune]
go-tests = true
unused-packages = true

[[constraint]]
name = "gopkg.in/DataDog/dd-trace-go.v1"
version = "1.9.0"
2 changes: 2 additions & 0 deletions weaver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Although it was predominantly designed for generating a PDF from a HTML using [`
- Strong service visibility for quality control:
- Metrics collection ([statsd])
- Error logging ([Sentry][sentry])
- APM ([Datadog APM][ddapm])
- Dockerized:
- Easy to set up, distribute, and deploy
- Runs in headless mode (the display server is handled for you)
Expand All @@ -52,3 +53,4 @@ See [`docs/building.md`](docs/building.md).
[cloudconvert]: https://cloudconvert.com/
[statsd]: https://github.com/etsy/statsd
[sentry]: https://getsentry.com/
[ddapm]: https://www.datadoghq.com/apm/
4 changes: 4 additions & 0 deletions weaver/conf/sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ WEAVER_CONVERSION_FALLBACK=false
# STATSD_ADDRESS=
# STATSD_PREFIX=
# SENTRY_DSN=

# Datadog APM tracing
# DATADOG_AGENT_ADDRESS=
# DATADOG_APM_SERVICE_NAME=
31 changes: 23 additions & 8 deletions weaver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,28 @@ type Config struct {
// The data source name (DSN) for a Sentry server (used for logging errors).
// Defaults to none.
SentryDSN string
// Hostname (and port) for reporting Datadog APM traces.
// Defaults to none (no trace reporting).
DatadogAgentAddress string
// Service name to report to Datadog APM
// Defaults to "weaver"
DatadogAPMServiceName string
}

// NewEnvConfig initialises configuration variables from the environment.
func NewEnvConfig() Config {
// Set defaults
cloudconvert := CloudConvert{APIUrl: "https://api.cloudconvert.com"}
conf := Config{
CloudConvert: cloudconvert,
HTTPAddr: ":8080",
AuthKey: "arachnys-weaver",
AthenaCMD: "athenapdf -S",
MaxWorkers: 10,
MaxConversionQueue: 50,
WorkerTimeout: 90,
ConversionFallback: false,
CloudConvert: cloudconvert,
HTTPAddr: ":8080",
AuthKey: "arachnys-weaver",
AthenaCMD: "athenapdf -S",
MaxWorkers: 10,
MaxConversionQueue: 50,
WorkerTimeout: 90,
ConversionFallback: false,
DatadogAPMServiceName: "weaver",
}

if httpAddr := os.Getenv("WEAVER_HTTP_ADDR"); httpAddr != "" {
Expand Down Expand Up @@ -145,5 +152,13 @@ func NewEnvConfig() Config {
conf.SentryDSN = sentryDSN
}

if datadogAgentAddress := os.Getenv("DATADOG_AGENT_ADDRESS"); datadogAgentAddress != "" {
conf.DatadogAgentAddress = datadogAgentAddress
}

if datadogAPMServiceName := os.Getenv("DATADOG_APM_SERVICE_NAME"); datadogAPMServiceName != "" {
conf.DatadogAPMServiceName = datadogAPMServiceName
}

return conf
}
33 changes: 33 additions & 0 deletions weaver/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package main

import (
"github.com/stretchr/testify/assert"
"os"
"testing"
)

func TestNewEnvConfig(t *testing.T) {
t.Run("Datadog Agent Address", func(t *testing.T) {
c := NewEnvConfig()
assert.Equal(t, "", c.DatadogAgentAddress)

expectValue := "123qweasdzxc:12312"
err := os.Setenv("DATADOG_AGENT_ADDRESS", expectValue)
assert.Nil(t, err)

c = NewEnvConfig()
assert.Equal(t, expectValue, c.DatadogAgentAddress)
})

t.Run("Datadog APM Service Name", func(t *testing.T) {
c := NewEnvConfig()
assert.Equal(t, "weaver", c.DatadogAPMServiceName)

expectValue := "12o38y27345987234695thekgjr"
err := os.Setenv("DATADOG_APM_SERVICE_NAME", expectValue)
assert.Nil(t, err)

c = NewEnvConfig()
assert.Equal(t, expectValue, c.DatadogAPMServiceName)
})
}
Loading