You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-07-15 01:04:25 +02:00
The stdoutlog exporter prints DroppedAttributes
field instead of Limit
s fields (#5272)
* Add tests for resource, scope, dropped attributes * Update CHANGELOG * Apply suggestions from code review --------- Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
This commit is contained in:
@ -21,6 +21,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|||||||
- The `ForceFlush` and `Shutdown` methods of the exporter returned by `New` in `go.opentelemetry.io/otel/exporters/stdout/stdoutmetric` ignore the context cancellation and always return `nil`. (#5189)
|
- The `ForceFlush` and `Shutdown` methods of the exporter returned by `New` in `go.opentelemetry.io/otel/exporters/stdout/stdoutmetric` ignore the context cancellation and always return `nil`. (#5189)
|
||||||
- Apply the value length limits to `Record` attributes in `go.opentelemetry.io/otel/sdk/log`. (#5230)
|
- Apply the value length limits to `Record` attributes in `go.opentelemetry.io/otel/sdk/log`. (#5230)
|
||||||
- De-duplicate map attributes added to a `Record` in `go.opentelemetry.io/otel/sdk/log`. (#5230)
|
- De-duplicate map attributes added to a `Record` in `go.opentelemetry.io/otel/sdk/log`. (#5230)
|
||||||
|
- The `go.opentelemetry.io/otel/exporters/stdout/stdoutlog` exporter won't print `AttributeValueLengthLimit` and `AttributeCountLimit` fields now, instead it prints the `DroppedAttributes` field. (#5272)
|
||||||
|
|
||||||
## [1.26.0/0.48.0/0.2.0-alpha] 2024-04-24
|
## [1.26.0/0.48.0/0.2.0-alpha] 2024-04-24
|
||||||
|
|
||||||
|
@ -11,6 +11,11 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"go.opentelemetry.io/otel/attribute"
|
||||||
|
"go.opentelemetry.io/otel/sdk/instrumentation"
|
||||||
|
"go.opentelemetry.io/otel/sdk/log/logtest"
|
||||||
|
"go.opentelemetry.io/otel/sdk/resource"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
@ -178,7 +183,7 @@ func getJSON(now *time.Time) string {
|
|||||||
timestamps = "\"Timestamp\":" + string(serializedNow) + ",\"ObservedTimestamp\":" + string(serializedNow) + ","
|
timestamps = "\"Timestamp\":" + string(serializedNow) + ",\"ObservedTimestamp\":" + string(serializedNow) + ","
|
||||||
}
|
}
|
||||||
|
|
||||||
return "{" + timestamps + "\"Severity\":9,\"SeverityText\":\"INFO\",\"Body\":{},\"Attributes\":[{\"Key\":\"key\",\"Value\":{}},{\"Key\":\"key2\",\"Value\":{}},{\"Key\":\"key3\",\"Value\":{}},{\"Key\":\"key4\",\"Value\":{}},{\"Key\":\"key5\",\"Value\":{}},{\"Key\":\"bool\",\"Value\":{}}],\"TraceID\":\"0102030405060708090a0b0c0d0e0f10\",\"SpanID\":\"0102030405060708\",\"TraceFlags\":\"01\",\"Resource\":null,\"Scope\":{\"Name\":\"\",\"Version\":\"\",\"SchemaURL\":\"\"},\"AttributeValueLengthLimit\":0,\"AttributeCountLimit\":0}\n"
|
return "{" + timestamps + "\"Severity\":9,\"SeverityText\":\"INFO\",\"Body\":{},\"Attributes\":[{\"Key\":\"key\",\"Value\":{}},{\"Key\":\"key2\",\"Value\":{}},{\"Key\":\"key3\",\"Value\":{}},{\"Key\":\"key4\",\"Value\":{}},{\"Key\":\"key5\",\"Value\":{}},{\"Key\":\"bool\",\"Value\":{}}],\"TraceID\":\"0102030405060708090a0b0c0d0e0f10\",\"SpanID\":\"0102030405060708\",\"TraceFlags\":\"01\",\"Resource\":[{\"Key\":\"foo\",\"Value\":{\"Type\":\"STRING\",\"Value\":\"bar\"}}],\"Scope\":{\"Name\":\"name\",\"Version\":\"version\",\"SchemaURL\":\"https://example.com/custom-schema\"},\"DroppedAttributes\":10}\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
func getJSONs(now *time.Time) string {
|
func getJSONs(now *time.Time) string {
|
||||||
@ -225,14 +230,21 @@ func getPrettyJSON(now *time.Time) string {
|
|||||||
"TraceID": "0102030405060708090a0b0c0d0e0f10",
|
"TraceID": "0102030405060708090a0b0c0d0e0f10",
|
||||||
"SpanID": "0102030405060708",
|
"SpanID": "0102030405060708",
|
||||||
"TraceFlags": "01",
|
"TraceFlags": "01",
|
||||||
"Resource": null,
|
"Resource": [
|
||||||
|
{
|
||||||
|
"Key": "foo",
|
||||||
|
"Value": {
|
||||||
|
"Type": "STRING",
|
||||||
|
"Value": "bar"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
"Scope": {
|
"Scope": {
|
||||||
"Name": "",
|
"Name": "name",
|
||||||
"Version": "",
|
"Version": "version",
|
||||||
"SchemaURL": ""
|
"SchemaURL": "https://example.com/custom-schema"
|
||||||
},
|
},
|
||||||
"AttributeValueLengthLimit": 0,
|
"DroppedAttributes": 10
|
||||||
"AttributeCountLimit": 0
|
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
}
|
}
|
||||||
@ -259,27 +271,34 @@ func getRecord(now time.Time) sdklog.Record {
|
|||||||
traceID, _ := trace.TraceIDFromHex("0102030405060708090a0b0c0d0e0f10")
|
traceID, _ := trace.TraceIDFromHex("0102030405060708090a0b0c0d0e0f10")
|
||||||
spanID, _ := trace.SpanIDFromHex("0102030405060708")
|
spanID, _ := trace.SpanIDFromHex("0102030405060708")
|
||||||
|
|
||||||
// Setup records
|
rf := logtest.RecordFactory{
|
||||||
record := sdklog.Record{}
|
Timestamp: now,
|
||||||
record.SetTimestamp(now)
|
ObservedTimestamp: now,
|
||||||
record.SetObservedTimestamp(now)
|
Severity: log.SeverityInfo1,
|
||||||
record.SetSeverity(log.SeverityInfo1)
|
SeverityText: "INFO",
|
||||||
record.SetSeverityText("INFO")
|
Body: log.StringValue("test"),
|
||||||
record.SetBody(log.StringValue("test"))
|
Attributes: []log.KeyValue{
|
||||||
record.SetAttributes([]log.KeyValue{
|
// More than 5 attributes to test back slice
|
||||||
// More than 5 attributes to test back slice
|
log.String("key", "value"),
|
||||||
log.String("key", "value"),
|
log.String("key2", "value"),
|
||||||
log.String("key2", "value"),
|
log.String("key3", "value"),
|
||||||
log.String("key3", "value"),
|
log.String("key4", "value"),
|
||||||
log.String("key4", "value"),
|
log.String("key5", "value"),
|
||||||
log.String("key5", "value"),
|
log.Bool("bool", true),
|
||||||
log.Bool("bool", true),
|
},
|
||||||
}...)
|
TraceID: traceID,
|
||||||
record.SetTraceID(traceID)
|
SpanID: spanID,
|
||||||
record.SetSpanID(spanID)
|
TraceFlags: trace.FlagsSampled,
|
||||||
record.SetTraceFlags(trace.FlagsSampled)
|
|
||||||
|
|
||||||
return record
|
Resource: resource.NewWithAttributes(
|
||||||
|
"https://example.com/custom-resource-schema",
|
||||||
|
attribute.String("foo", "bar"),
|
||||||
|
),
|
||||||
|
InstrumentationScope: instrumentation.Scope{Name: "name", Version: "version", SchemaURL: "https://example.com/custom-schema"},
|
||||||
|
DroppedAttributes: 10,
|
||||||
|
}
|
||||||
|
|
||||||
|
return rf.NewRecord()
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestExporterConcurrentSafe(t *testing.T) {
|
func TestExporterConcurrentSafe(t *testing.T) {
|
||||||
|
@ -4,6 +4,7 @@ go 1.21
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/stretchr/testify v1.9.0
|
github.com/stretchr/testify v1.9.0
|
||||||
|
go.opentelemetry.io/otel v1.26.0
|
||||||
go.opentelemetry.io/otel/log v0.2.0-alpha
|
go.opentelemetry.io/otel/log v0.2.0-alpha
|
||||||
go.opentelemetry.io/otel/sdk v1.26.0
|
go.opentelemetry.io/otel/sdk v1.26.0
|
||||||
go.opentelemetry.io/otel/sdk/log v0.2.0-alpha
|
go.opentelemetry.io/otel/sdk/log v0.2.0-alpha
|
||||||
@ -15,7 +16,6 @@ require (
|
|||||||
github.com/go-logr/logr v1.4.1 // indirect
|
github.com/go-logr/logr v1.4.1 // indirect
|
||||||
github.com/go-logr/stdr v1.2.2 // indirect
|
github.com/go-logr/stdr v1.2.2 // indirect
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
go.opentelemetry.io/otel v1.26.0 // indirect
|
|
||||||
go.opentelemetry.io/otel/metric v1.26.0 // indirect
|
go.opentelemetry.io/otel/metric v1.26.0 // indirect
|
||||||
golang.org/x/sys v0.19.0 // indirect
|
golang.org/x/sys v0.19.0 // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
|
@ -15,19 +15,18 @@ import (
|
|||||||
|
|
||||||
// recordJSON is a JSON-serializable representation of a Record.
|
// recordJSON is a JSON-serializable representation of a Record.
|
||||||
type recordJSON struct {
|
type recordJSON struct {
|
||||||
Timestamp *time.Time `json:",omitempty"`
|
Timestamp *time.Time `json:",omitempty"`
|
||||||
ObservedTimestamp *time.Time `json:",omitempty"`
|
ObservedTimestamp *time.Time `json:",omitempty"`
|
||||||
Severity log.Severity
|
Severity log.Severity
|
||||||
SeverityText string
|
SeverityText string
|
||||||
Body log.Value
|
Body log.Value
|
||||||
Attributes []log.KeyValue
|
Attributes []log.KeyValue
|
||||||
TraceID trace.TraceID
|
TraceID trace.TraceID
|
||||||
SpanID trace.SpanID
|
SpanID trace.SpanID
|
||||||
TraceFlags trace.TraceFlags
|
TraceFlags trace.TraceFlags
|
||||||
Resource *resource.Resource
|
Resource *resource.Resource
|
||||||
Scope instrumentation.Scope
|
Scope instrumentation.Scope
|
||||||
AttributeValueLengthLimit int
|
DroppedAttributes int
|
||||||
AttributeCountLimit int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Exporter) newRecordJSON(r sdklog.Record) recordJSON {
|
func (e *Exporter) newRecordJSON(r sdklog.Record) recordJSON {
|
||||||
@ -45,6 +44,8 @@ func (e *Exporter) newRecordJSON(r sdklog.Record) recordJSON {
|
|||||||
|
|
||||||
Resource: &res,
|
Resource: &res,
|
||||||
Scope: r.InstrumentationScope(),
|
Scope: r.InstrumentationScope(),
|
||||||
|
|
||||||
|
DroppedAttributes: r.DroppedAttributes(),
|
||||||
}
|
}
|
||||||
|
|
||||||
r.WalkAttributes(func(kv log.KeyValue) bool {
|
r.WalkAttributes(func(kv log.KeyValue) bool {
|
||||||
|
Reference in New Issue
Block a user