11import { trace } from '@opentelemetry/api'
2- import { expect , test , vi } from 'vitest'
2+ import { beforeEach , describe , expect , test , vi } from 'vitest'
33
44import { ATTRIBUTES_LEVEL_KEY , ATTRIBUTES_MESSAGE_TEMPLATE_KEY , ATTRIBUTES_SPAN_TYPE_KEY , ATTRIBUTES_TAGS_KEY } from './constants'
55import { info } from './index'
@@ -25,22 +25,50 @@ vi.mock('@opentelemetry/api', () => {
2525 }
2626} )
2727
28- test ( 'formats the message with the passed attributes' , ( ) => {
29- info ( 'aha {i}' , { i : 1 } )
30- const tracer = trace . getTracer ( 'logfire' )
31-
32- // eslint-disable-next-line @typescript-eslint/unbound-method
33- expect ( tracer . startSpan ) . toBeCalledWith (
34- 'aha 1' ,
35- {
36- attributes : {
37- [ ATTRIBUTES_LEVEL_KEY ] : 9 ,
38- [ ATTRIBUTES_MESSAGE_TEMPLATE_KEY ] : 'aha {i}' ,
39- [ ATTRIBUTES_SPAN_TYPE_KEY ] : 'log' ,
40- [ ATTRIBUTES_TAGS_KEY ] : [ ] ,
41- i : 1 ,
28+ describe ( 'info' , ( ) => {
29+ beforeEach ( ( ) => {
30+ vi . clearAllMocks ( )
31+ } )
32+ test ( 'formats the message with the passed attributes' , ( ) => {
33+ info ( 'aha {i}' , { i : 1 } )
34+ const tracer = trace . getTracer ( 'logfire' )
35+
36+ // eslint-disable-next-line @typescript-eslint/unbound-method
37+ expect ( tracer . startSpan ) . toBeCalledWith (
38+ 'aha 1' ,
39+ {
40+ attributes : {
41+ [ ATTRIBUTES_LEVEL_KEY ] : 9 ,
42+ [ ATTRIBUTES_MESSAGE_TEMPLATE_KEY ] : 'aha {i}' ,
43+ [ ATTRIBUTES_SPAN_TYPE_KEY ] : 'log' ,
44+ [ ATTRIBUTES_TAGS_KEY ] : [ ] ,
45+ i : 1 ,
46+ } ,
4247 } ,
43- } ,
44- undefined
45- )
48+ undefined
49+ )
50+ } )
51+
52+ test ( 'adds scrubbing details' , ( ) => {
53+ info ( 'aha {i}' , { i : 1 , password : 'hunter' } )
54+ const tracer = trace . getTracer ( 'logfire' )
55+
56+ // eslint-disable-next-line @typescript-eslint/unbound-method
57+ expect ( tracer . startSpan ) . toBeCalledWith (
58+ 'aha 1' ,
59+ {
60+ attributes : {
61+ [ ATTRIBUTES_LEVEL_KEY ] : 9 ,
62+ [ ATTRIBUTES_MESSAGE_TEMPLATE_KEY ] : 'aha {i}' ,
63+ [ ATTRIBUTES_SPAN_TYPE_KEY ] : 'log' ,
64+ [ ATTRIBUTES_TAGS_KEY ] : [ ] ,
65+ i : 1 ,
66+ 'logfire.json_schema' : '{"properties":{"logfire.scrubbed":{"type":"array"}},"type":"object"}' ,
67+ 'logfire.scrubbed' : '[{"matched_substring":"password","path":["password"]}]' ,
68+ password : "[Scrubbed due to 'password']" ,
69+ } ,
70+ } ,
71+ undefined
72+ )
73+ } )
4674} )
0 commit comments