diff --git a/CHANGELOG.md b/CHANGELOG.md index bcf657f9fab..4936ac646b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ ### 🛑 Breaking changes 🛑 +- Remove the InstrumentationLibrary to Scope translation (part of transition to OTLP 0.19). (#5819) + - This has a side effect that when sending JSON encoded telemetry using OTLP proto <= 0.15.0, telemetry will be dropped. - Require the storage to be explicitly set for the (experimental) persistent queue (#5784) - Remove deprecated `confighttp.HTTPClientSettings.ToClientWithHost` (#5803) - Remove deprecated component stability helpers (#5802): diff --git a/pdata/internal/otlp/logs.go b/pdata/internal/otlp/logs.go index a94fc24b6da..d89a36de8a9 100644 --- a/pdata/internal/otlp/logs.go +++ b/pdata/internal/otlp/logs.go @@ -15,34 +15,9 @@ package otlp // import "go.opentelemetry.io/collector/pdata/internal/otlp" import ( - otlpcommon "go.opentelemetry.io/collector/pdata/internal/data/protogen/common/v1" otlplogs "go.opentelemetry.io/collector/pdata/internal/data/protogen/logs/v1" ) -// InstrumentationLibraryLogsToScope implements the translation of resource logs data -// following the v0.15.0 upgrade: -// -// receivers SHOULD check if instrumentation_library_logs is set -// and scope_logs is not set then the value in instrumentation_library_logs -// SHOULD be used instead by converting InstrumentationLibraryLogs into ScopeLogs. -// If scope_logs is set then instrumentation_library_logs SHOULD be ignored. -// -// https://github.com/open-telemetry/opentelemetry-proto/blob/3c2915c01a9fb37abfc0415ec71247c4978386b0/opentelemetry/proto/logs/v1/logs.proto#L58 -func InstrumentationLibraryLogsToScope(rls []*otlplogs.ResourceLogs) { - for _, rl := range rls { - if len(rl.ScopeLogs) == 0 { - for _, ill := range rl.InstrumentationLibraryLogs { - scopeLogs := otlplogs.ScopeLogs{ - Scope: otlpcommon.InstrumentationScope{ - Name: ill.InstrumentationLibrary.Name, - Version: ill.InstrumentationLibrary.Version, - }, - LogRecords: ill.LogRecords, - SchemaUrl: ill.SchemaUrl, - } - rl.ScopeLogs = append(rl.ScopeLogs, &scopeLogs) - } - } - rl.InstrumentationLibraryLogs = nil - } -} +// MigrateLogs implements any translation needed due to deprecation in OTLP logs protocol. +// Any plog.Unmarshaler implementation from OTLP (proto/json) MUST call this, and the gRPC Server implementation. +func MigrateLogs(_ []*otlplogs.ResourceLogs) {} diff --git a/pdata/internal/otlp/metrics.go b/pdata/internal/otlp/metrics.go index 7f65ec5d9e0..775ace72b83 100644 --- a/pdata/internal/otlp/metrics.go +++ b/pdata/internal/otlp/metrics.go @@ -15,34 +15,9 @@ package otlp // import "go.opentelemetry.io/collector/pdata/internal/otlp" import ( - otlpcommon "go.opentelemetry.io/collector/pdata/internal/data/protogen/common/v1" otlpmetrics "go.opentelemetry.io/collector/pdata/internal/data/protogen/metrics/v1" ) -// InstrumentationLibraryMetricsToScope implements the translation of resource metrics data -// following the v0.15.0 upgrade: -// -// receivers SHOULD check if instrumentation_library_metrics is set -// and scope_metrics is not set then the value in instrumentation_library_metrics -// SHOULD be used instead by converting InstrumentationLibraryMetrics into ScopeMetrics. -// If scope_metrics is set then instrumentation_library_metrics SHOULD be ignored. -// -// https://github.com/open-telemetry/opentelemetry-proto/blob/3c2915c01a9fb37abfc0415ec71247c4978386b0/opentelemetry/proto/metrics/v1/metrics.proto#L58 -func InstrumentationLibraryMetricsToScope(rms []*otlpmetrics.ResourceMetrics) { - for _, rm := range rms { - if len(rm.ScopeMetrics) == 0 { - for _, ilm := range rm.InstrumentationLibraryMetrics { - scopeMetrics := otlpmetrics.ScopeMetrics{ - Scope: otlpcommon.InstrumentationScope{ - Name: ilm.InstrumentationLibrary.Name, - Version: ilm.InstrumentationLibrary.Version, - }, - Metrics: ilm.Metrics, - SchemaUrl: ilm.SchemaUrl, - } - rm.ScopeMetrics = append(rm.ScopeMetrics, &scopeMetrics) - } - } - rm.InstrumentationLibraryMetrics = nil - } -} +// MigrateMetrics implements any translation needed due to deprecation in OTLP metrics protocol. +// Any pmetric.Unmarshaler implementation from OTLP (proto/json) MUST call this, and the gRPC Server implementation. +func MigrateMetrics(_ []*otlpmetrics.ResourceMetrics) {} diff --git a/pdata/internal/otlp/traces.go b/pdata/internal/otlp/traces.go index 0658f2a19d4..70d202aea12 100644 --- a/pdata/internal/otlp/traces.go +++ b/pdata/internal/otlp/traces.go @@ -15,34 +15,9 @@ package otlp // import "go.opentelemetry.io/collector/pdata/internal/otlp" import ( - otlpcommon "go.opentelemetry.io/collector/pdata/internal/data/protogen/common/v1" otlptrace "go.opentelemetry.io/collector/pdata/internal/data/protogen/trace/v1" ) -// InstrumentationLibraryToScope implements the translation of resource span data -// following the v0.15.0 upgrade: -// -// receivers SHOULD check if instrumentation_library_spans is set -// and scope_spans is not set then the value in instrumentation_library_spans -// SHOULD be used instead by converting InstrumentationLibrarySpans into ScopeSpans. -// If scope_spans is set then instrumentation_library_spans SHOULD be ignored. -// -// https://github.com/open-telemetry/opentelemetry-proto/blob/3c2915c01a9fb37abfc0415ec71247c4978386b0/opentelemetry/proto/trace/v1/trace.proto#L58 -func InstrumentationLibrarySpansToScope(rss []*otlptrace.ResourceSpans) { - for _, rs := range rss { - if len(rs.ScopeSpans) == 0 { - for _, ils := range rs.InstrumentationLibrarySpans { - scopeSpans := otlptrace.ScopeSpans{ - Scope: otlpcommon.InstrumentationScope{ - Name: ils.InstrumentationLibrary.Name, - Version: ils.InstrumentationLibrary.Version, - }, - Spans: ils.Spans, - SchemaUrl: ils.SchemaUrl, - } - rs.ScopeSpans = append(rs.ScopeSpans, &scopeSpans) - } - } - rs.InstrumentationLibrarySpans = nil - } -} +// MigrateTraces implements any translation needed due to deprecation in OTLP traces protocol. +// Any ptrace.Unmarshaler implementation from OTLP (proto/json) MUST call this, and the gRPC Server implementation. +func MigrateTraces(_ []*otlptrace.ResourceSpans) {} diff --git a/pdata/plog/json.go b/pdata/plog/json.go index d66e31a7872..050651ae740 100644 --- a/pdata/plog/json.go +++ b/pdata/plog/json.go @@ -62,6 +62,6 @@ func (d *jsonUnmarshaler) UnmarshalLogs(buf []byte) (Logs, error) { if err := d.delegate.Unmarshal(bytes.NewReader(buf), &ld); err != nil { return Logs{}, err } - otlp.InstrumentationLibraryLogsToScope(ld.ResourceLogs) + otlp.MigrateLogs(ld.ResourceLogs) return internal.LogsFromProto(ld), nil } diff --git a/pdata/plog/plogotlp/logs.go b/pdata/plog/plogotlp/logs.go index 822370c2273..4026fdc9db1 100644 --- a/pdata/plog/plogotlp/logs.go +++ b/pdata/plog/plogotlp/logs.go @@ -92,7 +92,7 @@ func (lr Request) UnmarshalProto(data []byte) error { if err := lr.orig.Unmarshal(data); err != nil { return err } - otlp.InstrumentationLibraryLogsToScope(lr.orig.ResourceLogs) + otlp.MigrateLogs(lr.orig.ResourceLogs) return nil } @@ -110,7 +110,7 @@ func (lr Request) UnmarshalJSON(data []byte) error { if err := jsonUnmarshaler.Unmarshal(bytes.NewReader(data), lr.orig); err != nil { return err } - otlp.InstrumentationLibraryLogsToScope(lr.orig.ResourceLogs) + otlp.MigrateLogs(lr.orig.ResourceLogs) return nil } @@ -162,7 +162,7 @@ type rawLogsServer struct { } func (s rawLogsServer) Export(ctx context.Context, request *otlpcollectorlog.ExportLogsServiceRequest) (*otlpcollectorlog.ExportLogsServiceResponse, error) { - otlp.InstrumentationLibraryLogsToScope(request.ResourceLogs) + otlp.MigrateLogs(request.ResourceLogs) rsp, err := s.srv.Export(ctx, Request{orig: request}) return rsp.orig, err } diff --git a/pdata/plog/plogotlp/logs_test.go b/pdata/plog/plogotlp/logs_test.go index 95a3adc6747..9f85a541b51 100644 --- a/pdata/plog/plogotlp/logs_test.go +++ b/pdata/plog/plogotlp/logs_test.go @@ -31,8 +31,6 @@ import ( "google.golang.org/grpc/status" "google.golang.org/grpc/test/bufconn" - v1 "go.opentelemetry.io/collector/pdata/internal/data/protogen/logs/v1" - "go.opentelemetry.io/collector/pdata/internal/otlp" "go.opentelemetry.io/collector/pdata/plog" ) @@ -65,67 +63,6 @@ var logsRequestJSON = []byte(` ] }`) -var logsTransitionData = [][]byte{ - []byte(` - { - "resourceLogs": [ - { - "resource": {}, - "instrumentationLibraryLogs": [ - { - "instrumentationLibrary": {}, - "logRecords": [ - { - "body": { - "stringValue": "test_log_record" - }, - "traceId": "", - "spanId": "" - } - ] - } - ] - } - ] - }`), - []byte(` - { - "resourceLogs": [ - { - "resource": {}, - "instrumentationLibraryLogs": [ - { - "instrumentationLibrary": {}, - "logRecords": [ - { - "body": { - "stringValue": "test_log_record" - }, - "traceId": "", - "spanId": "" - } - ] - } - ], - "scopeLogs": [ - { - "scope": {}, - "logRecords": [ - { - "body": { - "stringValue": "test_log_record" - }, - "traceId": "", - "spanId": "" - } - ] - } - ] - } - ] - }`), -} - func TestRequestToPData(t *testing.T) { tr := NewRequest() assert.Equal(t, tr.Logs().LogRecordCount(), 0) @@ -143,18 +80,6 @@ func TestRequestJSON(t *testing.T) { assert.Equal(t, strings.Join(strings.Fields(string(logsRequestJSON)), ""), string(got)) } -func TestRequestJSONTransition(t *testing.T) { - for _, data := range logsTransitionData { - lr := NewRequest() - assert.NoError(t, lr.UnmarshalJSON(data)) - assert.Equal(t, "test_log_record", lr.Logs().ResourceLogs().At(0).ScopeLogs().At(0).LogRecords().At(0).Body().AsString()) - - got, err := lr.MarshalJSON() - assert.NoError(t, err) - assert.Equal(t, strings.Join(strings.Fields(string(logsRequestJSON)), ""), string(got)) - } -} - func TestGrpc(t *testing.T) { lis := bufconn.Listen(1024 * 1024) s := grpc.NewServer() @@ -188,83 +113,6 @@ func TestGrpc(t *testing.T) { assert.Equal(t, NewResponse(), resp) } -func TestGrpcTransition(t *testing.T) { - lis := bufconn.Listen(1024 * 1024) - s := grpc.NewServer() - RegisterServer(s, &fakeLogsServer{t: t}) - wg := sync.WaitGroup{} - wg.Add(1) - go func() { - defer wg.Done() - assert.NoError(t, s.Serve(lis)) - }() - t.Cleanup(func() { - s.Stop() - wg.Wait() - }) - - cc, err := grpc.Dial("bufnet", - grpc.WithContextDialer(func(context.Context, string) (net.Conn, error) { - return lis.Dial() - }), - grpc.WithTransportCredentials(insecure.NewCredentials()), - grpc.WithBlock()) - assert.NoError(t, err) - t.Cleanup(func() { - assert.NoError(t, cc.Close()) - }) - - logClient := NewClient(cc) - - req := generateLogsRequestWithInstrumentationLibrary() - otlp.InstrumentationLibraryLogsToScope(req.orig.ResourceLogs) - resp, err := logClient.Export(context.Background(), req) - assert.NoError(t, err) - assert.Equal(t, NewResponse(), resp) -} - -type fakeRawServer struct { - t *testing.T -} - -func (s fakeRawServer) Export(_ context.Context, req Request) (Response, error) { - assert.Equal(s.t, 1, req.Logs().LogRecordCount()) - return NewResponse(), nil -} - -func TestGrpcExport(t *testing.T) { - lis := bufconn.Listen(1024 * 1024) - s := grpc.NewServer() - RegisterServer(s, &fakeRawServer{t: t}) - wg := sync.WaitGroup{} - wg.Add(1) - go func() { - defer wg.Done() - assert.NoError(t, s.Serve(lis)) - }() - t.Cleanup(func() { - s.Stop() - wg.Wait() - }) - - cc, err := grpc.Dial("bufnet", - grpc.WithContextDialer(func(context.Context, string) (net.Conn, error) { - return lis.Dial() - }), - grpc.WithTransportCredentials(insecure.NewCredentials()), - grpc.WithBlock()) - assert.NoError(t, err) - t.Cleanup(func() { - assert.NoError(t, cc.Close()) - }) - - logClient := NewClient(cc) - - resp, err := logClient.Export(context.Background(), generateLogsRequestWithInstrumentationLibrary()) - assert.NoError(t, err) - assert.Equal(t, NewResponse(), resp) -} - func TestGrpcError(t *testing.T) { lis := bufconn.Listen(1024 * 1024) s := grpc.NewServer() @@ -316,14 +164,3 @@ func generateLogsRequest() Request { ld.ResourceLogs().AppendEmpty().ScopeLogs().AppendEmpty().LogRecords().AppendEmpty().Body().SetStringVal("test_log_record") return NewRequestFromLogs(ld) } - -func generateLogsRequestWithInstrumentationLibrary() Request { - lr := generateLogsRequest() - lr.orig.ResourceLogs[0].InstrumentationLibraryLogs = []*v1.InstrumentationLibraryLogs{ //nolint:staticcheck // SA1019 ignore this! - { - LogRecords: lr.orig.ResourceLogs[0].ScopeLogs[0].LogRecords, - }, - } - lr.orig.ResourceLogs[0].ScopeLogs = []*v1.ScopeLogs{} - return lr -} diff --git a/pdata/pmetric/json.go b/pdata/pmetric/json.go index c570eb163d5..f1a210fd028 100644 --- a/pdata/pmetric/json.go +++ b/pdata/pmetric/json.go @@ -61,6 +61,6 @@ func (d *jsonUnmarshaler) UnmarshalMetrics(buf []byte) (Metrics, error) { if err := d.delegate.Unmarshal(bytes.NewReader(buf), &md); err != nil { return Metrics{}, err } - otlp.InstrumentationLibraryMetricsToScope(md.ResourceMetrics) + otlp.MigrateMetrics(md.ResourceMetrics) return internal.MetricsFromProto(md), nil } diff --git a/pdata/pmetric/pmetricotlp/metrics.go b/pdata/pmetric/pmetricotlp/metrics.go index 7499e6e185c..01fe2bafa3e 100644 --- a/pdata/pmetric/pmetricotlp/metrics.go +++ b/pdata/pmetric/pmetricotlp/metrics.go @@ -106,7 +106,7 @@ func (mr Request) UnmarshalJSON(data []byte) error { if err := jsonUnmarshaler.Unmarshal(bytes.NewReader(data), mr.orig); err != nil { return err } - otlp.InstrumentationLibraryMetricsToScope(mr.orig.ResourceMetrics) + otlp.MigrateMetrics(mr.orig.ResourceMetrics) return nil } @@ -158,7 +158,7 @@ type rawMetricsServer struct { } func (s rawMetricsServer) Export(ctx context.Context, request *otlpcollectormetrics.ExportMetricsServiceRequest) (*otlpcollectormetrics.ExportMetricsServiceResponse, error) { - otlp.InstrumentationLibraryMetricsToScope(request.ResourceMetrics) + otlp.MigrateMetrics(request.ResourceMetrics) rsp, err := s.srv.Export(ctx, Request{orig: request}) return rsp.orig, err } diff --git a/pdata/pmetric/pmetricotlp/metrics_test.go b/pdata/pmetric/pmetricotlp/metrics_test.go index 6ca4112e8c5..efc607dac7a 100644 --- a/pdata/pmetric/pmetricotlp/metrics_test.go +++ b/pdata/pmetric/pmetricotlp/metrics_test.go @@ -31,8 +31,6 @@ import ( "google.golang.org/grpc/status" "google.golang.org/grpc/test/bufconn" - v1 "go.opentelemetry.io/collector/pdata/internal/data/protogen/metrics/v1" - "go.opentelemetry.io/collector/pdata/internal/otlp" "go.opentelemetry.io/collector/pdata/pmetric" ) @@ -61,55 +59,6 @@ var metricsRequestJSON = []byte(` ] }`) -var metricsTransitionData = [][]byte{ - []byte(` - { - "resourceMetrics": [ - { - "resource": {}, - "instrumentationLibraryMetrics": [ - { - "instrumentationLibrary": {}, - "metrics": [ - { - "name": "test_metric" - } - ] - } - ] - } - ] - }`), - []byte(` - { - "resourceMetrics": [ - { - "resource": {}, - "instrumentationLibraryMetrics": [ - { - "instrumentationLibrary": {}, - "metrics": [ - { - "name": "test_metric" - } - ] - } - ], - "scopeMetrics": [ - { - "scope": {}, - "metrics": [ - { - "name": "test_metric" - } - ] - } - ] - } - ] - }`), -} - func TestRequestToPData(t *testing.T) { tr := NewRequest() assert.Equal(t, tr.Metrics().MetricCount(), 0) @@ -127,18 +76,6 @@ func TestRequestJSON(t *testing.T) { assert.Equal(t, strings.Join(strings.Fields(string(metricsRequestJSON)), ""), string(got)) } -func TestRequestJSONTransition(t *testing.T) { - for _, data := range metricsTransitionData { - mr := NewRequest() - assert.NoError(t, mr.UnmarshalJSON(data)) - assert.Equal(t, "test_metric", mr.Metrics().ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(0).Name()) - - got, err := mr.MarshalJSON() - assert.NoError(t, err) - assert.Equal(t, strings.Join(strings.Fields(string(metricsRequestJSON)), ""), string(got)) - } -} - func TestGrpc(t *testing.T) { lis := bufconn.Listen(1024 * 1024) s := grpc.NewServer() @@ -172,83 +109,6 @@ func TestGrpc(t *testing.T) { assert.Equal(t, NewResponse(), resp) } -func TestGrpcTransition(t *testing.T) { - lis := bufconn.Listen(1024 * 1024) - s := grpc.NewServer() - RegisterServer(s, &fakeMetricsServer{t: t}) - wg := sync.WaitGroup{} - wg.Add(1) - go func() { - defer wg.Done() - assert.NoError(t, s.Serve(lis)) - }() - t.Cleanup(func() { - s.Stop() - wg.Wait() - }) - - cc, err := grpc.Dial("bufnet", - grpc.WithContextDialer(func(context.Context, string) (net.Conn, error) { - return lis.Dial() - }), - grpc.WithTransportCredentials(insecure.NewCredentials()), - grpc.WithBlock()) - assert.NoError(t, err) - t.Cleanup(func() { - assert.NoError(t, cc.Close()) - }) - - logClient := NewClient(cc) - - req := generateMetricsRequestWithInstrumentationLibrary() - otlp.InstrumentationLibraryMetricsToScope(req.orig.ResourceMetrics) - resp, err := logClient.Export(context.Background(), req) - assert.NoError(t, err) - assert.Equal(t, NewResponse(), resp) -} - -type fakeRawServer struct { - t *testing.T -} - -func (s fakeRawServer) Export(_ context.Context, req Request) (Response, error) { - assert.Equal(s.t, 1, req.Metrics().DataPointCount()) - return NewResponse(), nil -} - -func TestGrpcExport(t *testing.T) { - lis := bufconn.Listen(1024 * 1024) - s := grpc.NewServer() - RegisterServer(s, &fakeRawServer{t: t}) - wg := sync.WaitGroup{} - wg.Add(1) - go func() { - defer wg.Done() - assert.NoError(t, s.Serve(lis)) - }() - t.Cleanup(func() { - s.Stop() - wg.Wait() - }) - - cc, err := grpc.Dial("bufnet", - grpc.WithContextDialer(func(context.Context, string) (net.Conn, error) { - return lis.Dial() - }), - grpc.WithTransportCredentials(insecure.NewCredentials()), - grpc.WithBlock()) - assert.NoError(t, err) - t.Cleanup(func() { - assert.NoError(t, cc.Close()) - }) - - metricClient := NewClient(cc) - - resp, err := metricClient.Export(context.Background(), generateMetricsRequestWithInstrumentationLibrary()) - assert.NoError(t, err) - assert.Equal(t, NewResponse(), resp) -} - func TestGrpcError(t *testing.T) { lis := bufconn.Listen(1024 * 1024) s := grpc.NewServer() @@ -303,14 +163,3 @@ func generateMetricsRequest() Request { m.Gauge().DataPoints().AppendEmpty() return NewRequestFromMetrics(md) } - -func generateMetricsRequestWithInstrumentationLibrary() Request { - mr := generateMetricsRequest() - mr.orig.ResourceMetrics[0].InstrumentationLibraryMetrics = []*v1.InstrumentationLibraryMetrics{ //nolint:staticcheck // SA1019 ignore this! - { - Metrics: mr.orig.ResourceMetrics[0].ScopeMetrics[0].Metrics, - }, - } - mr.orig.ResourceMetrics[0].ScopeMetrics = []*v1.ScopeMetrics{} - return mr -} diff --git a/pdata/ptrace/json.go b/pdata/ptrace/json.go index bddee762cf3..e2592361893 100644 --- a/pdata/ptrace/json.go +++ b/pdata/ptrace/json.go @@ -100,10 +100,10 @@ func readResourceSpans(iter *jsoniter.Iterator) *otlptrace.ResourceSpans { } return true }) - case "instrumentationLibrarySpans", "instrumentation_library_spans", "scopeSpans", "scope_spans": + case "scopeSpans", "scope_spans": iter.ReadArrayCB(func(iter *jsoniter.Iterator) bool { rs.ScopeSpans = append(rs.ScopeSpans, - readInstrumentationLibrarySpans(iter)) + readScopeSpans(iter)) return true }) case "schemaUrl", "schema_url": @@ -116,12 +116,12 @@ func readResourceSpans(iter *jsoniter.Iterator) *otlptrace.ResourceSpans { return rs } -func readInstrumentationLibrarySpans(iter *jsoniter.Iterator) *otlptrace.ScopeSpans { +func readScopeSpans(iter *jsoniter.Iterator) *otlptrace.ScopeSpans { ils := &otlptrace.ScopeSpans{} iter.ReadObjectCB(func(iter *jsoniter.Iterator, f string) bool { switch f { - case "instrumentationLibrary", "instrumentation_library", "scope": + case "scope": iter.ReadObjectCB(func(iter *jsoniter.Iterator, f string) bool { switch f { case "name": @@ -129,7 +129,7 @@ func readInstrumentationLibrarySpans(iter *jsoniter.Iterator) *otlptrace.ScopeSp case "version": ils.Scope.Version = iter.ReadString() default: - iter.ReportError("readInstrumentationLibrarySpans.instrumentationLibrary", fmt.Sprintf("unknown field:%v", f)) + iter.ReportError("readScopeSpans.instrumentationLibrary", fmt.Sprintf("unknown field:%v", f)) } return true }) @@ -141,7 +141,7 @@ func readInstrumentationLibrarySpans(iter *jsoniter.Iterator) *otlptrace.ScopeSp case "schemaUrl", "schema_url": ils.SchemaUrl = iter.ReadString() default: - iter.ReportError("readInstrumentationLibrarySpans", fmt.Sprintf("unknown field:%v", f)) + iter.ReportError("readScopeSpans", fmt.Sprintf("unknown field:%v", f)) } return true }) diff --git a/pdata/ptrace/json_test.go b/pdata/ptrace/json_test.go index 37d251dd08e..9d241eeaff9 100644 --- a/pdata/ptrace/json_test.go +++ b/pdata/ptrace/json_test.go @@ -70,10 +70,10 @@ var tracesOTLPFull = func() Traces { rs.Resource().Attributes().UpsertString("host.name", "testHost") rs.Resource().Attributes().UpsertString("service.name", "testService") rs.Resource().SetDroppedAttributesCount(1) - // Add InstrumentationLibrarySpans. + // Add ScopeSpans. il := rs.ScopeSpans().AppendEmpty() - il.Scope().SetName("instrumentation name") - il.Scope().SetVersion("instrumentation version") + il.Scope().SetName("scope name") + il.Scope().SetVersion("scope version") il.SetSchemaUrl("schemaURL") // Add spans. sp := il.Spans().AppendEmpty() @@ -206,21 +206,21 @@ func TestReadResourceSpansUnknownResourceField(t *testing.T) { } } -func TestReadInstrumentationLibrarySpansUnknownField(t *testing.T) { +func TestReadScopeSpansUnknownField(t *testing.T) { jsonStr := `{"extra":""}` iter := jsoniter.ConfigFastest.BorrowIterator([]byte(jsonStr)) defer jsoniter.ConfigFastest.ReturnIterator(iter) - readInstrumentationLibrarySpans(iter) + readScopeSpans(iter) if assert.Error(t, iter.Error) { assert.Contains(t, iter.Error.Error(), "unknown field") } } -func TestReadInstrumentationLibrarySpansUnknownInstrumentationLibraryField(t *testing.T) { - jsonStr := `{"instrumentationLibrary":{"extra":""}}` +func TestReadScopeSpansUnknownScopeField(t *testing.T) { + jsonStr := `{"scope":{"extra":""}}` iter := jsoniter.ConfigFastest.BorrowIterator([]byte(jsonStr)) defer jsoniter.ConfigFastest.ReturnIterator(iter) - readInstrumentationLibrarySpans(iter) + readScopeSpans(iter) if assert.Error(t, iter.Error) { assert.Contains(t, iter.Error.Error(), "unknown field") } diff --git a/pdata/ptrace/ptraceotlp/traces.go b/pdata/ptrace/ptraceotlp/traces.go index 16884555d01..ddbe475c170 100644 --- a/pdata/ptrace/ptraceotlp/traces.go +++ b/pdata/ptrace/ptraceotlp/traces.go @@ -92,7 +92,7 @@ func (tr Request) UnmarshalProto(data []byte) error { if err := tr.orig.Unmarshal(data); err != nil { return err } - otlp.InstrumentationLibrarySpansToScope(tr.orig.ResourceSpans) + otlp.MigrateTraces(tr.orig.ResourceSpans) return nil } @@ -110,7 +110,7 @@ func (tr Request) UnmarshalJSON(data []byte) error { if err := jsonUnmarshaler.Unmarshal(bytes.NewReader(data), tr.orig); err != nil { return err } - otlp.InstrumentationLibrarySpansToScope(tr.orig.ResourceSpans) + otlp.MigrateTraces(tr.orig.ResourceSpans) return nil } @@ -163,7 +163,7 @@ type rawTracesServer struct { } func (s rawTracesServer) Export(ctx context.Context, request *otlpcollectortrace.ExportTraceServiceRequest) (*otlpcollectortrace.ExportTraceServiceResponse, error) { - otlp.InstrumentationLibrarySpansToScope(request.ResourceSpans) + otlp.MigrateTraces(request.ResourceSpans) rsp, err := s.srv.Export(ctx, Request{orig: request}) return rsp.orig, err } diff --git a/pdata/ptrace/ptraceotlp/traces_test.go b/pdata/ptrace/ptraceotlp/traces_test.go index 0b4f48b9817..13767cfb60e 100644 --- a/pdata/ptrace/ptraceotlp/traces_test.go +++ b/pdata/ptrace/ptraceotlp/traces_test.go @@ -31,8 +31,6 @@ import ( "google.golang.org/grpc/status" "google.golang.org/grpc/test/bufconn" - v1 "go.opentelemetry.io/collector/pdata/internal/data/protogen/trace/v1" - "go.opentelemetry.io/collector/pdata/internal/otlp" "go.opentelemetry.io/collector/pdata/ptrace" ) @@ -65,67 +63,6 @@ var tracesRequestJSON = []byte(` ] }`) -var tracesTransitionData = [][]byte{ - []byte(` - { - "resourceSpans": [ - { - "resource": {}, - "instrumentationLibrarySpans": [ - { - "instrumentationLibrary": {}, - "spans": [ - { - "traceId": "", - "spanId":"", - "parentSpanId":"", - "name": "test_span", - "status": {} - } - ] - } - ] - } - ] - }`), - []byte(` - { - "resourceSpans": [ - { - "resource": {}, - "instrumentationLibrarySpans": [ - { - "instrumentationLibrary": {}, - "spans": [ - { - "traceId": "", - "spanId":"", - "parentSpanId":"", - "name": "test_span", - "status": {} - } - ] - } - ], - "scopeSpans": [ - { - "scope": {}, - "spans": [ - { - "traceId": "", - "spanId":"", - "parentSpanId":"", - "name": "test_span", - "status": {} - } - ] - } - ] - } - ] - }`), -} - func TestRequestToPData(t *testing.T) { tr := NewRequest() assert.Equal(t, tr.Traces().SpanCount(), 0) @@ -143,18 +80,6 @@ func TestRequestJSON(t *testing.T) { assert.Equal(t, strings.Join(strings.Fields(string(tracesRequestJSON)), ""), string(got)) } -func TestRequestJSONTransition(t *testing.T) { - for _, data := range tracesTransitionData { - tr := NewRequest() - assert.NoError(t, tr.UnmarshalJSON(data)) - assert.Equal(t, "test_span", tr.Traces().ResourceSpans().At(0).ScopeSpans().At(0).Spans().At(0).Name()) - - got, err := tr.MarshalJSON() - assert.NoError(t, err) - assert.Equal(t, strings.Join(strings.Fields(string(tracesRequestJSON)), ""), string(got)) - } -} - func TestGrpc(t *testing.T) { lis := bufconn.Listen(1024 * 1024) s := grpc.NewServer() @@ -188,84 +113,6 @@ func TestGrpc(t *testing.T) { assert.Equal(t, NewResponse(), resp) } -func TestGrpcTransition(t *testing.T) { - lis := bufconn.Listen(1024 * 1024) - s := grpc.NewServer() - RegisterServer(s, &fakeTracesServer{t: t}) - wg := sync.WaitGroup{} - wg.Add(1) - go func() { - defer wg.Done() - assert.NoError(t, s.Serve(lis)) - }() - t.Cleanup(func() { - s.Stop() - wg.Wait() - }) - - cc, err := grpc.Dial("bufnet", - grpc.WithContextDialer(func(context.Context, string) (net.Conn, error) { - return lis.Dial() - }), - grpc.WithTransportCredentials(insecure.NewCredentials()), - grpc.WithBlock()) - assert.NoError(t, err) - t.Cleanup(func() { - assert.NoError(t, cc.Close()) - }) - - logClient := NewClient(cc) - - req := generateTracesRequestWithInstrumentationLibrary() - otlp.InstrumentationLibrarySpansToScope(req.orig.ResourceSpans) - resp, err := logClient.Export(context.Background(), req) - assert.NoError(t, err) - assert.Equal(t, NewResponse(), resp) -} - -type fakeRawServer struct { - t *testing.T -} - -func (s fakeRawServer) Export(_ context.Context, req Request) (Response, error) { - assert.Equal(s.t, 1, req.Traces().SpanCount()) - return NewResponse(), nil -} - -func TestGrpcExport(t *testing.T) { - lis := bufconn.Listen(1024 * 1024) - s := grpc.NewServer() - - RegisterServer(s, &fakeRawServer{t: t}) - wg := sync.WaitGroup{} - wg.Add(1) - go func() { - defer wg.Done() - assert.NoError(t, s.Serve(lis)) - }() - t.Cleanup(func() { - s.Stop() - wg.Wait() - }) - - cc, err := grpc.Dial("bufnet", - grpc.WithContextDialer(func(context.Context, string) (net.Conn, error) { - return lis.Dial() - }), - grpc.WithTransportCredentials(insecure.NewCredentials()), - grpc.WithBlock()) - assert.NoError(t, err) - t.Cleanup(func() { - assert.NoError(t, cc.Close()) - }) - traceClient := NewClient(cc) - - req := generateTracesRequestWithInstrumentationLibrary() - resp, err := traceClient.Export(context.Background(), req) - assert.NoError(t, err) - assert.Equal(t, NewResponse(), resp) -} - func TestGrpcError(t *testing.T) { lis := bufconn.Listen(1024 * 1024) s := grpc.NewServer() @@ -317,14 +164,3 @@ func generateTracesRequest() Request { td.ResourceSpans().AppendEmpty().ScopeSpans().AppendEmpty().Spans().AppendEmpty().SetName("test_span") return NewRequestFromTraces(td) } - -func generateTracesRequestWithInstrumentationLibrary() Request { - tr := generateTracesRequest() - tr.orig.ResourceSpans[0].InstrumentationLibrarySpans = []*v1.InstrumentationLibrarySpans{ //nolint:staticcheck // SA1019 ignore this! - { - Spans: tr.orig.ResourceSpans[0].ScopeSpans[0].Spans, - }, - } - tr.orig.ResourceSpans[0].ScopeSpans = []*v1.ScopeSpans{} - return tr -}