mirror of
https://github.com/hanzoai/telemetry.git
synced 2026-10-30 20:01:49 +00:00
#### 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 https://github.com/open-telemetry/opentelemetry-collector/issues/10515 #### Testing Updated unit tests. #### Documentation Updated example in documentation.
48 lines
1.6 KiB
Go
48 lines
1.6 KiB
Go
// Copyright The OpenTelemetry Authors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package normal // import "go.opentelemetry.io/collector/exporter/debugexporter/internal/normal"
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"strings"
|
|
|
|
"go.opentelemetry.io/collector/pdata/plog"
|
|
)
|
|
|
|
type normalLogsMarshaler struct{}
|
|
|
|
// Ensure normalLogsMarshaller implements interface plog.Marshaler
|
|
var _ plog.Marshaler = normalLogsMarshaler{}
|
|
|
|
// NewNormalLogsMarshaler returns a plog.Marshaler for normal verbosity. It writes one line of text per log record
|
|
func NewNormalLogsMarshaler() plog.Marshaler {
|
|
return normalLogsMarshaler{}
|
|
}
|
|
|
|
func (normalLogsMarshaler) MarshalLogs(ld plog.Logs) ([]byte, error) {
|
|
var buffer bytes.Buffer
|
|
for i := 0; i < ld.ResourceLogs().Len(); i++ {
|
|
resourceLog := ld.ResourceLogs().At(i)
|
|
|
|
buffer.WriteString(fmt.Sprintf("ResourceLog #%d%s%s\n", i, writeResourceDetails(resourceLog.SchemaUrl()), writeAttributesString(resourceLog.Resource().Attributes())))
|
|
|
|
for j := 0; j < resourceLog.ScopeLogs().Len(); j++ {
|
|
scopeLog := resourceLog.ScopeLogs().At(j)
|
|
|
|
buffer.WriteString(fmt.Sprintf("ScopeLog #%d%s%s\n", i, writeScopeDetails(scopeLog.Scope().Name(), scopeLog.Scope().Version(), scopeLog.SchemaUrl()), writeAttributesString(scopeLog.Scope().Attributes())))
|
|
|
|
for k := 0; k < scopeLog.LogRecords().Len(); k++ {
|
|
logRecord := scopeLog.LogRecords().At(k)
|
|
logAttributes := writeAttributes(logRecord.Attributes())
|
|
|
|
logString := fmt.Sprintf("%s %s", logRecord.Body().AsString(), strings.Join(logAttributes, " "))
|
|
buffer.WriteString(logString)
|
|
buffer.WriteString("\n")
|
|
}
|
|
}
|
|
}
|
|
return buffer.Bytes(), nil
|
|
}
|