@fluidframework/routerlicious-driver 2.0.0-internal.2.0.3 → 2.0.0-internal.2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -18,7 +18,7 @@ import {
18
18
  getQuorumValuesFromProtocolSummary,
19
19
  RateLimiter,
20
20
  } from "@fluidframework/driver-utils";
21
- import { ChildLogger } from "@fluidframework/telemetry-utils";
21
+ import { ChildLogger, PerformanceEvent } from "@fluidframework/telemetry-utils";
22
22
  import { ISession } from "@fluidframework/server-services-client";
23
23
  import { DocumentService } from "./documentService";
24
24
  import { IRouterliciousDriverPolicies } from "./policies";
@@ -108,16 +108,34 @@ export class RouterliciousDocumentServiceFactory implements IDocumentServiceFact
108
108
  resolvedUrl.endpoints.ordererUrl,
109
109
  );
110
110
 
111
- // @TODO: Remove returned "string" type when removing back-compat code
112
- const res = await ordererRestWrapper.post<{ id: string; token?: string; session?: ISession; } | string>(
113
- `/documents/${tenantId}`,
111
+ const res = await PerformanceEvent.timedExecAsync(
112
+ logger2,
114
113
  {
115
- summary: convertSummaryToCreateNewSummary(appSummary),
116
- sequenceNumber: documentAttributes.sequenceNumber,
117
- values: quorumValues,
118
- enableDiscovery: this.driverPolicies.enableDiscovery,
119
- generateToken: this.tokenProvider.documentPostCreateCallback !== undefined,
114
+ eventName: "CreateNew",
115
+ details: JSON.stringify({
116
+ enableDiscovery: this.driverPolicies.enableDiscovery,
117
+ sequenceNumber: documentAttributes.sequenceNumber,
118
+ }),
120
119
  },
120
+ async (event) => {
121
+ // @TODO: Remove returned "string" type when removing back-compat code
122
+ const postRes = await ordererRestWrapper.post<
123
+ { id: string; token?: string; session?: ISession; } | string
124
+ >(`/documents/${tenantId}`, {
125
+ summary: convertSummaryToCreateNewSummary(appSummary),
126
+ sequenceNumber: documentAttributes.sequenceNumber,
127
+ values: quorumValues,
128
+ enableDiscovery: this.driverPolicies.enableDiscovery,
129
+ generateToken:
130
+ this.tokenProvider.documentPostCreateCallback !==
131
+ undefined,
132
+ });
133
+
134
+ event.end({
135
+ docId: typeof postRes === "string" ? postRes : postRes.id,
136
+ });
137
+ return postRes;
138
+ }
121
139
  );
122
140
 
123
141
  // For supporting backward compatibility, when the request has generateToken === true, it will return
@@ -138,12 +156,20 @@ export class RouterliciousDocumentServiceFactory implements IDocumentServiceFact
138
156
 
139
157
  // @TODO: Remove token from the condition, checking the documentPostCreateCallback !== undefined
140
158
  // is sufficient to determine if the token will be undefined or not.
141
- if (token && this.tokenProvider.documentPostCreateCallback !== undefined) {
142
- try {
143
- await this.tokenProvider.documentPostCreateCallback(documentId, token);
144
- } catch (error: any) {
145
- throw new DocumentPostCreateError(error);
146
- }
159
+ try {
160
+ await PerformanceEvent.timedExecAsync(
161
+ logger2,
162
+ {
163
+ eventName: "DocPostCreateCallback",
164
+ docId: documentId,
165
+ },
166
+ async () => {
167
+ if (token && this.tokenProvider.documentPostCreateCallback !== undefined) {
168
+ return this.tokenProvider.documentPostCreateCallback(documentId, token);
169
+ }
170
+ });
171
+ } catch (error: any) {
172
+ throw new DocumentPostCreateError(error);
147
173
  }
148
174
 
149
175
  parsedUrl.set("pathname", replaceDocumentIdInPath(parsedUrl.pathname, documentId));
@@ -206,10 +232,18 @@ export class RouterliciousDocumentServiceFactory implements IDocumentServiceFact
206
232
  this.driverPolicies.enableRestLess,
207
233
  resolvedUrl.endpoints.ordererUrl,
208
234
  );
209
- // The service responds with the current document session associated with the container.
210
- const discoveredSession = await ordererRestWrapper.get<ISession>(
211
- `/documents/${tenantId}/session/${documentId}`,
212
- );
235
+
236
+ const discoveredSession = await PerformanceEvent.timedExecAsync(
237
+ logger2,
238
+ {
239
+ eventName: "DiscoverSession",
240
+ docId: documentId,
241
+ },
242
+ async () => {
243
+ // The service responds with the current document session associated with the container.
244
+ return ordererRestWrapper.get<ISession>(
245
+ `/documents/${tenantId}/session/${documentId}`);
246
+ });
213
247
  return getDiscoveredFluidResolvedUrl(resolvedUrl, discoveredSession);
214
248
  };
