@@ -41,7 +41,8 @@ import {
4141 SpanProcessor ,
4242 TimedEvent ,
4343} from '@opentelemetry/sdk-trace-node' ;
44- import { setLogFunction , Firestore } from '../src' ;
44+ import { setLogFunction , Firestore , CollectionReference } from '../src' ;
45+ import { autoId } from '../src/util' ;
4546import { verifyInstance } from '../test/util/helpers' ;
4647import {
4748 ATTRIBUTE_GCP_RESOURCE_NAME ,
@@ -159,6 +160,7 @@ class SpanData {
159160
160161describe . skipEnterprise ( 'Tracing Tests' , ( ) => {
161162 let firestore : Firestore ;
163+ let randomCol : CollectionReference ;
162164 let tracerProvider : NodeTracerProvider ;
163165 let inMemorySpanExporter : InMemorySpanExporter ;
164166 let consoleSpanExporter : ConsoleSpanExporter ;
@@ -299,6 +301,7 @@ describe.skipEnterprise('Tracing Tests', () => {
299301 }
300302
301303 firestore = new Firestore ( settings ) ;
304+ randomCol = firestore . collection ( 'node_tracing_' + autoId ( ) ) ;
302305 }
303306
304307 function getSettingsAttributes ( ) : Attributes {
@@ -767,9 +770,7 @@ describe.skipEnterprise('Tracing Tests', () => {
767770
768771 function runTestCases ( ) {
769772 it ( 'document reference get()' , async ( ) => {
770- await runFirestoreOperationInRootSpan ( ( ) =>
771- firestore . collection ( 'foo' ) . doc ( 'bar' ) . get ( ) ,
772- ) ;
773+ await runFirestoreOperationInRootSpan ( ( ) => randomCol . doc ( 'bar' ) . get ( ) ) ;
773774 await waitForCompletedSpans ( 3 ) ;
774775 expectSpanHierarchy (
775776 SPAN_NAME_TEST_ROOT ,
@@ -788,9 +789,7 @@ describe.skipEnterprise('Tracing Tests', () => {
788789 } ) ;
789790
790791 it ( 'document reference create()' , async ( ) => {
791- await runFirestoreOperationInRootSpan ( ( ) =>
792- firestore . collection ( 'foo' ) . doc ( ) . create ( { } ) ,
793- ) ;
792+ await runFirestoreOperationInRootSpan ( ( ) => randomCol . doc ( ) . create ( { } ) ) ;
794793 await waitForCompletedSpans ( 3 ) ;
795794 expectSpanHierarchy (
796795 SPAN_NAME_TEST_ROOT ,
@@ -805,7 +804,7 @@ describe.skipEnterprise('Tracing Tests', () => {
805804
806805 it ( 'document reference delete()' , async ( ) => {
807806 await runFirestoreOperationInRootSpan ( ( ) =>
808- firestore . collection ( 'foo' ) . doc ( 'bar' ) . delete ( ) ,
807+ randomCol . doc ( 'bar' ) . delete ( ) ,
809808 ) ;
810809 await waitForCompletedSpans ( 3 ) ;
811810 expectSpanHierarchy (
@@ -821,7 +820,7 @@ describe.skipEnterprise('Tracing Tests', () => {
821820
822821 it ( 'document reference set()' , async ( ) => {
823822 await runFirestoreOperationInRootSpan ( ( ) =>
824- firestore . collection ( 'foo' ) . doc ( 'bar' ) . set ( { foo : 'bar' } ) ,
823+ randomCol . doc ( 'bar' ) . set ( { foo : 'bar' } ) ,
825824 ) ;
826825 await waitForCompletedSpans ( 3 ) ;
827826 expectSpanHierarchy (
@@ -838,10 +837,10 @@ describe.skipEnterprise('Tracing Tests', () => {
838837 it ( 'document reference update()' , async ( ) => {
839838 // Make sure the document exists before updating it.
840839 // Perform the `set` operation outside of the root span.
841- await firestore . collection ( 'foo' ) . doc ( 'bar' ) . set ( { foo : 'bar' } ) ;
840+ await randomCol . doc ( 'bar' ) . set ( { foo : 'bar' } ) ;
842841
843842 await runFirestoreOperationInRootSpan ( ( ) =>
844- firestore . collection ( 'foo' ) . doc ( 'bar' ) . update ( 'foo' , 'bar2' ) ,
843+ randomCol . doc ( 'bar' ) . update ( 'foo' , 'bar2' ) ,
845844 ) ;
846845 await waitForCompletedSpans ( 3 ) ;
847846 expectSpanHierarchy (
@@ -857,7 +856,7 @@ describe.skipEnterprise('Tracing Tests', () => {
857856
858857 it ( 'document reference list collections' , async ( ) => {
859858 await runFirestoreOperationInRootSpan ( ( ) =>
860- firestore . collection ( 'foo' ) . doc ( 'bar' ) . listCollections ( ) ,
859+ randomCol . doc ( 'bar' ) . listCollections ( ) ,
861860 ) ;
862861 await waitForCompletedSpans ( 2 ) ;
863862 expectSpanHierarchy (
@@ -871,9 +870,7 @@ describe.skipEnterprise('Tracing Tests', () => {
871870 } ) ;
872871
873872 it ( 'aggregate query get()' , async ( ) => {
874- await runFirestoreOperationInRootSpan ( ( ) =>
875- firestore . collection ( 'foo' ) . count ( ) . get ( ) ,
876- ) ;
873+ await runFirestoreOperationInRootSpan ( ( ) => randomCol . count ( ) . get ( ) ) ;
877874 await waitForCompletedSpans ( 2 ) ;
878875 expectSpanHierarchy ( SPAN_NAME_TEST_ROOT , SPAN_NAME_AGGREGATION_QUERY_GET ) ;
879876 expectSpanHasEvents ( SPAN_NAME_AGGREGATION_QUERY_GET , [
@@ -884,9 +881,7 @@ describe.skipEnterprise('Tracing Tests', () => {
884881 } ) ;
885882
886883 it ( 'collection reference add()' , async ( ) => {
887- await runFirestoreOperationInRootSpan ( ( ) =>
888- firestore . collection ( 'foo' ) . add ( { foo : 'bar' } ) ,
889- ) ;
884+ await runFirestoreOperationInRootSpan ( ( ) => randomCol . add ( { foo : 'bar' } ) ) ;
890885 await waitForCompletedSpans ( 4 ) ;
891886 expectSpanHierarchy (
892887 SPAN_NAME_TEST_ROOT ,
@@ -902,9 +897,7 @@ describe.skipEnterprise('Tracing Tests', () => {
902897
903898 // Enterprise: field mask is not supported
904899 it . skipEnterprise ( 'collection reference list documents' , async ( ) => {
905- await runFirestoreOperationInRootSpan ( ( ) =>
906- firestore . collection ( 'foo' ) . listDocuments ( ) ,
907- ) ;
900+ await runFirestoreOperationInRootSpan ( ( ) => randomCol . listDocuments ( ) ) ;
908901 await waitForCompletedSpans ( 2 ) ;
909902 expectSpanHierarchy (
910903 SPAN_NAME_TEST_ROOT ,
@@ -918,7 +911,7 @@ describe.skipEnterprise('Tracing Tests', () => {
918911
919912 it ( 'query get()' , async ( ) => {
920913 await runFirestoreOperationInRootSpan ( ( ) =>
921- firestore . collection ( 'foo' ) . where ( 'foo' , '==' , 'bar' ) . limit ( 1 ) . get ( ) ,
914+ randomCol . where ( 'foo' , '==' , 'bar' ) . limit ( 1 ) . get ( ) ,
922915 ) ;
923916 await waitForCompletedSpans ( 2 ) ;
924917 expectSpanHierarchy ( SPAN_NAME_TEST_ROOT , SPAN_NAME_QUERY_GET ) ;
@@ -935,8 +928,8 @@ describe.skipEnterprise('Tracing Tests', () => {
935928 } ) ;
936929
937930 it ( 'firestore getAll()' , async ( ) => {
938- const docRef1 = firestore . collection ( 'foo' ) . doc ( '1' ) ;
939- const docRef2 = firestore . collection ( 'foo' ) . doc ( '2' ) ;
931+ const docRef1 = randomCol . doc ( '1' ) ;
932+ const docRef2 = randomCol . doc ( '2' ) ;
940933 await runFirestoreOperationInRootSpan ( ( ) =>
941934 firestore . getAll ( docRef1 , docRef2 ) ,
942935 ) ;
@@ -954,16 +947,18 @@ describe.skipEnterprise('Tracing Tests', () => {
954947 } ) ;
955948
956949 it ( 'transaction' , async ( ) => {
957- const docRef1 = firestore . collection ( 'foo' ) . doc ( 'bar' ) ;
958- const docRef2 = firestore . collection ( 'foo' ) . doc ( 'bar' ) ;
950+ const docRef1 = randomCol . doc ( 'bar' ) ;
951+ const docRef2 = randomCol . doc ( 'bar' ) ;
959952
960953 await runFirestoreOperationInRootSpan ( async ( ) => {
961954 return firestore . runTransaction ( async transaction => {
962955 await transaction . get ( docRef1 ) ;
963956 await transaction . getAll ( docRef1 , docRef2 ) ;
964- await transaction . get ( firestore . collection ( 'foo' ) . limit ( 1 ) ) ;
965- await transaction . get ( firestore . collection ( 'nonexistent' ) . count ( ) ) ;
966- transaction . set ( firestore . collection ( 'foo' ) . doc ( ) , { foo : 'bar' } ) ;
957+ await transaction . get ( randomCol . limit ( 1 ) ) ;
958+ await transaction . get (
959+ firestore . collection ( 'nonexistent_' + autoId ( ) ) . count ( ) ,
960+ ) ;
961+ transaction . set ( randomCol . doc ( ) , { foo : 'bar' } ) ;
967962 } ) ;
968963 } ) ;
969964
@@ -1032,7 +1027,7 @@ describe.skipEnterprise('Tracing Tests', () => {
10321027 // Service not implemented for Enterprise DB: PartitionQuery
10331028 it . skipEnterprise ( 'partition query' , async ( ) => {
10341029 await runFirestoreOperationInRootSpan ( async ( ) => {
1035- const query = firestore . collectionGroup ( 'foo' ) ;
1030+ const query = firestore . collectionGroup ( 'node_cg_' + autoId ( ) ) ;
10361031 let numPartitions = 0 ;
10371032 // eslint-disable-next-line @typescript-eslint/no-unused-vars
10381033 for await ( const partition of query . getPartitions ( 3 ) ) {
@@ -1052,11 +1047,11 @@ describe.skipEnterprise('Tracing Tests', () => {
10521047 await runFirestoreOperationInRootSpan ( async ( ) => {
10531048 const bulkWriter = firestore . bulkWriter ( ) ;
10541049 // No need to await the set operations as 'close()' will commit all writes before closing.
1055- void bulkWriter . set ( firestore . collection ( 'foo' ) . doc ( ) , { foo : 1 } ) ;
1056- void bulkWriter . set ( firestore . collection ( 'foo' ) . doc ( ) , { foo : 2 } ) ;
1057- void bulkWriter . set ( firestore . collection ( 'foo' ) . doc ( ) , { foo : 3 } ) ;
1058- void bulkWriter . set ( firestore . collection ( 'foo' ) . doc ( ) , { foo : 4 } ) ;
1059- void bulkWriter . set ( firestore . collection ( 'foo' ) . doc ( ) , { foo : 5 } ) ;
1050+ void bulkWriter . set ( randomCol . doc ( ) , { foo : 1 } ) ;
1051+ void bulkWriter . set ( randomCol . doc ( ) , { foo : 2 } ) ;
1052+ void bulkWriter . set ( randomCol . doc ( ) , { foo : 3 } ) ;
1053+ void bulkWriter . set ( randomCol . doc ( ) , { foo : 4 } ) ;
1054+ void bulkWriter . set ( randomCol . doc ( ) , { foo : 5 } ) ;
10601055 await bulkWriter . close ( ) ;
10611056 } ) ;
10621057
0 commit comments