1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-08-10 22:31:50 +02:00

sdk/log: Record.Resource to return *resource.Resource (#6864)

Fixes https://github.com/open-telemetry/opentelemetry-go/issues/6863

From https://pkg.go.dev/go.opentelemetry.io/otel/sdk/resource#Resource:

> Resource is an immutable object
> [...]
> Resources should be passed and stored as pointers
(`*resource.Resource`)

In all other places the exported API uses `*resource.Resource` and not
`resource.Resource`.
This commit is contained in:
Robert Pająk
2025-06-04 07:05:17 +02:00
committed by GitHub
parent 1636bcdd1d
commit a99f9b56ce
5 changed files with 6 additions and 8 deletions

View File

@@ -71,7 +71,7 @@ func TestRecordFactory(t *testing.T) {
assert.Equal(t, spanID, got.SpanID())
assert.Equal(t, traceFlags, got.TraceFlags())
assert.Equal(t, scope, got.InstrumentationScope())
assert.Equal(t, *r, got.Resource())
assert.Equal(t, r, got.Resource())
}
func TestRecordFactoryMultiple(t *testing.T) {

View File

@@ -387,11 +387,8 @@ func (r *Record) SetTraceFlags(flags trace.TraceFlags) {
}
// Resource returns the entity that collected the log.
func (r *Record) Resource() resource.Resource {
if r.resource == nil {
return *resource.Empty()
}
return *r.resource
func (r *Record) Resource() *resource.Resource {
return r.resource
}
// InstrumentationScope returns the scope that the Logger was created with.

View File

@@ -125,7 +125,7 @@ func TestRecordResource(t *testing.T) {
res := resource.NewSchemaless(attribute.Bool("key", true))
r.resource = res
got := r.Resource()
assert.True(t, res.Equal(&got))
assert.Equal(t, res, got)
}
func TestRecordInstrumentationScope(t *testing.T) {