1414 * limitations under the License.
1515 */
1616
17- import { Attributes , AttributeValue , diag } from '@opentelemetry/api' ;
17+ import { AttributeValue , diag } from '@opentelemetry/api' ;
1818import type * as logsAPI from '@opentelemetry/api-logs' ;
1919import * as api from '@opentelemetry/api' ;
2020import {
@@ -27,14 +27,15 @@ import type { IResource } from '@opentelemetry/resources';
2727import type { ReadableLogRecord } from './export/ReadableLogRecord' ;
2828import type { LogRecordLimits } from './types' ;
2929import { Logger } from './Logger' ;
30+ import { LogAttributes } from '@opentelemetry/api-logs' ;
3031
3132export class LogRecord implements ReadableLogRecord {
3233 readonly hrTime : api . HrTime ;
3334 readonly hrTimeObserved : api . HrTime ;
3435 readonly spanContext ?: api . SpanContext ;
3536 readonly resource : IResource ;
3637 readonly instrumentationScope : InstrumentationScope ;
37- readonly attributes : Attributes = { } ;
38+ readonly attributes : logsAPI . LogAttributes = { } ;
3839 private _severityText ?: string ;
3940 private _severityNumber ?: logsAPI . SeverityNumber ;
4041 private _body ?: string ;
@@ -102,13 +103,20 @@ export class LogRecord implements ReadableLogRecord {
102103 this . setAttributes ( attributes ) ;
103104 }
104105
105- public setAttribute ( key : string , value ?: AttributeValue ) {
106+ public setAttribute ( key : string , value ?: LogAttributes | AttributeValue ) {
106107 if ( this . _isLogRecordReadonly ( ) ) {
107108 return this ;
108109 }
109110 if ( value === null ) {
110111 return this ;
111112 }
113+ if (
114+ typeof value === 'object' &&
115+ ! Array . isArray ( value ) &&
116+ Object . keys ( value ) . length > 0
117+ ) {
118+ this . attributes [ key ] = value ;
119+ }
112120 if ( key . length === 0 ) {
113121 api . diag . warn ( `Invalid attribute key: ${ key } ` ) ;
114122 return this ;
@@ -128,7 +136,7 @@ export class LogRecord implements ReadableLogRecord {
128136 return this ;
129137 }
130138
131- public setAttributes ( attributes : Attributes ) {
139+ public setAttributes ( attributes : LogAttributes ) {
132140 for ( const [ k , v ] of Object . entries ( attributes ) ) {
133141 this . setAttribute ( k , v ) ;
134142 }
0 commit comments