Skip to content

Commit

Permalink
update code to v0.3
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Boten <[email protected]>
  • Loading branch information
codeboten committed Oct 9, 2024
1 parent 0755f9b commit ffe8eef
Show file tree
Hide file tree
Showing 5 changed files with 1,295 additions and 60 deletions.
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ func ParseYAML(file []byte) (*OpenTelemetryConfiguration, error) {

return &cfg, nil
}

func toStringMap(pairs []NameStringValuePair) map[string]string {
output := make(map[string]string)
for _, v := range pairs {
Expand Down
183 changes: 147 additions & 36 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,88 @@ func TestNewSDK(t *testing.T) {
}
}

var v02OpenTelemetryConfig = OpenTelemetryConfiguration{
var v03OpenTelemetryConfig = OpenTelemetryConfiguration{
Disabled: ptr(false),
FileFormat: "0.2",
FileFormat: ptr("0.3"),
AttributeLimits: &AttributeLimits{
AttributeCountLimit: ptr(128),
AttributeValueLengthLimit: ptr(4096),
},
Instrumentation: &Instrumentation{
Cpp: LanguageSpecificInstrumentation{
"example": map[string]interface{}{
"property": "value",
},
},
Dotnet: LanguageSpecificInstrumentation{
"example": map[string]interface{}{
"property": "value",
},
},
Erlang: LanguageSpecificInstrumentation{
"example": map[string]interface{}{
"property": "value",
},
},
General: &GeneralInstrumentation{
Http: &GeneralInstrumentationHttp{
Client: &GeneralInstrumentationHttpClient{
RequestCapturedHeaders: []string{"Content-Type", "Accept"},
ResponseCapturedHeaders: []string{"Content-Type", "Content-Encoding"},
},
Server: &GeneralInstrumentationHttpServer{
RequestCapturedHeaders: []string{"Content-Type", "Accept"},
ResponseCapturedHeaders: []string{"Content-Type", "Content-Encoding"},
},
},
Peer: &GeneralInstrumentationPeer{
ServiceMapping: []GeneralInstrumentationPeerServiceMappingElem{
{Peer: "1.2.3.4", Service: "FooService"},
{Peer: "2.3.4.5", Service: "BarService"},
},
},
},
Go: LanguageSpecificInstrumentation{
"example": map[string]interface{}{
"property": "value",
},
},
Java: LanguageSpecificInstrumentation{
"example": map[string]interface{}{
"property": "value",
},
},
Js: LanguageSpecificInstrumentation{
"example": map[string]interface{}{
"property": "value",
},
},
Php: LanguageSpecificInstrumentation{
"example": map[string]interface{}{
"property": "value",
},
},
Python: LanguageSpecificInstrumentation{
"example": map[string]interface{}{
"property": "value",
},
},
Ruby: LanguageSpecificInstrumentation{
"example": map[string]interface{}{
"property": "value",
},
},
Rust: LanguageSpecificInstrumentation{
"example": map[string]interface{}{
"property": "value",
},
},
Swift: LanguageSpecificInstrumentation{
"example": map[string]interface{}{
"property": "value",
},
},
},
LoggerProvider: &LoggerProvider{
Limits: &LogRecordLimits{
AttributeCountLimit: ptr(128),
Expand All @@ -100,13 +175,14 @@ var v02OpenTelemetryConfig = OpenTelemetryConfiguration{
ClientCertificate: ptr("/app/cert.pem"),
ClientKey: ptr("/app/cert.pem"),
Compression: ptr("gzip"),
Endpoint: "http://localhost:4318",
Headers: Headers{
"api-key": "1234",
Endpoint: ptr("http://localhost:4318/v1/logs"),
Headers: []NameStringValuePair{
{Name: "api-key", Value: ptr("1234")},
},
Insecure: ptr(false),
Protocol: "http/protobuf",
Timeout: ptr(10000),
HeadersList: ptr("api-key=1234"),
Insecure: ptr(false),
Protocol: ptr("http/protobuf"),
Timeout: ptr(10000),
},
},
MaxExportBatchSize: ptr(512),
Expand All @@ -126,8 +202,11 @@ var v02OpenTelemetryConfig = OpenTelemetryConfiguration{
MeterProvider: &MeterProvider{
Readers: []MetricReader{
{
Producers: []MetricProducer{
{Opencensus: MetricProducerOpencensus{}},
},
Pull: &PullMetricReader{
Exporter: MetricExporter{
Exporter: PullMetricExporter{
Prometheus: &Prometheus{
Host: ptr("localhost"),
Port: ptr(9464),
Expand All @@ -143,20 +222,24 @@ var v02OpenTelemetryConfig = OpenTelemetryConfiguration{
},
},
{
Producers: []MetricProducer{
{},
},
Periodic: &PeriodicMetricReader{
Exporter: MetricExporter{
Exporter: PushMetricExporter{
OTLP: &OTLPMetric{
Certificate: ptr("/app/cert.pem"),
ClientCertificate: ptr("/app/cert.pem"),
ClientKey: ptr("/app/cert.pem"),
Compression: ptr("gzip"),
DefaultHistogramAggregation: ptr(OTLPMetricDefaultHistogramAggregationBase2ExponentialBucketHistogram),
Endpoint: "http://localhost:4318",
Headers: Headers{
"api-key": "1234",
Endpoint: ptr("http://localhost:4318/v1/metrics"),
Headers: []NameStringValuePair{
{Name: "api-key", Value: ptr("1234")},
},
HeadersList: ptr("api-key=1234"),
Insecure: ptr(false),
Protocol: "http/protobuf",
Protocol: ptr("http/protobuf"),
TemporalityPreference: ptr("delta"),
Timeout: ptr(10000),
},
Expand All @@ -167,7 +250,7 @@ var v02OpenTelemetryConfig = OpenTelemetryConfiguration{
},
{
Periodic: &PeriodicMetricReader{
Exporter: MetricExporter{
Exporter: PushMetricExporter{
Console: Console{},
},
},
Expand All @@ -190,20 +273,32 @@ var v02OpenTelemetryConfig = OpenTelemetryConfiguration{
RecordMinMax: ptr(true),
},
},
AttributeKeys: []string{"key1", "key2"},
Description: ptr("new_description"),
Name: ptr("new_instrument_name"),
AttributeKeys: &IncludeExclude{
Included: []string{"key1", "key2"},
Excluded: []string{"key3"},
},
Description: ptr("new_description"),
Name: ptr("new_instrument_name"),
},
},
},
},
Propagator: &Propagator{
Composite: []string{"tracecontext", "baggage", "b3", "b3multi", "jaeger", "xray", "ottrace"},
Composite: []*string{ptr("tracecontext"), ptr("baggage"), ptr("b3"), ptr("b3multi"), ptr("jaeger"), ptr("xray"), ptr("ottrace")},
},
Resource: &Resource{
Attributes: Attributes{
"service.name": "unknown_service",
Attributes: []AttributeNameValue{
{Name: "service.name", Value: "unknown_service"},
{Name: "string_key", Type: &AttributeNameValueType{Value: "string"}, Value: "value"},
{Name: "bool_key", Type: &AttributeNameValueType{Value: "bool"}, Value: true},
{Name: "int_key", Type: &AttributeNameValueType{Value: "int"}, Value: float64(1)},
{Name: "double_key", Type: &AttributeNameValueType{Value: "double"}, Value: 1.1},
{Name: "string_array_key", Type: &AttributeNameValueType{Value: "string_array"}, Value: []interface{}{"value1", "value2"}},
{Name: "bool_array_key", Type: &AttributeNameValueType{Value: "bool_array"}, Value: []interface{}{true, false}},
{Name: "int_array_key", Type: &AttributeNameValueType{Value: "int_array"}, Value: []interface{}{float64(1), float64(2)}},
{Name: "double_array_key", Type: &AttributeNameValueType{Value: "double_array"}, Value: []interface{}{1.1, 2.2}},
},
AttributesList: ptr("service.namespace=my-namespace,service.version=1.0.0"),
Detectors: &Detectors{
Attributes: &DetectorsAttributes{
Excluded: []string{"process.command_args"},
Expand Down Expand Up @@ -231,13 +326,14 @@ var v02OpenTelemetryConfig = OpenTelemetryConfiguration{
ClientCertificate: ptr("/app/cert.pem"),
ClientKey: ptr("/app/cert.pem"),
Compression: ptr("gzip"),
Endpoint: "http://localhost:4318",
Headers: Headers{
"api-key": "1234",
Endpoint: ptr("http://localhost:4318/v1/traces"),
Headers: []NameStringValuePair{
{Name: "api-key", Value: ptr("1234")},
},
Insecure: ptr(false),
Protocol: "http/protobuf",
Timeout: ptr(10000),
HeadersList: ptr("api-key=1234"),
Insecure: ptr(false),
Protocol: ptr("http/protobuf"),
Timeout: ptr(10000),
},
},
MaxExportBatchSize: ptr(512),
Expand All @@ -249,7 +345,7 @@ var v02OpenTelemetryConfig = OpenTelemetryConfiguration{
Batch: &BatchSpanProcessor{
Exporter: SpanExporter{
Zipkin: &Zipkin{
Endpoint: "http://localhost:9411/api/v2/spans",
Endpoint: ptr("http://localhost:9411/api/v2/spans"),
Timeout: ptr(10000),
},
},
Expand Down Expand Up @@ -300,7 +396,7 @@ func TestParseYAML(t *testing.T) {
wantErr: nil,
wantType: &OpenTelemetryConfiguration{
Disabled: ptr(false),
FileFormat: "0.1",
FileFormat: ptr("0.1"),
},
},
{
Expand All @@ -310,9 +406,19 @@ func TestParseYAML(t *testing.T) {
line 2: cannot unmarshal !!str ` + "`notabool`" + ` into bool`),
},
{
name: "valid v0.2 config",
input: "v0.2.yaml",
wantType: &v02OpenTelemetryConfig,
name: "valid v0.2 config",
input: "v0.2.yaml",
wantErr: errors.New(`yaml: unmarshal errors:
line 81: cannot unmarshal !!map into []config.NameStringValuePair
line 185: cannot unmarshal !!map into []config.NameStringValuePair
line 244: cannot unmarshal !!seq into config.IncludeExclude
line 305: cannot unmarshal !!map into []config.NameStringValuePair
line 408: cannot unmarshal !!map into []config.AttributeNameValue`),
},
{
name: "valid v0.3 config",
input: "v0.3.yaml",
wantType: &v03OpenTelemetryConfig,
},
}

Expand Down Expand Up @@ -345,7 +451,7 @@ func TestSerializeJSON(t *testing.T) {
wantErr: nil,
wantType: OpenTelemetryConfiguration{
Disabled: ptr(false),
FileFormat: "0.1",
FileFormat: ptr("0.1"),
},
},
{
Expand All @@ -354,9 +460,14 @@ func TestSerializeJSON(t *testing.T) {
wantErr: errors.New(`json: cannot unmarshal string into Go struct field Plain.disabled of type bool`),
},
{
name: "valid v0.2 config",
input: "v0.2.json",
wantType: v02OpenTelemetryConfig,
name: "valid v0.2 config",
input: "v0.2.json",
wantErr: errors.New(`json: cannot unmarshal object into Go struct field LogRecordProcessor.logger_provider.processors.batch of type []config.NameStringValuePair`),
},
{
name: "valid v0.3 config",
input: "v0.3.json",
wantType: v03OpenTelemetryConfig,
},
}

Expand Down
Loading

0 comments on commit ffe8eef

Please sign in to comment.