Skip to content

Commit 92ae5bf

Browse files
committed
update code to v0.3
Signed-off-by: Alex Boten <[email protected]>
1 parent 8018790 commit 92ae5bf

File tree

5 files changed

+1295
-60
lines changed

5 files changed

+1295
-60
lines changed

config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ func ParseYAML(file []byte) (*OpenTelemetryConfiguration, error) {
150150

151151
return &cfg, nil
152152
}
153+
153154
func toStringMap(pairs []NameStringValuePair) map[string]string {
154155
output := make(map[string]string)
155156
for _, v := range pairs {

config/config_test.go

Lines changed: 147 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,88 @@ func TestNewSDK(t *testing.T) {
7878
}
7979
}
8080

81-
var v02OpenTelemetryConfig = OpenTelemetryConfiguration{
81+
var v03OpenTelemetryConfig = OpenTelemetryConfiguration{
8282
Disabled: ptr(false),
83-
FileFormat: "0.2",
83+
FileFormat: ptr("0.3"),
8484
AttributeLimits: &AttributeLimits{
8585
AttributeCountLimit: ptr(128),
8686
AttributeValueLengthLimit: ptr(4096),
8787
},
88+
Instrumentation: &Instrumentation{
89+
Cpp: LanguageSpecificInstrumentation{
90+
"example": map[string]interface{}{
91+
"property": "value",
92+
},
93+
},
94+
Dotnet: LanguageSpecificInstrumentation{
95+
"example": map[string]interface{}{
96+
"property": "value",
97+
},
98+
},
99+
Erlang: LanguageSpecificInstrumentation{
100+
"example": map[string]interface{}{
101+
"property": "value",
102+
},
103+
},
104+
General: &GeneralInstrumentation{
105+
Http: &GeneralInstrumentationHttp{
106+
Client: &GeneralInstrumentationHttpClient{
107+
RequestCapturedHeaders: []string{"Content-Type", "Accept"},
108+
ResponseCapturedHeaders: []string{"Content-Type", "Content-Encoding"},
109+
},
110+
Server: &GeneralInstrumentationHttpServer{
111+
RequestCapturedHeaders: []string{"Content-Type", "Accept"},
112+
ResponseCapturedHeaders: []string{"Content-Type", "Content-Encoding"},
113+
},
114+
},
115+
Peer: &GeneralInstrumentationPeer{
116+
ServiceMapping: []GeneralInstrumentationPeerServiceMappingElem{
117+
{Peer: "1.2.3.4", Service: "FooService"},
118+
{Peer: "2.3.4.5", Service: "BarService"},
119+
},
120+
},
121+
},
122+
Go: LanguageSpecificInstrumentation{
123+
"example": map[string]interface{}{
124+
"property": "value",
125+
},
126+
},
127+
Java: LanguageSpecificInstrumentation{
128+
"example": map[string]interface{}{
129+
"property": "value",
130+
},
131+
},
132+
Js: LanguageSpecificInstrumentation{
133+
"example": map[string]interface{}{
134+
"property": "value",
135+
},
136+
},
137+
Php: LanguageSpecificInstrumentation{
138+
"example": map[string]interface{}{
139+
"property": "value",
140+
},
141+
},
142+
Python: LanguageSpecificInstrumentation{
143+
"example": map[string]interface{}{
144+
"property": "value",
145+
},
146+
},
147+
Ruby: LanguageSpecificInstrumentation{
148+
"example": map[string]interface{}{
149+
"property": "value",
150+
},
151+
},
152+
Rust: LanguageSpecificInstrumentation{
153+
"example": map[string]interface{}{
154+
"property": "value",
155+
},
156+
},
157+
Swift: LanguageSpecificInstrumentation{
158+
"example": map[string]interface{}{
159+
"property": "value",
160+
},
161+
},
162+
},
88163
LoggerProvider: &LoggerProvider{
89164
Limits: &LogRecordLimits{
90165
AttributeCountLimit: ptr(128),
@@ -100,13 +175,14 @@ var v02OpenTelemetryConfig = OpenTelemetryConfiguration{
100175
ClientCertificate: ptr("/app/cert.pem"),
101176
ClientKey: ptr("/app/cert.pem"),
102177
Compression: ptr("gzip"),
103-
Endpoint: "http://localhost:4318",
104-
Headers: Headers{
105-
"api-key": "1234",
178+
Endpoint: ptr("http://localhost:4318/v1/logs"),
179+
Headers: []NameStringValuePair{
180+
{Name: "api-key", Value: ptr("1234")},
106181
},
107-
Insecure: ptr(false),
108-
Protocol: "http/protobuf",
109-
Timeout: ptr(10000),
182+
HeadersList: ptr("api-key=1234"),
183+
Insecure: ptr(false),
184+
Protocol: ptr("http/protobuf"),
185+
Timeout: ptr(10000),
110186
},
111187
},
112188
MaxExportBatchSize: ptr(512),
@@ -126,8 +202,11 @@ var v02OpenTelemetryConfig = OpenTelemetryConfiguration{
126202
MeterProvider: &MeterProvider{
127203
Readers: []MetricReader{
128204
{
205+
Producers: []MetricProducer{
206+
{Opencensus: MetricProducerOpencensus{}},
207+
},
129208
Pull: &PullMetricReader{
130-
Exporter: MetricExporter{
209+
Exporter: PullMetricExporter{
131210
Prometheus: &Prometheus{
132211
Host: ptr("localhost"),
133212
Port: ptr(9464),
@@ -143,20 +222,24 @@ var v02OpenTelemetryConfig = OpenTelemetryConfiguration{
143222
},
144223
},
145224
{
225+
Producers: []MetricProducer{
226+
{},
227+
},
146228
Periodic: &PeriodicMetricReader{
147-
Exporter: MetricExporter{
229+
Exporter: PushMetricExporter{
148230
OTLP: &OTLPMetric{
149231
Certificate: ptr("/app/cert.pem"),
150232
ClientCertificate: ptr("/app/cert.pem"),
151233
ClientKey: ptr("/app/cert.pem"),
152234
Compression: ptr("gzip"),
153235
DefaultHistogramAggregation: ptr(OTLPMetricDefaultHistogramAggregationBase2ExponentialBucketHistogram),
154-
Endpoint: "http://localhost:4318",
155-
Headers: Headers{
156-
"api-key": "1234",
236+
Endpoint: ptr("http://localhost:4318/v1/metrics"),
237+
Headers: []NameStringValuePair{
238+
{Name: "api-key", Value: ptr("1234")},
157239
},
240+
HeadersList: ptr("api-key=1234"),
158241
Insecure: ptr(false),
159-
Protocol: "http/protobuf",
242+
Protocol: ptr("http/protobuf"),
160243
TemporalityPreference: ptr("delta"),
161244
Timeout: ptr(10000),
162245
},
@@ -167,7 +250,7 @@ var v02OpenTelemetryConfig = OpenTelemetryConfiguration{
167250
},
168251
{
169252
Periodic: &PeriodicMetricReader{
170-
Exporter: MetricExporter{
253+
Exporter: PushMetricExporter{
171254
Console: Console{},
172255
},
173256
},
@@ -190,20 +273,32 @@ var v02OpenTelemetryConfig = OpenTelemetryConfiguration{
190273
RecordMinMax: ptr(true),
191274
},
192275
},
193-
AttributeKeys: []string{"key1", "key2"},
194-
Description: ptr("new_description"),
195-
Name: ptr("new_instrument_name"),
276+
AttributeKeys: &IncludeExclude{
277+
Included: []string{"key1", "key2"},
278+
Excluded: []string{"key3"},
279+
},
280+
Description: ptr("new_description"),
281+
Name: ptr("new_instrument_name"),
196282
},
197283
},
198284
},
199285
},
200286
Propagator: &Propagator{
201-
Composite: []string{"tracecontext", "baggage", "b3", "b3multi", "jaeger", "xray", "ottrace"},
287+
Composite: []*string{ptr("tracecontext"), ptr("baggage"), ptr("b3"), ptr("b3multi"), ptr("jaeger"), ptr("xray"), ptr("ottrace")},
202288
},
203289
Resource: &Resource{
204-
Attributes: Attributes{
205-
"service.name": "unknown_service",
290+
Attributes: []AttributeNameValue{
291+
{Name: "service.name", Value: "unknown_service"},
292+
{Name: "string_key", Type: &AttributeNameValueType{Value: "string"}, Value: "value"},
293+
{Name: "bool_key", Type: &AttributeNameValueType{Value: "bool"}, Value: true},
294+
{Name: "int_key", Type: &AttributeNameValueType{Value: "int"}, Value: float64(1)},
295+
{Name: "double_key", Type: &AttributeNameValueType{Value: "double"}, Value: 1.1},
296+
{Name: "string_array_key", Type: &AttributeNameValueType{Value: "string_array"}, Value: []interface{}{"value1", "value2"}},
297+
{Name: "bool_array_key", Type: &AttributeNameValueType{Value: "bool_array"}, Value: []interface{}{true, false}},
298+
{Name: "int_array_key", Type: &AttributeNameValueType{Value: "int_array"}, Value: []interface{}{float64(1), float64(2)}},
299+
{Name: "double_array_key", Type: &AttributeNameValueType{Value: "double_array"}, Value: []interface{}{1.1, 2.2}},
206300
},
301+
AttributesList: ptr("service.namespace=my-namespace,service.version=1.0.0"),
207302
Detectors: &Detectors{
208303
Attributes: &DetectorsAttributes{
209304
Excluded: []string{"process.command_args"},
@@ -231,13 +326,14 @@ var v02OpenTelemetryConfig = OpenTelemetryConfiguration{
231326
ClientCertificate: ptr("/app/cert.pem"),
232327
ClientKey: ptr("/app/cert.pem"),
233328
Compression: ptr("gzip"),
234-
Endpoint: "http://localhost:4318",
235-
Headers: Headers{
236-
"api-key": "1234",
329+
Endpoint: ptr("http://localhost:4318/v1/traces"),
330+
Headers: []NameStringValuePair{
331+
{Name: "api-key", Value: ptr("1234")},
237332
},
238-
Insecure: ptr(false),
239-
Protocol: "http/protobuf",
240-
Timeout: ptr(10000),
333+
HeadersList: ptr("api-key=1234"),
334+
Insecure: ptr(false),
335+
Protocol: ptr("http/protobuf"),
336+
Timeout: ptr(10000),
241337
},
242338
},
243339
MaxExportBatchSize: ptr(512),
@@ -249,7 +345,7 @@ var v02OpenTelemetryConfig = OpenTelemetryConfiguration{
249345
Batch: &BatchSpanProcessor{
250346
Exporter: SpanExporter{
251347
Zipkin: &Zipkin{
252-
Endpoint: "http://localhost:9411/api/v2/spans",
348+
Endpoint: ptr("http://localhost:9411/api/v2/spans"),
253349
Timeout: ptr(10000),
254350
},
255351
},
@@ -300,7 +396,7 @@ func TestParseYAML(t *testing.T) {
300396
wantErr: nil,
301397
wantType: &OpenTelemetryConfiguration{
302398
Disabled: ptr(false),
303-
FileFormat: "0.1",
399+
FileFormat: ptr("0.1"),
304400
},
305401
},
306402
{
@@ -310,9 +406,19 @@ func TestParseYAML(t *testing.T) {
310406
line 2: cannot unmarshal !!str ` + "`notabool`" + ` into bool`),
311407
},
312408
{
313-
name: "valid v0.2 config",
314-
input: "v0.2.yaml",
315-
wantType: &v02OpenTelemetryConfig,
409+
name: "valid v0.2 config",
410+
input: "v0.2.yaml",
411+
wantErr: errors.New(`yaml: unmarshal errors:
412+
line 81: cannot unmarshal !!map into []config.NameStringValuePair
413+
line 185: cannot unmarshal !!map into []config.NameStringValuePair
414+
line 244: cannot unmarshal !!seq into config.IncludeExclude
415+
line 305: cannot unmarshal !!map into []config.NameStringValuePair
416+
line 408: cannot unmarshal !!map into []config.AttributeNameValue`),
417+
},
418+
{
419+
name: "valid v0.3 config",
420+
input: "v0.3.yaml",
421+
wantType: &v03OpenTelemetryConfig,
316422
},
317423
}
318424

@@ -345,7 +451,7 @@ func TestSerializeJSON(t *testing.T) {
345451
wantErr: nil,
346452
wantType: OpenTelemetryConfiguration{
347453
Disabled: ptr(false),
348-
FileFormat: "0.1",
454+
FileFormat: ptr("0.1"),
349455
},
350456
},
351457
{
@@ -354,9 +460,14 @@ func TestSerializeJSON(t *testing.T) {
354460
wantErr: errors.New(`json: cannot unmarshal string into Go struct field Plain.disabled of type bool`),
355461
},
356462
{
357-
name: "valid v0.2 config",
358-
input: "v0.2.json",
359-
wantType: v02OpenTelemetryConfig,
463+
name: "valid v0.2 config",
464+
input: "v0.2.json",
465+
wantErr: errors.New(`json: cannot unmarshal object into Go struct field LogRecordProcessor.logger_provider.processors.batch of type []config.NameStringValuePair`),
466+
},
467+
{
468+
name: "valid v0.3 config",
469+
input: "v0.3.json",
470+
wantType: v03OpenTelemetryConfig,
360471
},
361472
}
362473

0 commit comments

Comments
 (0)