Skip to content

Commit

Permalink
log/logtest: Add Attributes to ScopeRecords (#5927)
Browse files Browse the repository at this point in the history
Towards #3368
  • Loading branch information
pellared authored Oct 30, 2024
1 parent 6a2f7de commit 4f94b1e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- The `go.opentelemetry.io/otel/semconv/v1.27.0` package.
The package contains semantic conventions from the `v1.27.0` version of the OpenTelemetry Semantic Conventions. (#5894)
- Add `Attributes attribute.Set` field to `Scope` in `go.opentelemetry.io/otel/sdk/instrumentation`. (#5903)
- Add `Attributes attribute.Set` field to `ScopeRecords` in `go.opentelemetry.io/otel/log/logtest`. (#5927)

### Fixed

Expand Down
10 changes: 7 additions & 3 deletions log/logtest/recorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"sync"

"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/log"
"go.opentelemetry.io/otel/log/embedded"
)
Expand Down Expand Up @@ -66,6 +67,8 @@ type ScopeRecords struct {
Version string
// SchemaURL of the telemetry emitted by the scope.
SchemaURL string
// Attributes of the telemetry emitted by the scope.
Attributes attribute.Set

// Records are the log records, and their associated context this
// instrumentation scope recorded.
Expand Down Expand Up @@ -104,9 +107,10 @@ func (r *Recorder) Logger(name string, opts ...log.LoggerOption) log.Logger {

nl := &logger{
scopeRecord: &ScopeRecords{
Name: name,
Version: cfg.InstrumentationVersion(),
SchemaURL: cfg.SchemaURL(),
Name: name,
Version: cfg.InstrumentationVersion(),
SchemaURL: cfg.SchemaURL(),
Attributes: cfg.InstrumentationAttributes(),
},
enabledFn: r.enabledFn,
}
Expand Down
9 changes: 6 additions & 3 deletions log/logtest/recorder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/stretchr/testify/assert"

"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/log"
)

Expand Down Expand Up @@ -37,13 +38,15 @@ func TestRecorderLogger(t *testing.T) {
loggerOptions: []log.LoggerOption{
log.WithInstrumentationVersion("logtest v42"),
log.WithSchemaURL("https://example.com"),
log.WithInstrumentationAttributes(attribute.String("foo", "bar")),
},

wantLogger: &logger{
scopeRecord: &ScopeRecords{
Name: "test",
Version: "logtest v42",
SchemaURL: "https://example.com",
Name: "test",
Version: "logtest v42",
SchemaURL: "https://example.com",
Attributes: attribute.NewSet(attribute.String("foo", "bar")),
},
},
},
Expand Down

0 comments on commit 4f94b1e

Please sign in to comment.