Skip to content

Commit e6c05b8

Browse files
[exporter/debug] display resource and scope in normal verbosity (#13011)
#### Description Adds displaying of resource and scope details in `normal` verbosity. Each resource is represented with one line showing the resource's details: - schema URL - resource attributes which looks like `ResourceTraces #0 [resource-schema-url] resource_attr1=value1 attr2=value2`. Each instrumentation scope is represented by one line showing the scope's details: - scope name - scope version - scope schema URL - scope attributes which looks like `ScopeTraces #0 scope-name@scope-version [scope-schema-url] scope_attr1=value1 attr2=value2`. Before: ```console 2025-05-09T19:57:16.332+0200 info Traces {"resource": {}, "otelcol.component.id": "debug/normal", "otelcol.component.kind": "exporter", "otelcol.signal": "traces", "resource spans": 1, "spans": 2} 2025-05-09T19:57:16.332+0200 info okey-dokey-0 ab1030bd4ee554af936542b01d7b4807 1d8c93663d043aa8 net.sock.peer.addr=1.2.3.4 peer.service=telemetrygen-client lets-go ab1030bd4ee554af936542b01d7b4807 0d238e8a2f97733f net.sock.peer.addr=1.2.3.4 peer.service=telemetrygen-server {"resource": {}, "otelcol.component.id": "debug/normal", "otelcol.component.kind": "exporter", "otelcol.signal": "traces"} ``` After: ```console 2025-05-09T19:57:16.332+0200 info Traces {"resource": {}, "otelcol.component.id": "debug/normal", "otelcol.component.kind": "exporter", "otelcol.signal": "traces", "resource spans": 1, "spans": 2} 2025-05-09T19:57:16.332+0200 info ResourceTraces #0 [https://opentelemetry.io/schemas/1.25.0] service.name=telemetrygen ScopeTraces #0 telemetrygen okey-dokey-0 ab1030bd4ee554af936542b01d7b4807 1d8c93663d043aa8 net.sock.peer.addr=1.2.3.4 peer.service=telemetrygen-client lets-go ab1030bd4ee554af936542b01d7b4807 0d238e8a2f97733f net.sock.peer.addr=1.2.3.4 peer.service=telemetrygen-server {"resource": {}, "otelcol.component.id": "debug/normal", "otelcol.component.kind": "exporter", "otelcol.signal": "traces"} ``` #### Link to tracking issue Fixes #10515 #### Testing Updated unit tests. #### Documentation Updated example in documentation.
1 parent ee2c784 commit e6c05b8

File tree

11 files changed

+213
-15
lines changed

11 files changed

+213
-15
lines changed

.chloggen/add-resource-scope.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: enhancement
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
7+
component: exporter/debug
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Display resource and scope in `normal` verbosity
11+
12+
# One or more tracking issues or pull requests related to the change
13+
issues: [10515]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# Optional: The change log or logs in which this entry should be included.
21+
# e.g. '[user]' or '[user, api]'
22+
# Include 'user' if the change is relevant to end users.
23+
# Include 'api' if there is a change to a library API.
24+
# Default: '[user]'
25+
change_logs: []

exporter/debugexporter/README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,12 @@ For example, logs with multiline body will be output as multiple lines.
7373
Here's an example output:
7474

7575
```console
76-
2025-04-17T10:40:44.560+0200 info Traces {"otelcol.component.id": "debug/normal", "otelcol.component.kind": "Exporter", "otelcol.signal": "traces", "resource spans": 1, "spans": 2}
77-
2025-04-17T10:40:44.560+0200 info okey-dokey-0 fafdac970271dd2ce89de2442c0518c7 3875f436d989d0e5 net.sock.peer.addr=1.2.3.4 peer.service=telemetrygen-client
78-
lets-go fafdac970271dd2ce89de2442c0518c7 d98de4cb8e2a0ad6 net.sock.peer.addr=1.2.3.4 peer.service=telemetrygen-server
79-
{"otelcol.component.id": "debug/normal", "otelcol.component.kind": "Exporter", "otelcol.signal": "traces"}
76+
2025-05-09T19:57:16.332+0200 info Traces {"resource": {}, "otelcol.component.id": "debug/normal", "otelcol.component.kind": "exporter", "otelcol.signal": "traces", "resource spans": 1, "spans": 2}
77+
2025-05-09T19:57:16.332+0200 info ResourceTraces #0 [https://opentelemetry.io/schemas/1.25.0] service.name=telemetrygen
78+
ScopeTraces #0 telemetrygen
79+
okey-dokey-0 ab1030bd4ee554af936542b01d7b4807 1d8c93663d043aa8 net.sock.peer.addr=1.2.3.4 peer.service=telemetrygen-client
80+
lets-go ab1030bd4ee554af936542b01d7b4807 0d238e8a2f97733f net.sock.peer.addr=1.2.3.4 peer.service=telemetrygen-server
81+
{"resource": {}, "otelcol.component.id": "debug/normal", "otelcol.component.kind": "exporter", "otelcol.signal": "traces"}
8082
```
8183

8284
### Detailed verbosity

exporter/debugexporter/internal/normal/common.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package normal // import "go.opentelemetry.io/collector/exporter/debugexporter/i
55

66
import (
77
"fmt"
8+
"strings"
89

910
"go.opentelemetry.io/collector/pdata/pcommon"
1011
)
@@ -17,3 +18,38 @@ func writeAttributes(attributes pcommon.Map) (attributeStrings []string) {
1718
}
1819
return attributeStrings
1920
}
21+
22+
// writeAttributesString returns a string in the form " attrKey=attrValue attr2=value2"
23+
func writeAttributesString(attributesMap pcommon.Map) (attributesString string) {
24+
attributes := writeAttributes(attributesMap)
25+
if len(attributes) > 0 {
26+
attributesString = " " + strings.Join(attributes, " ")
27+
}
28+
return attributesString
29+
}
30+
31+
func writeResourceDetails(schemaURL string) (resourceDetails string) {
32+
if len(schemaURL) > 0 {
33+
resourceDetails = " [" + schemaURL + "]"
34+
}
35+
return resourceDetails
36+
}
37+
38+
func writeScopeDetails(name string, version string, schemaURL string) (scopeDetails string) {
39+
if len(name) > 0 {
40+
scopeDetails += name
41+
}
42+
if len(version) > 0 {
43+
scopeDetails += "@" + version
44+
}
45+
if len(schemaURL) > 0 {
46+
if len(scopeDetails) > 0 {
47+
scopeDetails += " "
48+
}
49+
scopeDetails += "[" + schemaURL + "]"
50+
}
51+
if len(scopeDetails) > 0 {
52+
scopeDetails = " " + scopeDetails
53+
}
54+
return scopeDetails
55+
}

