@@ -68,20 +68,28 @@ type ISpan = opentelemetry.proto.trace.v1.ISpan
68
68
69
69
function mapLogRecord ( logRecord : ILogRecord ) : ISpan {
70
70
// console.log(logRecord)
71
- const time = logRecord . observedTimeUnixNano || logRecord . timeUnixNano
71
+ const time = logRecord . timeUnixNano || logRecord . observedTimeUnixNano
72
72
const attributes = logRecord . attributes || [ ]
73
+ attributes . push ( { key : 'logfire.span_type' , value : { stringValue : 'log' } } )
73
74
if ( logRecord . severityNumber ) {
74
75
attributes . push ( { key : 'logfire.level_num' , value : { intValue : logRecord . severityNumber } } )
75
76
}
76
77
if ( logRecord . eventName ) {
77
78
attributes . push ( { key : 'log_event_name' , value : { stringValue : logRecord . eventName } } )
78
79
}
79
- let name : string | null = null
80
+ if ( logRecord . timeUnixNano ) {
81
+ attributes . push ( { key : 'TimeUnixNano' , value : { intValue : logRecord . timeUnixNano } } )
82
+ }
83
+ if ( logRecord . observedTimeUnixNano ) {
84
+ attributes . push ( { key : 'ObservedTimestampUnixNano' , value : { intValue : logRecord . observedTimeUnixNano } } )
85
+ }
86
+ let name : string = 'unknown log'
80
87
81
88
if ( logRecord . body ) {
82
89
if ( logRecord . body . stringValue ) {
83
90
name = logRecord . body . stringValue
84
91
} else {
92
+ name = JSON . stringify ( logRecord . body )
85
93
attributes . push ( { key : 'log_body' , value : logRecord . body } )
86
94
}
87
95
}
@@ -99,15 +107,25 @@ function mapLogRecord(logRecord: ILogRecord): ISpan {
99
107
startTimeUnixNano : time ,
100
108
endTimeUnixNano : time ,
101
109
attributes,
102
- name,
110
+ name : truncate ( name ) ,
103
111
droppedAttributesCount : logRecord . droppedAttributesCount ,
104
112
flags : logRecord . flags ,
105
113
}
106
114
}
107
115
108
116
/// generate a random traceID or spanID
109
- export function generateRand ( bytes : number ) : Uint8Array {
117
+ function generateRand ( bytes : number ) : Uint8Array {
110
118
const array = new Uint8Array ( bytes )
111
119
crypto . getRandomValues ( array )
112
120
return array
113
121
}
122
+
123
+ const MAX_LENGTH = 120
124
+
125
+ function truncate ( text : string ) : string {
126
+ if ( text . length <= MAX_LENGTH ) {
127
+ return text
128
+ } else {
129
+ return text . slice ( 0 , MAX_LENGTH ) + '…'
130
+ }
131
+ }
0 commit comments