Skip to content

Commit 4f94b1e

Browse files
authored
log/logtest: Add Attributes to ScopeRecords (#5927)
Towards #3368
1 parent 6a2f7de commit 4f94b1e

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
1818
- The `go.opentelemetry.io/otel/semconv/v1.27.0` package.
1919
The package contains semantic conventions from the `v1.27.0` version of the OpenTelemetry Semantic Conventions. (#5894)
2020
- Add `Attributes attribute.Set` field to `Scope` in `go.opentelemetry.io/otel/sdk/instrumentation`. (#5903)
21+
- Add `Attributes attribute.Set` field to `ScopeRecords` in `go.opentelemetry.io/otel/log/logtest`. (#5927)
2122

2223
### Fixed
2324

log/logtest/recorder.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"context"
88
"sync"
99

10+
"go.opentelemetry.io/otel/attribute"
1011
"go.opentelemetry.io/otel/log"
1112
"go.opentelemetry.io/otel/log/embedded"
1213
)
@@ -66,6 +67,8 @@ type ScopeRecords struct {
6667
Version string
6768
// SchemaURL of the telemetry emitted by the scope.
6869
SchemaURL string
70+
// Attributes of the telemetry emitted by the scope.
71+
Attributes attribute.Set
6972

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

105108
nl := &logger{
106109
scopeRecord: &ScopeRecords{
107-
Name: name,
108-
Version: cfg.InstrumentationVersion(),
109-
SchemaURL: cfg.SchemaURL(),
110+
Name: name,
111+
Version: cfg.InstrumentationVersion(),
112+
SchemaURL: cfg.SchemaURL(),
113+
Attributes: cfg.InstrumentationAttributes(),
110114
},
111115
enabledFn: r.enabledFn,
112116
}

log/logtest/recorder_test.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
"github.com/stretchr/testify/assert"
1212

13+
"go.opentelemetry.io/otel/attribute"
1314
"go.opentelemetry.io/otel/log"
1415
)
1516

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

4244
wantLogger: &logger{
4345
scopeRecord: &ScopeRecords{
44-
Name: "test",
45-
Version: "logtest v42",
46-
SchemaURL: "https://example.com",
46+
Name: "test",
47+
Version: "logtest v42",
48+
SchemaURL: "https://example.com",
49+
Attributes: attribute.NewSet(attribute.String("foo", "bar")),
4750
},
4851
},
4952
},

0 commit comments

Comments
 (0)