215
249
  const fluidResolvedUrl: IFluidResolvedUrl = session !== undefined
package/src/index.ts CHANGED
@@ -4,11 +4,11 @@
4
4
  */
5
5
 
6
6
  // Tokens
7
- export * from "./defaultTokenProvider";
8
- export * from "./tokens";
7
+ export { DefaultTokenProvider } from "./defaultTokenProvider";
8
+ export { ITokenProvider, ITokenResponse, ITokenService } from "./tokens";
9
9
 
10
10
  // Factory
11
- export * from "./documentServiceFactory";
11
+ export { DocumentPostCreateError, RouterliciousDocumentServiceFactory } from "./documentServiceFactory";
12
12
 
13
13
  // Configuration
14
- export * from "./policies";
14
+ export { IRouterliciousDriverPolicies } from "./policies";
@@ -6,4 +6,4 @@
6
6
  */
7
7
 
8
8
  export const pkgName = "@fluidframework/routerlicious-driver";
9
- export const pkgVersion = "2.0.0-internal.2.0.3";
9
+ export const pkgVersion = "2.0.0-internal.2.1.0";
@@ -11,6 +11,7 @@ import {
11
11
  RestLessClient,
12
12
  RestWrapper,
13
13
  } from "@fluidframework/server-services-client";
14
+ import { PerformanceEvent } from "@fluidframework/telemetry-utils";
14
15
  import fetch from "cross-fetch";
15
16
  import type { AxiosRequestConfig, AxiosRequestHeaders } from "axios";
16
17
  import safeStringify from "json-stringify-safe";
@@ -145,17 +146,26 @@ export class RouterliciousStorageRestWrapper extends RouterliciousRestWrapper {
145
146
  token: `${fromUtf8ToBase64(tenantId)}`,
146
147
  };
147
148
  const getAuthorizationHeader: AuthorizationHeaderGetter = async (refreshToken?: boolean): Promise<string> => {
148
- // Craft credentials using tenant id and token
149
- const storageToken = await tokenProvider.fetchStorageToken(
150
- tenantId,
151
- documentId,
152
- refreshToken,
149
+ return PerformanceEvent.timedExecAsync(
150
+ logger,
151
+ {
152
+ eventName: "FetchStorageToken",
153
+ docId: documentId,
154
+ },
155
+ async () => {
156
+ // Craft credentials using tenant id and token
157
+ const storageToken = await tokenProvider.fetchStorageToken(
158
+ tenantId,
159
+ documentId,
160
+ refreshToken
161
+ );
162
+ const credentials = {
163
+ password: storageToken.jwt,
164
+ user: tenantId,
165
+ };
166
+ return getAuthorizationTokenFromCredentials(credentials);
167
+ }
153
168
  );
154
- const credentials = {
155
- password: storageToken.jwt,
156
- user: tenantId,
157
- };
158
- return getAuthorizationTokenFromCredentials(credentials);
159
169
  };
160
170
 
161
171
  const restWrapper = new RouterliciousStorageRestWrapper(
@@ -194,12 +204,21 @@ export class RouterliciousOrdererRestWrapper extends RouterliciousRestWrapper {
194
204
  baseurl?: string,
195
205
  ): Promise<RouterliciousOrdererRestWrapper> {
196
206
  const getAuthorizationHeader: AuthorizationHeaderGetter = async (refreshToken?: boolean): Promise<string> => {
197
- const ordererToken = await tokenProvider.fetchOrdererToken(
198
- tenantId,
199
- documentId,
200
- refreshToken,
207
+ return PerformanceEvent.timedExecAsync(
208
+ logger,
209
+ {
210
+ eventName: "FetchOrdererToken",
211
+ docId: documentId,
212
+ },
213
+ async () => {
214
+ const ordererToken = await tokenProvider.fetchOrdererToken(
215
+ tenantId,
216
+ documentId,
217
+ refreshToken,
218
+ );
219
+ return `Basic ${ordererToken.jwt}`;
220
+ }
201
221
  );
202
- return `Basic ${ordererToken.jwt}`;
203
222
  };
204
223
 
205
224
  const restWrapper = new RouterliciousOrdererRestWrapper(