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

Commit ae443e6

Browse files
author
Sam Park
committed
Add support for Datadog APM tracing
Addresses #188
1 parent bf3d5d0 commit ae443e6

File tree

7 files changed

+204
-14
lines changed

7 files changed

+204
-14
lines changed

weaver/Gopkg.lock

Lines changed: 119 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

weaver/Gopkg.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@
5757
name = "gopkg.in/alexcesaro/statsd.v2"
5858
version = "2.0.0"
5959

60+
[[constraint]]
61+
name = "github.com/stretchr/testify"
62+
version = "1.3.0"
63+
6064
[prune]
6165
go-tests = true
6266
unused-packages = true
67+
68+
[[constraint]]
69+
name = "gopkg.in/DataDog/dd-trace-go.v1"
70+
version = "1.9.0"

weaver/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Although it was predominantly designed for generating a PDF from a HTML using [`
2626
- Strong service visibility for quality control:
2727
- Metrics collection ([statsd])
2828
- Error logging ([Sentry][sentry])
29+
- APM ([Datadog APM][ddapm])
2930
- Dockerized:
3031
- Easy to set up, distribute, and deploy
3132
- Runs in headless mode (the display server is handled for you)
@@ -52,3 +53,4 @@ See [`docs/building.md`](docs/building.md).
5253
[cloudconvert]: https://cloudconvert.com/
5354
[statsd]: https://github.com/etsy/statsd
5455
[sentry]: https://getsentry.com/
56+
[ddapm]: https://www.datadoghq.com/apm/

weaver/conf/sample.env

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,7 @@ WEAVER_CONVERSION_FALLBACK=false
1717
# STATSD_ADDRESS=
1818
# STATSD_PREFIX=
1919
# SENTRY_DSN=
20+
21+
# Datadog APM tracing
22+
# DATADOG_AGENT_ADDRESS=
23+
# DATADOG_APM_SERVICE_NAME=

weaver/config.go

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,21 +67,28 @@ type Config struct {
6767
// The data source name (DSN) for a Sentry server (used for logging errors).
6868
// Defaults to none.
6969
SentryDSN string
70+
// Hostname (and port) for reporting Datadog APM traces.
71+
// Defaults to none (no trace reporting).
72+
DatadogAgentAddress string
73+
// Service name to report to Datadog APM
74+
// DEfaults to "weaver"
75+
DatadogAPMServiceName string
7076
}
7177

7278
// NewEnvConfig initialises configuration variables from the environment.
7379
func NewEnvConfig() Config {
7480
// Set defaults
7581
cloudconvert := CloudConvert{APIUrl: "https://api.cloudconvert.com"}
7682
conf := Config{
77-
CloudConvert: cloudconvert,
78-
HTTPAddr: ":8080",
79-
AuthKey: "arachnys-weaver",
80-
AthenaCMD: "athenapdf -S",
81-
MaxWorkers: 10,
82-
MaxConversionQueue: 50,
83-
WorkerTimeout: 90,
84-
ConversionFallback: false,
83+
CloudConvert: cloudconvert,
84+
HTTPAddr: ":8080",
85+
AuthKey: "arachnys-weaver",
86+
AthenaCMD: "athenapdf -S",
87+
MaxWorkers: 10,
88+
MaxConversionQueue: 50,
89+
WorkerTimeout: 90,
90+
ConversionFallback: false,
91+
DatadogAPMServiceName: "weaver",
8592
}
8693

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

155+
if datadogAgentAddress := os.Getenv("DATADOG_AGENT_ADDRESS"); datadogAgentAddress != "" {
156+
conf.DatadogAgentAddress = datadogAgentAddress
157+
}
158+
159+
if datadogAPMServiceName := os.Getenv("DATADOG_APM_SERVICE_NAME"); datadogAPMServiceName != "" {
160+
conf.DatadogAPMServiceName = datadogAPMServiceName
161+
}
162+
148163
return conf
149164
}

weaver/config_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package main
2+
3+
import (
4+
"github.com/stretchr/testify/assert"
5+
"os"
6+
"testing"
7+
)
8+
9+
func TestNewEnvConfig(t *testing.T) {
10+
t.Run("Datadog Agent Address", func(t *testing.T) {
11+
c := NewEnvConfig()
12+
assert.Equal(t, "", c.DatadogAgentAddress)
13+
14+
expectValue := "123qweasdzxc:12312"
15+
err := os.Setenv("DATADOG_AGENT_ADDRESS", expectValue)
16+
assert.Nil(t, err)
17+
18+
c = NewEnvConfig()
19+
assert.Equal(t, expectValue, c.DatadogAgentAddress)
20+
})
21+
22+
t.Run("Datadog APM Service Name", func(t *testing.T) {
23+
c := NewEnvConfig()
24+
assert.Equal(t, "weaver", c.DatadogAPMServiceName)
25+
26+
expectValue := "12o38y27345987234695thekgjr"
27+
err := os.Setenv("DATADOG_APM_SERVICE_NAME", expectValue)
28+
assert.Nil(t, err)
29+
30+
c = NewEnvConfig()
31+
assert.Equal(t, expectValue, c.DatadogAPMServiceName)
32+
})
33+
}

0 commit comments

Comments
 (0)