@@ -10,9 +10,11 @@ import {
10
10
type AzureContainerServices ,
11
11
type AzureLocalConnectionConfig ,
12
12
type AzureRemoteConnectionConfig ,
13
+ type ITelemetryBaseEvent ,
13
14
} from "@fluidframework/azure-client" ;
14
15
import { AttachState } from "@fluidframework/container-definitions" ;
15
16
import { ConnectionState } from "@fluidframework/container-loader" ;
17
+ import { LogLevel } from "@fluidframework/core-interfaces" ;
16
18
import type { ScopeType } from "@fluidframework/driver-definitions/legacy" ;
17
19
import type { ContainerSchema , IFluidContainer } from "@fluidframework/fluid-static" ;
18
20
import {
@@ -37,6 +39,7 @@ type MessageToParent = Required<MessageFromChild>;
37
39
const connectTimeoutMs = 10_000 ;
38
40
// Identifier given to child process
39
41
const process_id = process . argv [ 2 ] ;
42
+ const verbosity = process . argv [ 3 ] ?? "" ;
40
43
41
44
const useAzure = process . env . FLUID_CLIENT === "azure" ;
42
45
const tenantId = useAzure
@@ -47,6 +50,24 @@ if (useAzure && endPoint === undefined) {
47
50
throw new Error ( "Azure Fluid Relay service endpoint is missing" ) ;
48
51
}
49
52
53
+ function selectiveVerboseLog ( event : ITelemetryBaseEvent , logLevel ?: LogLevel ) : void {
54
+ if ( event . eventName . includes ( ":Signal" ) || event . eventName . includes ( ":Join" ) ) {
55
+ console . log ( `[${ process_id } ] [${ logLevel ?? LogLevel . default } ]` , {
56
+ eventName : event . eventName ,
57
+ details : event . details ,
58
+ containerConnectionState : event . containerConnectionState ,
59
+ } ) ;
60
+ } else if (
61
+ event . eventName . includes ( ":Container:" ) ||
62
+ event . eventName . includes ( ":Presence:" )
63
+ ) {
64
+ console . log ( `[${ process_id } ] [${ logLevel ?? LogLevel . default } ]` , {
65
+ eventName : event . eventName ,
66
+ containerConnectionState : event . containerConnectionState ,
67
+ } ) ;
68
+ }
69
+ }
70
+
50
71
/**
51
72
* Get or create a Fluid container with Presence in initialObjects.
52
73
*/
@@ -81,7 +102,12 @@ const getOrCreatePresenceContainer = async (
81
102
endpoint : "http://localhost:7071" ,
82
103
type : "local" ,
83
104
} ;
84
- const client = new AzureClient ( { connection : connectionProps } ) ;
105
+ const client = new AzureClient ( {
106
+ connection : connectionProps ,
107
+ logger : {
108
+ send : verbosity . includes ( "telem" ) ? selectiveVerboseLog : ( ) => { } ,
109
+ } ,
110
+ } ) ;
85
111
const schema : ContainerSchema = {
86
112
initialObjects : {
87
113
// A DataObject is added as otherwise fluid-static complains "Container cannot be initialized without any DataTypes"
@@ -120,7 +146,14 @@ const getOrCreatePresenceContainer = async (
120
146
} ;
121
147
function createSendFunction ( ) : ( msg : MessageToParent ) => void {
122
148
if ( process . send ) {
123
- return process . send . bind ( process ) ;
149
+ const sendFn = process . send . bind ( process ) ;
150
+ if ( verbosity . includes ( "msgs" ) ) {
151
+ return ( msg : MessageToParent ) => {
152
+ console . log ( `[${ process_id } ] Sending` , msg ) ;
153
+ sendFn ( msg ) ;
154
+ } ;
155
+ }
156
+ return sendFn ;
124
157
}
125
158
throw new Error ( "process.send is not defined" ) ;
126
159
}
@@ -262,6 +295,9 @@ class MessageHandler {
262
295
}
263
296
264
297
public async onMessage ( msg : MessageFromParent ) : Promise < void > {
298
+ if ( verbosity . includes ( "msgs" ) ) {
299
+ console . log ( `[${ process_id } ] Received` , msg ) ;
300
+ }
265
301
switch ( msg . command ) {
266
302
case "ping" : {
267
303
this . handlePing ( ) ;
0 commit comments