11import { expect , test } from '@playwright/test' ;
2- import { waitForTransaction } from '@sentry-internal/test-utils' ;
2+ import { waitForError , waitForTransaction } from '@sentry-internal/test-utils' ;
33
44test ( 'should only call the function once without any extra calls' , async ( ) => {
55 const serverTransactionPromise = waitForTransaction ( 'node-firebase' , span => {
@@ -15,6 +15,7 @@ test('should only call the function once without any extra calls', async () => {
1515 expect . objectContaining ( {
1616 trace : expect . objectContaining ( {
1717 data : {
18+ 'cloud.project_id' : 'demo-functions' ,
1819 'faas.name' : 'helloWorld' ,
1920 'faas.provider' : 'firebase' ,
2021 'faas.trigger' : 'http.request' ,
@@ -34,6 +35,35 @@ test('should only call the function once without any extra calls', async () => {
3435 ) ;
3536} ) ;
3637
38+ test ( 'should send failed transaction when the function fails' , async ( ) => {
39+ const errorEventPromise = waitForError ( 'node-firebase' , ( ) => true ) ;
40+ const serverTransactionPromise = waitForTransaction ( 'node-firebase' , span => {
41+ return ! ! span . transaction ;
42+ } ) ;
43+
44+ await fetch ( `http://localhost:5001/demo-functions/default/unhandeledError` ) ;
45+
46+ const transactionEvent = await serverTransactionPromise ;
47+ const errorEvent = await errorEventPromise ;
48+
49+ expect ( transactionEvent . transaction ) . toEqual ( 'firebase.function.http.request' ) ;
50+ expect ( transactionEvent . contexts ?. trace ?. trace_id ) . toEqual ( errorEvent . contexts ?. trace ?. trace_id ) ;
51+ expect ( errorEvent ) . toMatchObject ( {
52+ exception : {
53+ values : [
54+ {
55+ type : 'Error' ,
56+ value : 'There is an error!' ,
57+ mechanism : {
58+ type : 'auto.firebase.otel.functions' ,
59+ handled : false ,
60+ } ,
61+ } ,
62+ ] ,
63+ } ,
64+ } ) ;
65+ } ) ;
66+
3767test ( 'should create a document and trigger onDocumentCreated and another with authContext' , async ( ) => {
3868 const serverTransactionPromise = waitForTransaction ( 'node-firebase' , span => {
3969 return span . transaction === 'firebase.function.http.request' ;
@@ -62,6 +92,7 @@ test('should create a document and trigger onDocumentCreated and another with au
6292 expect ( transactionEvent . transaction ) . toEqual ( 'firebase.function.http.request' ) ;
6393 expect ( transactionEvent . contexts ?. trace ) . toEqual ( {
6494 data : {
95+ 'cloud.project_id' : 'demo-functions' ,
6596 'faas.name' : 'onCallSomething' ,
6697 'faas.provider' : 'firebase' ,
6798 'faas.trigger' : 'http.request' ,
@@ -80,6 +111,7 @@ test('should create a document and trigger onDocumentCreated and another with au
80111 expect ( transactionEvent . spans ) . toHaveLength ( 3 ) ;
81112 expect ( transactionEventOnDocumentCreate . contexts ?. trace ) . toEqual ( {
82113 data : {
114+ 'cloud.project_id' : 'demo-functions' ,
83115 'faas.name' : 'onDocumentCreate' ,
84116 'faas.provider' : 'firebase' ,
85117 'faas.trigger' : 'firestore.document.created' ,
@@ -98,6 +130,7 @@ test('should create a document and trigger onDocumentCreated and another with au
98130 expect ( transactionEventOnDocumentCreate . spans ) . toHaveLength ( 2 ) ;
99131 expect ( transactionEventOnDocumentWithAuthContextCreate . contexts ?. trace ) . toEqual ( {
100132 data : {
133+ 'cloud.project_id' : 'demo-functions' ,
101134 'faas.name' : 'onDocumentCreateWithAuthContext' ,
102135 'faas.provider' : 'firebase' ,
103136 'faas.trigger' : 'firestore.document.created' ,
0 commit comments