exporter/debugexporter/internal/normal/logs.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,14 @@ func (normalLogsMarshaler) MarshalLogs(ld plog.Logs) ([]byte, error) {
2525
var buffer bytes.Buffer
2626
for i := 0; i < ld.ResourceLogs().Len(); i++ {
2727
resourceLog := ld.ResourceLogs().At(i)
28+
29+
buffer.WriteString(fmt.Sprintf("ResourceLog #%d%s%s\n", i, writeResourceDetails(resourceLog.SchemaUrl()), writeAttributesString(resourceLog.Resource().Attributes())))
30+
2831
for j := 0; j < resourceLog.ScopeLogs().Len(); j++ {
2932
scopeLog := resourceLog.ScopeLogs().At(j)
33+
34+
buffer.WriteString(fmt.Sprintf("ScopeLog #%d%s%s\n", i, writeScopeDetails(scopeLog.Scope().Name(), scopeLog.Scope().Version(), scopeLog.SchemaUrl()), writeAttributesString(scopeLog.Scope().Attributes())))
35+
3036
for k := 0; k < scopeLog.LogRecords().Len(); k++ {
3137
logRecord := scopeLog.LogRecords().At(k)
3238
logAttributes := writeAttributes(logRecord.Attributes())

exporter/debugexporter/internal/normal/logs_test.go

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,37 @@ func TestMarshalLogs(t *testing.T) {
3838
logRecord.Attributes().PutStr("key2", "value2")
3939
return logs
4040
}(),
41-
expected: `Single line log message key1=value1 key2=value2
41+
expected: `ResourceLog #0
42+
ScopeLog #0
43+
Single line log message key1=value1 key2=value2
44+
`,
45+
},
46+
{
47+
name: "one log record with resource and scope attributes",
48+
input: func() plog.Logs {
49+
logs := plog.NewLogs()
50+
resourceLogs := logs.ResourceLogs().AppendEmpty()
51+
resourceLogs.SetSchemaUrl("https://opentelemetry.io/resource-schema-url")
52+
resourceLogs.Resource().Attributes().PutStr("resourceKey1", "resourceValue1")
53+
resourceLogs.Resource().Attributes().PutBool("resourceKey2", false)
54+
scopeLogs := resourceLogs.ScopeLogs().AppendEmpty()
55+
scopeLogs.SetSchemaUrl("http://opentelemetry.io/scope-schema-url")
56+
scopeLogs.Scope().SetName("scope-name")
57+
scopeLogs.Scope().SetVersion("1.2.3")
58+
scopeLogs.Scope().Attributes().PutStr("scopeKey1", "scopeValue1")
59+
scopeLogs.Scope().Attributes().PutBool("scopeKey2", true)
60+
logRecord := scopeLogs.LogRecords().AppendEmpty()
61+
logRecord.SetTimestamp(pcommon.NewTimestampFromTime(time.Date(2024, 1, 23, 17, 54, 41, 153, time.UTC)))
62+
logRecord.SetSeverityNumber(plog.SeverityNumberInfo)
63+
logRecord.SetSeverityText("INFO")
64+
logRecord.Body().SetStr("Single line log message")
65+
logRecord.Attributes().PutStr("key1", "value1")
66+
logRecord.Attributes().PutStr("key2", "value2")
67+
return logs
68+
}(),
69+
expected: `ResourceLog #0 [https://opentelemetry.io/resource-schema-url] resourceKey1=resourceValue1 resourceKey2=false
70+
ScopeLog #0 [email protected] [http://opentelemetry.io/scope-schema-url] scopeKey1=scopeValue1 scopeKey2=true
71+
Single line log message key1=value1 key2=value2
4272
`,
4373
},
4474
{
@@ -54,7 +84,9 @@ func TestMarshalLogs(t *testing.T) {
5484
logRecord.Attributes().PutStr("key2", "value2")
5585
return logs
5686
}(),
57-
expected: `First line of the log message
87+
expected: `ResourceLog #0
88+
ScopeLog #0
89+
First line of the log message
5890
second line of the log message key1=value1 key2=value2
5991
`,
6092
},
@@ -78,7 +110,9 @@ func TestMarshalLogs(t *testing.T) {
78110
logRecord.Attributes().PutStr("mykey1", "myvalue1")
79111
return logs
80112
}(),
81-
expected: `Single line log message key1=value1 key2=value2
113+
expected: `ResourceLog #0
114+
ScopeLog #0
115+
Single line log message key1=value1 key2=value2
82116
Multi-line
83117
log message mykey2=myvalue2 mykey1=myvalue1
84118
`,
@@ -105,7 +139,9 @@ log message mykey2=myvalue2 mykey1=myvalue1
105139
logRecord.Attributes().PutStr("service", "payments")
106140
return logs
107141
}(),
108-
expected: `{"app":"CurrencyConverter","event":{"operation":"convert","result":"success"}} conversion={"destination":{"currency":"EUR"},"source":{"amount":34.22,"currency":"USD"}} service=payments
142+
expected: `ResourceLog #0
143+
ScopeLog #0
144+
{"app":"CurrencyConverter","event":{"operation":"convert","result":"success"}} conversion={"destination":{"currency":"EUR"},"source":{"amount":34.22,"currency":"USD"}} service=payments
109145
`,
110146
},
111147
}

exporter/debugexporter/internal/normal/metrics.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,14 @@ func (normalMetricsMarshaler) MarshalMetrics(md pmetric.Metrics) ([]byte, error)
2626
var buffer bytes.Buffer
2727
for i := 0; i < md.ResourceMetrics().Len(); i++ {
2828
resourceMetrics := md.ResourceMetrics().At(i)
29+
30+
buffer.WriteString(fmt.Sprintf("ResourceMetrics #%d%s%s\n", i, writeResourceDetails(resourceMetrics.SchemaUrl()), writeAttributesString(resourceMetrics.Resource().Attributes())))
31+
2932
for j := 0; j < resourceMetrics.ScopeMetrics().Len(); j++ {
3033
scopeMetrics := resourceMetrics.ScopeMetrics().At(j)
34+
35+
buffer.WriteString(fmt.Sprintf("ScopeMetrics #%d%s%s\n", i, writeScopeDetails(scopeMetrics.Scope().Name(), scopeMetrics.Scope().Version(), scopeMetrics.SchemaUrl()), writeAttributesString(scopeMetrics.Scope().Attributes())))
36+
3137
for k := 0; k < scopeMetrics.Metrics().Len(); k++ {
3238
metric := scopeMetrics.Metrics().At(k)
3339

exporter/debugexporter/internal/normal/metrics_test.go

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,36 @@ func TestMarshalMetrics(t *testing.T) {
3535
dataPoint.Attributes().PutStr("cpu", "0")
3636
return metrics
3737
}(),
38-
expected: `system.cpu.time{state=user,cpu=0} 123.456
38+
expected: `ResourceMetrics #0
39+
ScopeMetrics #0
40+
system.cpu.time{state=user,cpu=0} 123.456
41+
`,
42+
},
43+
{
44+
name: "data point with resource and scope attributes",
45+
input: func() pmetric.Metrics {
46+
metrics := pmetric.NewMetrics()
47+
resourceMetrics := metrics.ResourceMetrics().AppendEmpty()
48+
resourceMetrics.SetSchemaUrl("https://opentelemetry.io/resource-schema-url")
49+
resourceMetrics.Resource().Attributes().PutStr("resourceKey1", "resourceValue1")
50+
resourceMetrics.Resource().Attributes().PutBool("resourceKey2", false)
51+
scopeMetrics := resourceMetrics.ScopeMetrics().AppendEmpty()
52+
scopeMetrics.SetSchemaUrl("http://opentelemetry.io/scope-schema-url")
53+
scopeMetrics.Scope().SetName("scope-name")
54+
scopeMetrics.Scope().SetVersion("1.2.3")
55+
scopeMetrics.Scope().Attributes().PutStr("scopeKey1", "scopeValue1")
56+
scopeMetrics.Scope().Attributes().PutBool("scopeKey2", true)
57+
metric := scopeMetrics.Metrics().AppendEmpty()
58+
metric.SetName("system.cpu.time")
59+
dataPoint := metric.SetEmptySum().DataPoints().AppendEmpty()
60+
dataPoint.SetDoubleValue(123.456)
61+
dataPoint.Attributes().PutStr("state", "user")
62+
dataPoint.Attributes().PutStr("cpu", "0")
63+
return metrics
64+
}(),
65+
expected: `ResourceMetrics #0 [https://opentelemetry.io/resource-schema-url] resourceKey1=resourceValue1 resourceKey2=false
66+
ScopeMetrics #0 [email protected] [http://opentelemetry.io/scope-schema-url] scopeKey1=scopeValue1 scopeKey2=true
67+
system.cpu.time{state=user,cpu=0} 123.456
3968
`,
4069
},
4170
{
@@ -50,7 +79,9 @@ func TestMarshalMetrics(t *testing.T) {
5079
dataPoint.Attributes().PutStr("cpu", "8")
5180
return metrics
5281
}(),
53-
expected: `system.cpu.utilization{state=free,cpu=8} 78.901234567
82+
expected: `ResourceMetrics #0
83+
ScopeMetrics #0
84+
system.cpu.utilization{state=free,cpu=8} 78.901234567
5485
`,
5586
},
5687
{
@@ -70,7 +101,9 @@ func TestMarshalMetrics(t *testing.T) {
70101
dataPoint.SetMax(8.13)
71102
return metrics
72103
}(),
73-
expected: `http.server.request.duration{http.response.status_code=200,http.request.method=GET} count=1340 sum=99.573 min=0.017 max=8.13 le0.125=1324 le0.5=13 le1=0 le3=2 1
104+
expected: `ResourceMetrics #0
105+
ScopeMetrics #0
106+
http.server.request.duration{http.response.status_code=200,http.request.method=GET} count=1340 sum=99.573 min=0.017 max=8.13 le0.125=1324 le0.5=13 le1=0 le3=2 1
74107
`,
75108
},
76109
{
@@ -88,7 +121,9 @@ func TestMarshalMetrics(t *testing.T) {
88121
dataPoint.SetMax(8.13)
89122
return metrics
90123
}(),
91-
expected: `http.server.request.duration{http.response.status_code=200,http.request.method=GET} count=1340 sum=99.573 min=0.017 max=8.13
124+
expected: `ResourceMetrics #0
125+
ScopeMetrics #0
126+
http.server.request.duration{http.response.status_code=200,http.request.method=GET} count=1340 sum=99.573 min=0.017 max=8.13
92127
`,
93128
},
94129
{
@@ -107,7 +142,9 @@ func TestMarshalMetrics(t *testing.T) {
107142
quantile.SetValue(15)
108143
return metrics
109144
}(),
110-
expected: `summary{http.response.status_code=200,http.request.method=GET} count=1340 sum=99.573000 q0.01=15
145+
expected: `ResourceMetrics #0
146+
ScopeMetrics #0
147+
summary{http.response.status_code=200,http.request.method=GET} count=1340 sum=99.573000 q0.01=15
111148
`,
112149
},
113150
}

exporter/debugexporter/internal/normal/profiles.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,14 @@ func (normalProfilesMarshaler) MarshalProfiles(pd pprofile.Profiles) ([]byte, er
2626
var buffer bytes.Buffer
2727
for i := 0; i < pd.ResourceProfiles().Len(); i++ {
2828
resourceProfiles := pd.ResourceProfiles().At(i)
29+
30+
buffer.WriteString(fmt.Sprintf("ResourceProfiles #%d%s%s\n", i, writeResourceDetails(resourceProfiles.SchemaUrl()), writeAttributesString(resourceProfiles.Resource().Attributes())))
31+
2932
for j := 0; j < resourceProfiles.ScopeProfiles().Len(); j++ {
3033
scopeProfiles := resourceProfiles.ScopeProfiles().At(j)
34+
35+
buffer.WriteString(fmt.Sprintf("ScopeProfiles #%d%s%s\n", i, writeScopeDetails(scopeProfiles.Scope().Name(), scopeProfiles.Scope().Version(), scopeProfiles.SchemaUrl()), writeAttributesString(scopeProfiles.Scope().Attributes())))
36+
3137
for k := 0; k < scopeProfiles.Profiles().Len(); k++ {
3238
profile := scopeProfiles.Profiles().At(k)
3339

exporter/debugexporter/internal/normal/profiles_test.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ func TestMarshalProfiles(t *testing.T) {
2828
input: func() pprofile.Profiles {
2929
profiles := pprofile.NewProfiles()
3030
profile := profiles.ResourceProfiles().AppendEmpty().ScopeProfiles().AppendEmpty().Profiles().AppendEmpty()
31+
profiles.ResourceProfiles().At(0).SetSchemaUrl("https://example.com/resource")
32+
profiles.ResourceProfiles().At(0).Resource().Attributes().PutStr("resourceKey", "resourceValue")
33+
profiles.ResourceProfiles().At(0).ScopeProfiles().At(0).SetSchemaUrl("https://example.com/scope")
34+
profiles.ResourceProfiles().At(0).ScopeProfiles().At(0).Scope().SetName("scope-name")
35+
profiles.ResourceProfiles().At(0).ScopeProfiles().At(0).Scope().SetVersion("1.2.3")
36+
profiles.ResourceProfiles().At(0).ScopeProfiles().At(0).Scope().Attributes().PutStr("scopeKey", "scopeValue")
3137
profile.SetProfileID([16]byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10})
3238
profile.Sample().AppendEmpty()
3339
profile.Sample().AppendEmpty()
@@ -37,7 +43,9 @@ func TestMarshalProfiles(t *testing.T) {
3743
a.Value().SetStr("value1")
3844
return profiles
3945
}(),
40-
expected: `0102030405060708090a0b0c0d0e0f10 samples=2 key1=value1
46+
expected: `ResourceProfiles #0 [https://example.com/resource] resourceKey=resourceValue
47+
ScopeProfiles #0 [email protected] [https://example.com/scope] scopeKey=scopeValue
48+
0102030405060708090a0b0c0d0e0f10 samples=2 key1=value1
4149
`,
4250
},
4351
}

exporter/debugexporter/internal/normal/traces.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package normal // import "go.opentelemetry.io/collector/exporter/debugexporter/i
55

66
import (
77
"bytes"
8+
"fmt"
89
"strings"
910

1011
"go.opentelemetry.io/collector/pdata/ptrace"
@@ -24,8 +25,14 @@ func (normalTracesMarshaler) MarshalTraces(md ptrace.Traces) ([]byte, error) {
2425
var buffer bytes.Buffer
2526
for i := 0; i < md.ResourceSpans().Len(); i++ {
2627
resourceTraces := md.ResourceSpans().At(i)
28+
29+
buffer.WriteString(fmt.Sprintf("ResourceTraces #%d%s%s\n", i, writeResourceDetails(resourceTraces.SchemaUrl()), writeAttributesString(resourceTraces.Resource().Attributes())))
30+
2731
for j := 0; j < resourceTraces.ScopeSpans().Len(); j++ {
2832
scopeTraces := resourceTraces.ScopeSpans().At(j)
33+
34+
buffer.WriteString(fmt.Sprintf("ScopeTraces #%d%s%s\n", i, writeScopeDetails(scopeTraces.Scope().Name(), scopeTraces.Scope().Version(), scopeTraces.SchemaUrl()), writeAttributesString(scopeTraces.Scope().Attributes())))
35+
2936
for k := 0; k < scopeTraces.Spans().Len(); k++ {
3037
span := scopeTraces.Spans().At(k)
3138

exporter/debugexporter/internal/normal/traces_test.go

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,33 @@ func TestMarshalTraces(t *testing.T) {
2323
input: ptrace.NewTraces(),
2424
expected: "",
2525
},
26+
{
27+
name: "one span with resource and scope attributes",
28+
input: func() ptrace.Traces {
29+
traces := ptrace.NewTraces()
30+
resourceSpans := traces.ResourceSpans().AppendEmpty()
31+
resourceSpans.SetSchemaUrl("https://opentelemetry.io/resource-schema-url")
32+
resourceSpans.Resource().Attributes().PutStr("resourceKey1", "resourceValue1")
33+
resourceSpans.Resource().Attributes().PutBool("resourceKey2", false)
34+
scopeSpans := resourceSpans.ScopeSpans().AppendEmpty()
35+
scopeSpans.SetSchemaUrl("http://opentelemetry.io/scope-schema-url")
36+
scopeSpans.Scope().SetName("scope-name")
37+
scopeSpans.Scope().SetVersion("1.2.3")
38+
scopeSpans.Scope().Attributes().PutStr("scopeKey1", "scopeValue1")
39+
scopeSpans.Scope().Attributes().PutBool("scopeKey2", true)
40+
span := scopeSpans.Spans().AppendEmpty()
41+
span.SetName("span-name")
42+
span.SetTraceID([16]byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10})
43+
span.SetSpanID([8]byte{0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18})
44+
span.Attributes().PutStr("key1", "value1")
45+
span.Attributes().PutStr("key2", "value2")
46+
return traces
47+
}(),
48+
expected: `ResourceTraces #0 [https://opentelemetry.io/resource-schema-url] resourceKey1=resourceValue1 resourceKey2=false
49+
ScopeTraces #0 [email protected] [http://opentelemetry.io/scope-schema-url] scopeKey1=scopeValue1 scopeKey2=true
50+
span-name 0102030405060708090a0b0c0d0e0f10 1112131415161718 key1=value1 key2=value2
51+
`,
52+
},
2653
{
2754
name: "one span",
2855
input: func() ptrace.Traces {
@@ -35,7 +62,9 @@ func TestMarshalTraces(t *testing.T) {
3562
span.Attributes().PutStr("key2", "value2")
3663
return traces
3764
}(),
38-
expected: `span-name 0102030405060708090a0b0c0d0e0f10 1112131415161718 key1=value1 key2=value2
65+
expected: `ResourceTraces #0
66+
ScopeTraces #0
67+
span-name 0102030405060708090a0b0c0d0e0f10 1112131415161718 key1=value1 key2=value2
3968
`,
4069
},
4170
}

0 commit comments

Comments
 (0)