Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
0345c29
Add DataDog exporter back from old fork
mx-psi Sep 21, 2020
dfd3cbe
go mod tidy
mx-psi Sep 21, 2020
0ce7520
Address feedback from upstream PR we did not merge (#1)
mx-psi Sep 21, 2020
fcc9b77
Remove DogStatsD mode (#2)
mx-psi Sep 23, 2020
5760c12
Add traces boilerplate and config
mx-psi Sep 23, 2020
53da05f
Improve test coverage (#3)
mx-psi Sep 24, 2020
86c91ca
[wip] adding trace translation and flushing to intake
ericmustin Sep 25, 2020
ca25ab5
[wip] add client to exporter
ericmustin Sep 25, 2020
07e6d2f
truncate attrib strings
ericmustin Sep 25, 2020
21d3703
[wip] add stats payload begin env and hostname work
ericmustin Sep 26, 2020
3ad9913
[wip]: add rough hostname resolution
ericmustin Sep 27, 2020
4dd5037
Remove client validation (#6)
mx-psi Sep 28, 2020
605dfca
[wip] trace translation work
ericmustin Sep 28, 2020
fe0d7da
add obfuscation
ericmustin Sep 28, 2020
aedb172
[wip] migrate span translation to otel internals
ericmustin Sep 29, 2020
4f355c6
[wip] span translation
ericmustin Sep 29, 2020
c4b33a0
[wip] use passed in hostname and env from config and also remove unus…
ericmustin Sep 29, 2020
0cd9512
linting'
ericmustin Sep 29, 2020
197806d
impement feedback first round
ericmustin Sep 29, 2020
3348e3a
linting, package cleanup
ericmustin Sep 30, 2020
d817a56
clean up tag mappings and pass in whole config instead of specific tags
ericmustin Sep 30, 2020
8cb8fd7
improve retry logic
ericmustin Sep 30, 2020
c6173e8
start specing out tests
ericmustin Oct 1, 2020
4aeb87c
add more robust basic trace translation test
ericmustin Oct 1, 2020
bb5e693
Rewrite without using OpenCensus metrics (#4)
mx-psi Oct 1, 2020
35b20d1
add test for resource and error handling'
ericmustin Oct 1, 2020
71c857f
add tests for translation helper funcs
ericmustin Oct 1, 2020
d5a60ef
add retry helper functions, reduce retry, remove unused code
ericmustin Oct 2, 2020
9c443bc
remove unused mocks for trace exporting
ericmustin Oct 2, 2020
681681e
brig up to date with master
ericmustin Oct 2, 2020
c42d2c4
fix tests and handle global tags
ericmustin Oct 2, 2020
cab8f61
Merge remote-tracking branch 'upstream/master' into master
mx-psi Oct 2, 2020
c8baa95
Disable environment variables parsing
mx-psi Oct 2, 2020
c45a09c
add basic trace exporter tests
ericmustin Oct 2, 2020
12927be
Merge branch 'master' into traces/dev
mx-psi Oct 2, 2020
8c630ee
merge upstream master
ericmustin Oct 2, 2020
bd3f6f6
run make
ericmustin Oct 2, 2020
3457de6
merge master
ericmustin Oct 2, 2020
2beeb3e
update against traces/dev
ericmustin Oct 2, 2020
6c149e9
try to bring up to date with traces/dev
ericmustin Oct 2, 2020
82efc78
clean up factory test
ericmustin Oct 2, 2020
314e023
newline
ericmustin Oct 2, 2020
5590012
linting
ericmustin Oct 2, 2020
2508e9d
add factory test'
ericmustin Oct 2, 2020
3a535a9
add trace connecction test with mock server
ericmustin Oct 3, 2020
92a8604
fix span naming wonkiness and more robustly test trace connection
ericmustin Oct 4, 2020
e1b29e3
merge master
ericmustin Oct 5, 2020
39f0abb
merge master
ericmustin Oct 5, 2020
43d9cef
clear up differences vs master
ericmustin Oct 5, 2020
f8c1d75
add better code comments
ericmustin Oct 5, 2020
4600217
add back env var work
ericmustin Oct 5, 2020
6ce8aba
merge upstream master
ericmustin Oct 5, 2020
f34c642
merge datadog metric work updates
ericmustin Oct 5, 2020
aac9b53
remove unrelated metrics work
ericmustin Oct 5, 2020
a073b9c
[datadogexporter] add more unit tests for translation
ericmustin Oct 5, 2020
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
2 changes: 2 additions & 0 deletions cmd/otelcontribcol/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awsxrayexporter"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/azuremonitorexporter"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/carbonexporter"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/elasticexporter"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/honeycombexporter"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/jaegerthrifthttpexporter"
Expand Down Expand Up @@ -123,6 +124,7 @@ func components() (component.Factories, error) {
alibabacloudlogserviceexporter.NewFactory(),
awsemfexporter.NewFactory(),
sentryexporter.NewFactory(),
datadogexporter.NewFactory(),
}
for _, exp := range factories.Exporters {
exporters = append(exporters, exp)
Expand Down
27 changes: 27 additions & 0 deletions exporter/datadogexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
package datadogexporter

import (
"context"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/configmodels"
"go.opentelemetry.io/collector/config/confignet"
Expand All @@ -33,6 +35,7 @@ func NewFactory() component.ExporterFactory {
return exporterhelper.NewFactory(
typeStr,
createDefaultConfig,
exporterhelper.WithTraces(createTraceExporter),
)
}

Expand Down Expand Up @@ -70,3 +73,27 @@ func createDefaultConfig() configmodels.Exporter {
},
}
}

func createTraceExporter(
_ context.Context,
params component.ExporterCreateParams,
c configmodels.Exporter,
) (component.TraceExporter, error) {

cfg := c.(*Config)

params.Logger.Info("sanitizing Datadog metrics exporter configuration")
if err := cfg.Sanitize(); err != nil {
return nil, err
}

exp, err := newTraceExporter(params.Logger, cfg)
if err != nil {
return nil, err
}

return exporterhelper.NewTraceExporter(
cfg,
exp.pushTraceData,
)
}
31 changes: 31 additions & 0 deletions exporter/datadogexporter/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,18 @@
package datadogexporter

import (
"context"
"path"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/config/configcheck"
"go.opentelemetry.io/collector/config/configmodels"
"go.opentelemetry.io/collector/config/configtest"
"go.uber.org/zap"
)

// Test that the factory creates the default configuration
Expand Down Expand Up @@ -48,3 +55,27 @@ func TestCreateDefaultConfig(t *testing.T) {

assert.NoError(t, configcheck.ValidateConfig(cfg))
}

func TestCreateAPITracesExporter(t *testing.T) {
logger := zap.NewNop()

factories, err := componenttest.ExampleComponents()
assert.NoError(t, err)

factory := NewFactory()
factories.Exporters[configmodels.Type(typeStr)] = factory
cfg, err := configtest.LoadConfigFile(t, path.Join(".", "testdata", "config.yaml"), factories)

require.NoError(t, err)
require.NotNil(t, cfg)

ctx := context.Background()
exp, err := factory.CreateTraceExporter(
ctx,
component.ExporterCreateParams{Logger: logger},
cfg.Exporters["datadog/api"],
)

assert.Nil(t, err)
assert.NotNil(t, exp)
}
10 changes: 10 additions & 0 deletions exporter/datadogexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,18 @@ module github.com/DataDog/opentelemetry-collector-contrib/exporter/datadogexport
go 1.15

require (
github.com/DataDog/datadog-agent v0.0.0-20200417180928-f454c60bc16f
github.com/DataDog/viper v1.8.0 // indirect
github.com/census-instrumentation/opencensus-proto v0.3.0
github.com/cihub/seelog v0.0.0-20170130134532-f561c5e57575 // indirect
github.com/gogo/protobuf v1.3.1
github.com/klauspost/compress v1.10.10
github.com/stretchr/testify v1.6.1
github.com/zorkian/go-datadog-api v2.29.0+incompatible // indirect
go.opencensus.io v0.22.4
go.opentelemetry.io/collector v0.11.1-0.20201001213035-035aa5cf6c92
go.uber.org/zap v1.16.0
google.golang.org/protobuf v1.25.0
gopkg.in/DataDog/dd-trace-go.v1 v1.26.0
gopkg.in/zorkian/go-datadog-api.v2 v2.29.0
)
18 changes: 18 additions & 0 deletions exporter/datadogexporter/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@ github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
github.com/DataDog/datadog-agent v0.0.0-20200417180928-f454c60bc16f h1:xxXb5hVZlZaqorgnkoLKiaUj4Qr09iV/mLhmnDVxmQ8=
github.com/DataDog/datadog-agent v0.0.0-20200417180928-f454c60bc16f/go.mod h1:f7AFj9QYK5z18qnWk459V90uDI4UFe+0ZoOxeboeRNk=
github.com/DataDog/datadog-go v3.2.0+incompatible h1:qSG2N4FghB1He/r2mFrWKCaL7dXCilEuNEeAn20fdD4=
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
github.com/DataDog/viper v1.8.0 h1:+0s6jzOzQEpMCW+c4bkirz+4vNoWm4jmiQNmKfO2p38=
github.com/DataDog/viper v1.8.0/go.mod h1:Gx7+/WONkbQIh3ac52KqcFTzipQ1OYHhCQGWAgHlzpc=
github.com/DataDog/zstd v1.3.6-0.20190409195224-796139022798/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo=
github.com/DataDog/zstd v1.4.4/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo=
github.com/Djarvur/go-err113 v0.0.0-20200511133814-5174e21577d5 h1:XTrzB+F8+SpRmbhAH8HLxhiiG6nYNwaBZjrFps1oWEk=
Expand Down Expand Up @@ -160,6 +165,8 @@ github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XL
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/cihub/seelog v0.0.0-20170130134532-f561c5e57575 h1:kHaBemcxl8o/pQ5VM1c8PVE1PubbNx3mjUr09OqWGCs=
github.com/cihub/seelog v0.0.0-20170130134532-f561c5e57575/go.mod h1:9d6lWj8KzO/fd/NrVaLscBKmPigpZpn5YawRPw+e3Yo=
github.com/circonus-labs/circonus-gometrics v2.3.1+incompatible/go.mod h1:nmEj6Dob7S7YxXgwXpfOuvO54S+tGdZdw9fuRZt25Ag=
github.com/circonus-labs/circonusllhist v0.1.3/go.mod h1:kMXHVDlOchFAehlya5ePtbp5jckzBHf4XRpQvBOLI+I=
github.com/clbanning/x2j v0.0.0-20191024224557-825249438eec/go.mod h1:jMjuTZXRI4dUb/I5gc9Hdhagfvm9+RyrPryS/auMzxE=
Expand All @@ -172,8 +179,10 @@ github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE
github.com/containerd/containerd v1.3.4 h1:3o0smo5SKY7H6AJCmJhsnCjR2/V2T8VmiHt7seN2/kI=
github.com/containerd/containerd v1.3.4/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA=
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
github.com/coreos/bbolt v1.3.3/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
github.com/coreos/go-oidc v2.2.1+incompatible h1:mh48q/BqXqgjVHpy2ZY7WnWAbenxRjsz9N1i1YxjHAk=
github.com/coreos/go-oidc v2.2.1+incompatible/go.mod h1:CgnwVTmzoESiwO9qyAFEMiHoZ1nMCKZlZ9V6mm3/LKc=
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
Expand Down Expand Up @@ -539,6 +548,7 @@ github.com/grpc-ecosystem/go-grpc-middleware v1.2.0/go.mod h1:mJzapYve32yjrKlk9G
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
github.com/grpc-ecosystem/grpc-gateway v1.13.0/go.mod h1:8XEsbTttt/W+VvjtQhLACqCisSPWTxCZ7sBRjU6iH9c=
github.com/grpc-ecosystem/grpc-gateway v1.14.5/go.mod h1:UJ0EZAp832vCd54Wev9N1BMKEyvcZ5+IM0AwDrnlkEc=
github.com/grpc-ecosystem/grpc-gateway v1.14.6/go.mod h1:zdiPV4Yse/1gnckTHtghG4GkDEdKCRJduHpTxT3/jcw=
github.com/grpc-ecosystem/grpc-gateway v1.15.0 h1:ntPNC9TD/6l2XDenJZe6T5lSMg95thpV9sGAqHX4WU8=
Expand Down Expand Up @@ -819,6 +829,7 @@ github.com/onsi/gomega v1.9.0/go.mod h1:Ho0h+IUsWyvy1OpqCwxlQ/21gkhVunqlU8fDGcoT
github.com/onsi/gomega v1.10.1 h1:o0+MgICZLuZ7xjH7Vx6zS/zcu93/BEp1VwkIW1mEXCE=
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk=
github.com/open-telemetry/opentelemetry-collector-contrib v0.11.0 h1:1rkTd2NRFlGEV4uXdZUJnwpSwRNOujt8t/VHIiG92K0=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opencontainers/image-spec v1.0.1 h1:JMemWkRwHx4Zj+fVxWoMCFm/8sYGGrUVojFA6h/TRcI=
Expand Down Expand Up @@ -1064,6 +1075,7 @@ github.com/tinylib/msgp v1.1.2 h1:gWmO7n0Ys2RBEb7GPYB9Ujq8Mk5p2U08lRnmMcGy6BQ=
github.com/tinylib/msgp v1.1.2/go.mod h1:+d+yLhGm8mzTaHzB+wgMYrodPfmZrzkirds8fDWklFE=
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/tmc/grpc-websocket-proxy v0.0.0-20200122045848-3419fae592fc/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/tommy-muehle/go-mnd v1.3.1-0.20200224220436-e6f9a994e8fa h1:RC4maTWLKKwb7p1cnoygsbKIgNlJqSYBeAFON3Ar8As=
github.com/tommy-muehle/go-mnd v1.3.1-0.20200224220436-e6f9a994e8fa/go.mod h1:dSUh0FtTP8VhvkL1S+gUR1OKd9ZnSaozuI6r3m6wOig=
github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM=
Expand All @@ -1074,6 +1086,8 @@ github.com/uber/jaeger-lib v2.2.0+incompatible/go.mod h1:ComeNDZlWwrWnDv8aPp0Ba6
github.com/uber/jaeger-lib v2.3.0+incompatible h1:B/kUIXcj6kIU3WSXgeJ7/uYj94I/r0LDa//JKgN/Sf0=
github.com/uber/jaeger-lib v2.3.0+incompatible/go.mod h1:ComeNDZlWwrWnDv8aPp0Ba6+uUTzImX/AauajbLI56U=
github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc=
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
github.com/ultraware/funlen v0.0.3 h1:5ylVWm8wsNwH5aWo9438pwvsK0QiqVuUrt9bn7S/iLA=
github.com/ultraware/funlen v0.0.3/go.mod h1:Dp4UiAus7Wdb9KUZsYWZEWiRzGuM2kXM1lPbfaF6xhA=
github.com/ultraware/whitespace v0.0.4 h1:If7Va4cM03mpgrNH9k49/VOicWpGoG70XPBFFODYDsg=
Expand All @@ -1100,6 +1114,7 @@ github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/zorkian/go-datadog-api v2.29.0+incompatible/go.mod h1:PkXwHX9CUQa/FpB9ZwAD45N1uhCW4MT/Wj7m36PbKss=
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg=
Expand Down Expand Up @@ -1137,6 +1152,7 @@ go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9E
go.uber.org/zap v1.9.1/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM=
go.uber.org/zap v1.14.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM=
go.uber.org/zap v1.16.0 h1:uFRZXykJGK9lLY4HtgSw44DnIcAM+kRBP7x5m+NpAOM=
go.uber.org/zap v1.16.0/go.mod h1:MA8QOfq0BHJwdXa996Y4dYkAqRKB8/1K1QMMZVaNZjQ=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
Expand Down Expand Up @@ -1497,6 +1513,8 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD
google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4=
google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c=
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
gopkg.in/DataDog/dd-trace-go.v1 v1.26.0 h1:Fxt3Z7Nc9NJwqaD5NMOEDANTOT3sUo4gViwFbnqJAfY=
gopkg.in/DataDog/dd-trace-go.v1 v1.26.0/go.mod h1:Sp1lku8WJMvNV0kjDI4Ni/T7J/U3BO5ct5kEaoVU8+I=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
91 changes: 91 additions & 0 deletions exporter/datadogexporter/model.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package datadogexporter

import (
"github.com/DataDog/datadog-agent/pkg/trace/event"
"github.com/DataDog/datadog-agent/pkg/trace/obfuscate"
"github.com/DataDog/datadog-agent/pkg/trace/pb"
"github.com/DataDog/datadog-agent/pkg/trace/sampler"
"github.com/DataDog/datadog-agent/pkg/trace/stats"
"github.com/DataDog/datadog-agent/pkg/trace/traceutil"
)

// ObfuscatePayload applies obfuscator rules to the trace payloads
func ObfuscatePayload(obfuscator *obfuscate.Obfuscator, tracePayloads []*pb.TracePayload) {
for _, tracePayload := range tracePayloads {

// Obfuscate the traces in the payload
for _, trace := range tracePayload.Traces {
for _, span := range trace.Spans {
obfuscator.Obfuscate(span)
}
}
}
}

// GetAnalyzedSpans finds all the analyzed spans in a trace, including top level spans
// and spans marked as analyzed by the tracer.
// A span is considered top-level if:
// - it's a root span
// - its parent is unknown (other part of the code, distributed trace)
// - its parent belongs to another service (in that case it's a "local root"
// being the highest ancestor of other spans belonging to this service and
// attached to it).
func GetAnalyzedSpans(sps []*pb.Span) []*pb.Span {
// build a lookup map
spanIDToIdx := make(map[uint64]int, len(sps))
for i, span := range sps {
spanIDToIdx[span.SpanID] = i
}

top := []*pb.Span{}

extractor := event.NewMetricBasedExtractor()

// iterate on each span and mark them as top-level if relevant
for _, span := range sps {
// The tracer can mark a span to be analyzed, with a value 0-1, where 1 is always keep, and 0 is always reject.
// Values between 0-1 are used by the agent to prioritize which spans are sampled or not. Since we can't
// reliably apply sampling decisions in a serverless environment, we keep any analyzed span with a priority
// greater than 0, and let the backend make the sampling decision instead.
priority, extracted := extractor.Extract(span, sampler.PriorityUserKeep)
shouldExtract := priority > 0 && extracted

if span.ParentID != 0 {
if parentIdx, ok := spanIDToIdx[span.ParentID]; ok && sps[parentIdx].Service == span.Service && !shouldExtract {
continue
}
}

top = append(top, span)
}
return top
}

// Compute Sublayers updates a spans metrics with relevant metadata so that it's duration and breakdown between different services can
// be accurately displayed in the Datadog UI
func ComputeSublayerMetrics(t pb.Trace) {
root := traceutil.GetRoot(t)
traceutil.ComputeTopLevel(t)

subtraces := stats.ExtractSubtraces(t, root)
sublayers := make(map[*pb.Span][]stats.SublayerValue)
for _, subtrace := range subtraces {
subtraceSublayers := stats.ComputeSublayers(subtrace.Trace)
sublayers[subtrace.Root] = subtraceSublayers
stats.SetSublayersOnSpan(subtrace.Root, subtraceSublayers)
}
}
72 changes: 72 additions & 0 deletions exporter/datadogexporter/stats.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package datadogexporter

import (
"github.com/DataDog/datadog-agent/pkg/trace/pb"
"github.com/DataDog/datadog-agent/pkg/trace/stats"
)

const (
statsBucketDuration int64 = 1e10 // 10 seconds
)

// ComputeAPMStats calculates the stats that should be submitted to APM about a given trace
func ComputeAPMStats(tracePayload *pb.TracePayload) *stats.Payload {

statsRawBuckets := make(map[int64]*stats.RawBucket)

for _, trace := range tracePayload.Traces {
spans := GetAnalyzedSpans(trace.Spans)

sublayers := stats.ComputeSublayers(trace.Spans)
for _, span := range spans {

// Aggregate the span to a bucket by rounding its end timestamp to the closest bucket ts.
// E.g., for buckets of size 10, a span ends on 36 should be aggregated to the second bucket
// with bucketTS 30 (36 - 36 % 10). Create a new bucket if needed.
spanEnd := span.Start + span.Duration
bucketTS := spanEnd - (spanEnd % statsBucketDuration)
var statsRawBucket *stats.RawBucket
if existingBucket, ok := statsRawBuckets[bucketTS]; ok {
statsRawBucket = existingBucket
} else {
statsRawBucket = stats.NewRawBucket(bucketTS, statsBucketDuration)
statsRawBuckets[bucketTS] = statsRawBucket
}

// Use weight 1, as sampling in opentelemetry would occur upstream in a processor.
// Generally we want to ship 100% of traces to the backend where more accurate tail based sampling can be performed.
// TopLevel is always "true" since we only compute stats for top-level spans.
weightedSpan := &stats.WeightedSpan{
Span: span,
Weight: 1,
TopLevel: true,
}
statsRawBucket.HandleSpan(weightedSpan, tracePayload.Env, []string{}, sublayers)
}
}

// Export statsRawBuckets to statsBuckets
statsBuckets := make([]stats.Bucket, 0)
for _, statsRawBucket := range statsRawBuckets {
statsBuckets = append(statsBuckets, statsRawBucket.Export())
}
return &stats.Payload{
HostName: tracePayload.HostName,
Env: tracePayload.Env,
Stats: statsBuckets,
}
}
Loading