@@ -141,6 +141,16 @@ func TestSerializeComplexBody(t *testing.T) {
141
141
}
142
142
}
143
143
144
+ func TestEncodeWithFlags (t * testing.T ) {
145
+ in := `{"body":"Example log","traceid":"01020304000000000000000000000000","spanid":"0506070800000000","severity":"error","flags":1,"attributes":{"attr1":"1","attr2":"2"},"resources":{"host.name":"something"},"instrumentation_scope":{"name":"example-logger-name","version":"v1"}}`
146
+ log , resource , scope := exampleLog ()
147
+ log .SetFlags (plog .DefaultLogRecordFlags .WithIsSampled (true ))
148
+
149
+ out , err := Encode (log , resource , scope )
150
+ assert .NoError (t , err )
151
+ assert .Equal (t , in , out )
152
+ }
153
+
144
154
func TestEncodeLogfmtWithStringBody (t * testing.T ) {
145
155
in := `msg="hello world" traceID=01020304000000000000000000000000 spanID=0506070800000000 severity=error attribute_attr1=1 attribute_attr2=2 resource_host.name=something instrumentation_scope_name=example-logger-name instrumentation_scope_version=v1`
146
156
log , resource , scope := exampleLog ()
@@ -195,3 +205,13 @@ func TestEncodeLogfmtWithComplexAttributes(t *testing.T) {
195
205
assert .NoError (t , err )
196
206
assert .Equal (t , in , out )
197
207
}
208
+
209
+ func TestEncodeLogfmtWithFlags (t * testing.T ) {
210
+ in := `msg="hello world" traceID=01020304000000000000000000000000 spanID=0506070800000000 severity=error flags=1 attribute_attr1=1 attribute_attr2=2 resource_host.name=something instrumentation_scope_name=example-logger-name instrumentation_scope_version=v1`
211
+ log , resource , scope := exampleLog ()
212
+ log .Body ().SetStr ("msg=\" hello world\" " )
213
+ log .SetFlags (plog .DefaultLogRecordFlags .WithIsSampled (true ))
214
+ out , err := EncodeLogfmt (log , resource , scope )
215
+ assert .NoError (t , err )
216
+ assert .Equal (t , in , out )
217
+ }
0 commit comments