From 973f019713c6a8fdddf37196f760261260b7209c Mon Sep 17 00:00:00 2001 From: PingZhu2232 <36140352+PingZhu2232@users.noreply.github.com> Date: Mon, 11 Jan 2021 11:03:40 -0800 Subject: [PATCH] Add correlation id in routerlicious-driver (#4734) * bug fix to change from fixed uuid to random ones every time * fix eslint issue * added correlation id in the header * reverted changes in bindCorrelationId * fixed lint issues * reverted historian client to be without getCorrelationId * added correlation id in historian client * clean up and removed else condition * recover * recover again * added lerna lock * added logger into driver * fixed version error Co-authored-by: Ping Zhu --- lerna-package-lock.json | 86 +++++++++---------- .../drivers/routerlicious-driver/package.json | 3 + .../src/createDocumentService2.ts | 3 + .../src/deltaStorageService.ts | 23 +++-- .../src/documentService.ts | 4 +- .../src/documentService2.ts | 3 + .../src/documentServiceFactory.ts | 5 ++ .../routerlicious-driver/src/registration.ts | 5 +- 8 files changed, 82 insertions(+), 50 deletions(-) diff --git a/lerna-package-lock.json b/lerna-package-lock.json index 1d93f459534f..65d28a9816a2 100644 --- a/lerna-package-lock.json +++ b/lerna-package-lock.json @@ -2833,12 +2833,12 @@ } }, "@fluidframework/server-services-utils": { - "version": "0.1016.0", - "resolved": "https://registry.npmjs.org/@fluidframework/server-services-utils/-/server-services-utils-0.1016.0.tgz", - "integrity": "sha512-V4lqkIGd0Qf6S9gAgbMLlU+oZCkh4KmHp80bb61oJLjQRn0BfjQCp1huGO2gHfRLwxub2AXHy5jHqd5adZcbuQ==", + "version": "0.1016.1", + "resolved": "https://registry.npmjs.org/@fluidframework/server-services-utils/-/server-services-utils-0.1016.1.tgz", + "integrity": "sha512-neVyTV5F2YH+VuwTzHvWqD0rlV+68jLGKuOj3pkriFrNt/HERx5LZv8hp57F/aFfziuOG3rPaCbF7Q175smsXw==", "dev": true, "requires": { - "@fluidframework/protocol-definitions": "^0.1016.0", + "@fluidframework/protocol-definitions": "^0.1016.1", "@sentry/node": "^5.6.2", "debug": "^4.1.1", "express": "^4.16.3", @@ -5679,51 +5679,51 @@ } }, "@sentry/core": { - "version": "5.29.1", - "resolved": "https://registry.npmjs.org/@sentry/core/-/core-5.29.1.tgz", - "integrity": "sha512-SMybIx9IlswkJ7a61ez/zjdiMdAo51Adpo4nVrzke2k84U/t726/EbJj0FJ4vVgsGdLCvSSZ6v7BQlINcwWupg==", + "version": "5.29.2", + "resolved": "https://registry.npmjs.org/@sentry/core/-/core-5.29.2.tgz", + "integrity": "sha512-7WYkoxB5IdlNEbwOwqSU64erUKH4laavPsM0/yQ+jojM76ErxlgEF0u//p5WaLPRzh3iDSt6BH+9TL45oNZeZw==", "dev": true, "requires": { - "@sentry/hub": "5.29.1", - "@sentry/minimal": "5.29.1", - "@sentry/types": "5.29.1", - "@sentry/utils": "5.29.1", + "@sentry/hub": "5.29.2", + "@sentry/minimal": "5.29.2", + "@sentry/types": "5.29.2", + "@sentry/utils": "5.29.2", "tslib": "^1.9.3" } }, "@sentry/hub": { - "version": "5.29.1", - "resolved": "https://registry.npmjs.org/@sentry/hub/-/hub-5.29.1.tgz", - "integrity": "sha512-Ig/vqCiJcsnGaWajkWRFH+5IKeo50ZtsjM0zJb8IfTadLjQuF/gTQst0aXO3l6q4HzveeGsELY8jlm6WVcq9Aw==", + "version": "5.29.2", + "resolved": "https://registry.npmjs.org/@sentry/hub/-/hub-5.29.2.tgz", + "integrity": "sha512-LaAIo2hwUk9ykeh9RF0cwLy6IRw+DjEee8l1HfEaDFUM6TPGlNNGObMJNXb9/95jzWp7jWwOpQjoIE3jepdQJQ==", "dev": true, "requires": { - "@sentry/types": "5.29.1", - "@sentry/utils": "5.29.1", + "@sentry/types": "5.29.2", + "@sentry/utils": "5.29.2", "tslib": "^1.9.3" } }, "@sentry/minimal": { - "version": "5.29.1", - "resolved": "https://registry.npmjs.org/@sentry/minimal/-/minimal-5.29.1.tgz", - "integrity": "sha512-lAa3+Duxum1qQvR0tKiBUsH6Ehit3g/vO53SqBib7YK3qdvIUWHacmkJvfz/AeSvVnpJ9bsBMCVRJNSVe8BPVA==", + "version": "5.29.2", + "resolved": "https://registry.npmjs.org/@sentry/minimal/-/minimal-5.29.2.tgz", + "integrity": "sha512-0aINSm8fGA1KyM7PavOBe1GDZDxrvnKt+oFnU0L+bTcw8Lr+of+v6Kwd97rkLRNOLw621xP076dL/7LSIzMuhw==", "dev": true, "requires": { - "@sentry/hub": "5.29.1", - "@sentry/types": "5.29.1", + "@sentry/hub": "5.29.2", + "@sentry/types": "5.29.2", "tslib": "^1.9.3" } }, "@sentry/node": { - "version": "5.29.1", - "resolved": "https://registry.npmjs.org/@sentry/node/-/node-5.29.1.tgz", - "integrity": "sha512-j8PzW+Fk84UZJkxPSnyEE4HTQxphSAAauGbeLiEJ69ZZGKD7/O1CBxEsvPel3n4jGe/9bK+AIuEpLHwoZjex0Q==", + "version": "5.29.2", + "resolved": "https://registry.npmjs.org/@sentry/node/-/node-5.29.2.tgz", + "integrity": "sha512-98m1ZejmJgA+eiz6jEFyYYfp6kJZQnx6d6KrJDMxGfss4YTmmJY57bE4xStnjjk7WINDGzlCiHuk+wJFMBjuoA==", "dev": true, "requires": { - "@sentry/core": "5.29.1", - "@sentry/hub": "5.29.1", - "@sentry/tracing": "5.29.1", - "@sentry/types": "5.29.1", - "@sentry/utils": "5.29.1", + "@sentry/core": "5.29.2", + "@sentry/hub": "5.29.2", + "@sentry/tracing": "5.29.2", + "@sentry/types": "5.29.2", + "@sentry/utils": "5.29.2", "cookie": "^0.4.1", "https-proxy-agent": "^5.0.0", "lru_map": "^0.3.3", @@ -5758,31 +5758,31 @@ } }, "@sentry/tracing": { - "version": "5.29.1", - "resolved": "https://registry.npmjs.org/@sentry/tracing/-/tracing-5.29.1.tgz", - "integrity": "sha512-iWfPtDhf5X7N9R5WB3vX/wlyFVsGG8iMx4hLIP+6bj8EcPYnZfeP6Sxn65a0ACT/FKv7SMBoZ1qPDzmvk0bviw==", + "version": "5.29.2", + "resolved": "https://registry.npmjs.org/@sentry/tracing/-/tracing-5.29.2.tgz", + "integrity": "sha512-iumYbVRpvoU3BUuIooxibydeaOOjl5ysc+mzsqhRs2NGW/C3uKAsFXdvyNfqt3bxtRQwJEhwJByLP2u3pLThpw==", "dev": true, "requires": { - "@sentry/hub": "5.29.1", - "@sentry/minimal": "5.29.1", - "@sentry/types": "5.29.1", - "@sentry/utils": "5.29.1", + "@sentry/hub": "5.29.2", + "@sentry/minimal": "5.29.2", + "@sentry/types": "5.29.2", + "@sentry/utils": "5.29.2", "tslib": "^1.9.3" } }, "@sentry/types": { - "version": "5.29.1", - "resolved": "https://registry.npmjs.org/@sentry/types/-/types-5.29.1.tgz", - "integrity": "sha512-QXZBA1gJheMYTGFV+UUhr3+jKpGZqPx8kEJABs8htlKabCDJlEeoFNmeqPuVxCxukoy5ZaaHACoE+2Z87T0g2A==", + "version": "5.29.2", + "resolved": "https://registry.npmjs.org/@sentry/types/-/types-5.29.2.tgz", + "integrity": "sha512-dM9wgt8wy4WRty75QkqQgrw9FV9F+BOMfmc0iaX13Qos7i6Qs2Q0dxtJ83SoR4YGtW8URaHzlDtWlGs5egBiMA==", "dev": true }, "@sentry/utils": { - "version": "5.29.1", - "resolved": "https://registry.npmjs.org/@sentry/utils/-/utils-5.29.1.tgz", - "integrity": "sha512-FOhWxASvIQREAlSuWf3Vmb4uIkG0fmRdHkULpuv5dFmrMX2PpudYAppQtS8K9V4BYxFy6KFdUht1Qz5zYTecMw==", + "version": "5.29.2", + "resolved": "https://registry.npmjs.org/@sentry/utils/-/utils-5.29.2.tgz", + "integrity": "sha512-nEwQIDjtFkeE4k6yIk4Ka5XjGRklNLThWLs2xfXlL7uwrYOH2B9UBBOOIRUraBm/g/Xrra3xsam/kRxuiwtXZQ==", "dev": true, "requires": { - "@sentry/types": "5.29.1", + "@sentry/types": "5.29.2", "tslib": "^1.9.3" } }, diff --git a/packages/drivers/routerlicious-driver/package.json b/packages/drivers/routerlicious-driver/package.json index 24c0756f8c04..1b680cd73263 100644 --- a/packages/drivers/routerlicious-driver/package.json +++ b/packages/drivers/routerlicious-driver/package.json @@ -37,12 +37,14 @@ "@fluidframework/protocol-base": "^0.1017.1", "@fluidframework/protocol-definitions": "^0.1017.1", "@fluidframework/server-services-client": "^0.1017.1", + "@fluidframework/telemetry-utils": "^0.33.0", "assert": "^2.0.0", "axios": "^0.21.1", "debug": "^4.1.1", "isomorphic-ws": "^4.0.1", "jwt-decode": "^2.2.0", "socket.io-client": "^2.1.1", + "uuid": "^8.3.1", "ws": "^6.1.2" }, "devDependencies": { @@ -55,6 +57,7 @@ "@types/mocha": "^5.2.5", "@types/nock": "^9.3.0", "@types/socket.io-client": "^1.4.32", + "@types/uuid": "^8.3.0", "@types/ws": "^6.0.1", "@typescript-eslint/eslint-plugin": "~4.2.0", "@typescript-eslint/parser": "~4.2.0", diff --git a/packages/drivers/routerlicious-driver/src/createDocumentService2.ts b/packages/drivers/routerlicious-driver/src/createDocumentService2.ts index 92d5dec2a4fe..9513dfc53dc0 100644 --- a/packages/drivers/routerlicious-driver/src/createDocumentService2.ts +++ b/packages/drivers/routerlicious-driver/src/createDocumentService2.ts @@ -3,6 +3,7 @@ * Licensed under the MIT License. */ +import { ITelemetryLogger } from "@fluidframework/common-definitions"; import { IDocumentService, IResolvedUrl } from "@fluidframework/driver-definitions"; import { IErrorTrackingService } from "@fluidframework/protocol-definitions"; import { ICredentials } from "@fluidframework/server-services-client"; @@ -27,6 +28,7 @@ export const createDocumentService2 = ( errorTracking: IErrorTrackingService = new DefaultErrorTracking(), disableCache = false, historianApi = true, + logger: ITelemetryLogger, credentials?: ICredentials): IDocumentService => new DocumentService2( resolvedUrl, ordererUrl, @@ -36,6 +38,7 @@ export const createDocumentService2 = ( disableCache, historianApi, credentials, + logger, tokenProvider, tenantId, documentId); diff --git a/packages/drivers/routerlicious-driver/src/deltaStorageService.ts b/packages/drivers/routerlicious-driver/src/deltaStorageService.ts index 0daa6904cb64..2538b636de87 100644 --- a/packages/drivers/routerlicious-driver/src/deltaStorageService.ts +++ b/packages/drivers/routerlicious-driver/src/deltaStorageService.ts @@ -3,12 +3,15 @@ * Licensed under the MIT License. */ +import { OutgoingHttpHeaders } from "http"; import querystring from "querystring"; import { fromUtf8ToBase64 } from "@fluidframework/common-utils"; import { IDeltaStorageService, IDocumentDeltaStorageService } from "@fluidframework/driver-definitions"; import Axios from "axios"; +import * as uuid from "uuid"; import { ISequencedDocumentMessage } from "@fluidframework/protocol-definitions"; import { readAndParse } from "@fluidframework/driver-utils"; +import { ITelemetryLogger } from "@fluidframework/common-definitions"; import { ITokenProvider } from "./tokens"; import { DocumentStorageService } from "./documentStorageService"; @@ -44,7 +47,10 @@ export class DocumentDeltaStorageService implements IDocumentDeltaStorageService * Provides access to the underlying delta storage on the server for routerlicious driver. */ export class DeltaStorageService implements IDeltaStorageService { - constructor(private readonly url: string, private readonly tokenProvider: ITokenProvider) { + constructor( + private readonly url: string, + private readonly tokenProvider: ITokenProvider, + private readonly logger: ITelemetryLogger | undefined) { } public async get( @@ -54,7 +60,9 @@ export class DeltaStorageService implements IDeltaStorageService { to?: number): Promise { const query = querystring.stringify({ from, to }); - let headers: { Authorization: string } | null = null; + const headers: OutgoingHttpHeaders = { + "x-correlation-id": uuid.v4(), + }; const storageToken = await this.tokenProvider.fetchStorageToken( tenantId, @@ -62,14 +70,19 @@ export class DeltaStorageService implements IDeltaStorageService { ); if (storageToken) { - headers = { - Authorization: `Basic ${fromUtf8ToBase64(`${tenantId}:${storageToken.jwt}`)}`, - }; + headers.Authorization = `Basic ${fromUtf8ToBase64(`${tenantId}:${storageToken.jwt}`)}`; } const ops = await Axios.get( `${this.url}?${query}`, { headers }); + if (this.logger) { + this.logger.sendTelemetryEvent({ + eventName: "R11sDriverToServer", + correlationId: headers["x-correlation-id"] as string, + }); + } + return ops.data; } } diff --git a/packages/drivers/routerlicious-driver/src/documentService.ts b/packages/drivers/routerlicious-driver/src/documentService.ts index fbcf18756d9e..b157ac97ac83 100644 --- a/packages/drivers/routerlicious-driver/src/documentService.ts +++ b/packages/drivers/routerlicious-driver/src/documentService.ts @@ -8,6 +8,7 @@ import * as api from "@fluidframework/driver-definitions"; import { IClient, IErrorTrackingService } from "@fluidframework/protocol-definitions"; import { GitManager, Historian, ICredentials, IGitCache } from "@fluidframework/server-services-client"; import io from "socket.io-client"; +import { ITelemetryLogger } from "@fluidframework/common-definitions"; import { DeltaStorageService, DocumentDeltaStorageService } from "./deltaStorageService"; import { DocumentStorageService } from "./documentStorageService"; import { R11sDocumentDeltaConnection } from "./documentDeltaConnection"; @@ -29,6 +30,7 @@ export class DocumentService implements api.IDocumentService { private readonly historianApi: boolean, private readonly directCredentials: ICredentials | undefined, private readonly gitCache: IGitCache | undefined, + private readonly logger: ITelemetryLogger | undefined, protected tokenProvider: ITokenProvider, protected tenantId: string, protected documentId: string, @@ -101,7 +103,7 @@ export class DocumentService implements api.IDocumentService { public async connectToDeltaStorage(): Promise { assert(this.documentStorageService, "Storage service not initialized"); - const deltaStorage = new DeltaStorageService(this.deltaStorageUrl, this.tokenProvider); + const deltaStorage = new DeltaStorageService(this.deltaStorageUrl, this.tokenProvider, this.logger); return new DocumentDeltaStorageService(this.tenantId, this.documentId, deltaStorage, this.documentStorageService); } diff --git a/packages/drivers/routerlicious-driver/src/documentService2.ts b/packages/drivers/routerlicious-driver/src/documentService2.ts index b81d9b239339..dc8193d28004 100644 --- a/packages/drivers/routerlicious-driver/src/documentService2.ts +++ b/packages/drivers/routerlicious-driver/src/documentService2.ts @@ -3,6 +3,7 @@ * Licensed under the MIT License. */ +import { ITelemetryLogger } from "@fluidframework/common-definitions"; import { IDocumentDeltaConnection, IResolvedUrl } from "@fluidframework/driver-definitions"; import * as api from "@fluidframework/protocol-definitions"; import { ICredentials } from "@fluidframework/server-services-client"; @@ -23,6 +24,7 @@ export class DocumentService2 extends DocumentService { errorTracking: api.IErrorTrackingService, disableCache: boolean, historianApi: boolean, directCredentials: ICredentials | undefined, + logger: ITelemetryLogger, tokenProvider: ITokenProvider, tenantId: string, documentId: string) { @@ -36,6 +38,7 @@ export class DocumentService2 extends DocumentService { historianApi, directCredentials, undefined, + logger, tokenProvider, tenantId, documentId); diff --git a/packages/drivers/routerlicious-driver/src/documentServiceFactory.ts b/packages/drivers/routerlicious-driver/src/documentServiceFactory.ts index 84e908f1524e..522dcd7c9114 100644 --- a/packages/drivers/routerlicious-driver/src/documentServiceFactory.ts +++ b/packages/drivers/routerlicious-driver/src/documentServiceFactory.ts @@ -19,6 +19,7 @@ import { getQuorumValuesFromProtocolSummary, } from "@fluidframework/driver-utils"; import Axios from "axios"; +import { ChildLogger } from "@fluidframework/telemetry-utils"; import { DocumentService } from "./documentService"; import { DocumentService2 } from "./documentService2"; import { DefaultErrorTracking } from "./errorTracking"; @@ -99,6 +100,8 @@ export class RouterliciousDocumentServiceFactory implements IDocumentServiceFact `Couldn't parse documentId and/or tenantId. [documentId:${documentId}][tenantId:${tenantId}]`); } + const logger2 = ChildLogger.create(logger, "RouterliciousDriver"); + if (this.useDocumentService2) { return new DocumentService2( fluidResolvedUrl, @@ -109,6 +112,7 @@ export class RouterliciousDocumentServiceFactory implements IDocumentServiceFact this.disableCache, this.historianApi, this.credentials, + logger2, this.tokenProvider, tenantId, documentId); @@ -123,6 +127,7 @@ export class RouterliciousDocumentServiceFactory implements IDocumentServiceFact this.historianApi, this.credentials, this.gitCache, + logger2, this.tokenProvider, tenantId, documentId); diff --git a/packages/drivers/routerlicious-driver/src/registration.ts b/packages/drivers/routerlicious-driver/src/registration.ts index 0fa139a68d84..2d711edb8537 100644 --- a/packages/drivers/routerlicious-driver/src/registration.ts +++ b/packages/drivers/routerlicious-driver/src/registration.ts @@ -3,6 +3,7 @@ * Licensed under the MIT License. */ +import { ITelemetryLogger } from "@fluidframework/common-definitions"; import { IDocumentService, IResolvedUrl } from "@fluidframework/driver-definitions"; import { IErrorTrackingService } from "@fluidframework/protocol-definitions"; import { IGitCache } from "@fluidframework/server-services-client"; @@ -28,7 +29,8 @@ export function createDocumentService( disableCache = false, historianApi = true, credentials?, - seedData?: IGitCache): IDocumentService { + seedData?: IGitCache, + logger?: ITelemetryLogger): IDocumentService { const service = new DocumentService( resolvedUrl, ordererUrl, @@ -39,6 +41,7 @@ export function createDocumentService( historianApi, credentials, seedData, + logger, tokenProvider, tenantId, documentId);