This repository has been archived by the owner on Nov 7, 2022. It is now read-only.
/
datadog.go
98 lines (81 loc) · 2.98 KB
/
datadog.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Copyright 2018, OpenCensus 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 exporterparser
import (
"context"
datadog "github.com/DataDog/opencensus-go-exporter-datadog"
"github.com/census-instrumentation/opencensus-service/data"
"github.com/census-instrumentation/opencensus-service/exporter"
)
type datadogConfig struct {
// Namespace specifies the namespaces to which metric keys are appended.
Namespace string `yaml:"namespace,omitempty"`
// TraceAddr specifies the host[:port] address of the Datadog Trace Agent.
// It defaults to localhost:8126.
TraceAddr string `yaml:"trace_addr,omitempty"`
// MetricsAddr specifies the host[:port] address for DogStatsD. It defaults
// to localhost:8125.
MetricsAddr string `yaml:"metrics_addr,omitempty"`
// Tags specifies a set of global tags to attach to each metric.
Tags []string `yaml:"tags,omitempty"`
EnableTracing bool `yaml:"enable_tracing,omitempty"`
EnableMetrics bool `yaml:"enable_metrics,omitempty"`
}
type datadogExporter struct {
exporter *datadog.Exporter
}
// DatadogTraceExportersFromYAML parses the yaml bytes and returns an exporter.TraceExporter targeting
// Datadog according to the configuration settings.
func DatadogTraceExportersFromYAML(config []byte) (tes []exporter.TraceExporter, mes []exporter.MetricsExporter, doneFns []func() error, err error) {
var cfg struct {
Exporters *struct {
Datadog *datadogConfig `yaml:"datadog"`
} `yaml:"exporters"`
}
if err := yamlUnmarshal(config, &cfg); err != nil {
return nil, nil, nil, err
}
if cfg.Exporters == nil {
return nil, nil, nil, nil
}
dc := cfg.Exporters.Datadog
if dc == nil {
return nil, nil, nil, nil
}
if !dc.EnableTracing && !dc.EnableMetrics {
return nil, nil, nil, nil
}
// TODO(jbd): Create new exporter for each service name.
de := datadog.NewExporter(datadog.Options{
Namespace: dc.Namespace,
TraceAddr: dc.TraceAddr,
StatsAddr: dc.MetricsAddr,
Tags: dc.Tags,
})
doneFns = append(doneFns, func() error {
de.Stop()
return nil
})
dexp := &datadogExporter{exporter: de}
tes = append(tes, dexp)
// TODO: (@odeke-em, @songya23) implement ExportMetrics for Datadog.
// mes = append(mes, oexp)
return
}
func (dde *datadogExporter) ExportSpans(ctx context.Context, td data.TraceData) error {
// TODO: Examine the Datadog exporter to see
// if trace.ExportSpan was constraining and if perhaps the
// upload can use the context and information from the Node.
return exportSpans(ctx, "datadog", dde.exporter, td)
}