forked from open-telemetry/opentelemetry-collector-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
172 lines (150 loc) · 5.13 KB
/
config.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
// 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:https://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 translator // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/internal/model/translator"
import "fmt"
type translatorConfig struct {
// metrics export behavior
HistMode HistogramMode
SendCountSum bool
Quantiles bool
SendMonotonic bool
ResourceAttributesAsTags bool
// Deprecated: [0.54.0] Use InstrumentationScopeMetadataAsTags instead in favor of
// https://github.com/open-telemetry/opentelemetry-proto/releases/tag/v0.15.0
// Both must not be enabled at the same time.
InstrumentationLibraryMetadataAsTags bool
InstrumentationScopeMetadataAsTags bool
// cache configuration
sweepInterval int64
deltaTTL int64
// hostname provider configuration
previewHostnameFromAttributes bool
fallbackHostnameProvider HostnameProvider
}
// Option is a translator creation option.
type Option func(*translatorConfig) error
// WithDeltaTTL sets the delta TTL for cumulative metrics datapoints.
// By default, 3600 seconds are used.
func WithDeltaTTL(deltaTTL int64) Option {
return func(t *translatorConfig) error {
if deltaTTL <= 0 {
return fmt.Errorf("time to live must be positive: %d", deltaTTL)
}
t.deltaTTL = deltaTTL
t.sweepInterval = 1
if t.deltaTTL > 1 {
t.sweepInterval = t.deltaTTL / 2
}
return nil
}
}
// WithFallbackHostnameProvider sets the fallback hostname provider.
// By default, an empty hostname is used as a fallback.
func WithFallbackHostnameProvider(provider HostnameProvider) Option {
return func(t *translatorConfig) error {
t.fallbackHostnameProvider = provider
return nil
}
}
// WithPreviewHostnameFromAttributes enables the preview hostname algorithm.
func WithPreviewHostnameFromAttributes() Option {
return func(t *translatorConfig) error {
t.previewHostnameFromAttributes = true
return nil
}
}
// WithQuantiles enables quantiles exporting for summary metrics.
func WithQuantiles() Option {
return func(t *translatorConfig) error {
t.Quantiles = true
return nil
}
}
// WithResourceAttributesAsTags sets resource attributes as tags.
func WithResourceAttributesAsTags() Option {
return func(t *translatorConfig) error {
t.ResourceAttributesAsTags = true
return nil
}
}
// WithInstrumentationLibraryMetadataAsTags sets instrumentation library metadata as tags.
func WithInstrumentationLibraryMetadataAsTags() Option {
return func(t *translatorConfig) error {
t.InstrumentationLibraryMetadataAsTags = true
return nil
}
}
// WithInstrumentationScopeMetadataAsTags sets instrumentation scope metadata as tags.
func WithInstrumentationScopeMetadataAsTags() Option {
return func(t *translatorConfig) error {
t.InstrumentationScopeMetadataAsTags = true
return nil
}
}
// HistogramMode is an export mode for OTLP Histogram metrics.
type HistogramMode string
const (
// HistogramModeNoBuckets disables bucket export.
HistogramModeNoBuckets HistogramMode = "nobuckets"
// HistogramModeCounters exports buckets as Datadog counts.
HistogramModeCounters HistogramMode = "counters"
// HistogramModeDistributions exports buckets as Datadog distributions.
HistogramModeDistributions HistogramMode = "distributions"
)
// WithHistogramMode sets the histograms mode.
// The default mode is HistogramModeOff.
func WithHistogramMode(mode HistogramMode) Option {
return func(t *translatorConfig) error {
switch mode {
case HistogramModeNoBuckets, HistogramModeCounters, HistogramModeDistributions:
t.HistMode = mode
default:
return fmt.Errorf("unknown histogram mode: %q", mode)
}
return nil
}
}
// WithCountSumMetrics exports .count and .sum histogram metrics.
func WithCountSumMetrics() Option {
return func(t *translatorConfig) error {
t.SendCountSum = true
return nil
}
}
// NumberMode is an export mode for OTLP Number metrics.
type NumberMode string
const (
// NumberModeCumulativeToDelta calculates delta for
// cumulative monotonic metrics in the client side and reports
// them as Datadog counts.
NumberModeCumulativeToDelta NumberMode = "cumulative_to_delta"
// NumberModeRawValue reports the raw value for cumulative monotonic
// metrics as a Datadog gauge.
NumberModeRawValue NumberMode = "raw_value"
)
// WithNumberMode sets the number mode.
// The default mode is NumberModeCumulativeToDelta.
func WithNumberMode(mode NumberMode) Option {
return func(t *translatorConfig) error {
switch mode {
case NumberModeCumulativeToDelta:
t.SendMonotonic = true
case NumberModeRawValue:
t.SendMonotonic = false
default:
return fmt.Errorf("unknown number mode: %q", mode)
}
return nil
}
}