Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed old logging and implement Azure core logging coverage #18723

Merged
merged 1 commit into from
Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sdk/cosmosdb/cosmos/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
"@azure/dev-tool": "^1.0.0",
"@azure/eslint-plugin-azure-sdk": "^3.0.0",
"@azure/identity": "^2.0.1",
"@azure/logger": "^1.0.0",
"@microsoft/api-extractor": "^7.18.11",
"@rollup/plugin-json": "^4.0.0",
"@rollup/plugin-multi-entry": "^3.0.0",
Expand Down
11 changes: 5 additions & 6 deletions sdk/cosmosdb/cosmos/src/ClientContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { PartitionKeyRange } from "./client/Container/PartitionKeyRange";
import { Resource } from "./client/Resource";
import { Constants, HTTPMethod, OperationType, ResourceType } from "./common/constants";
import { getIdFromLink, getPathFromLink, parseLink } from "./common/helper";
import { logger } from "./common/logger";
import { StatusCodes, SubStatusCodes } from "./common/statusCodes";
import { CosmosClientOptions } from "./CosmosClientOptions";
import { ConnectionPolicy, ConsistencyLevel, DatabaseAccount, PartitionKey } from "./documents";
Expand All @@ -30,9 +29,9 @@ import { SessionContainer } from "./session/sessionContainer";
import { SessionContext } from "./session/SessionContext";
import { BulkOptions } from "./utils/batch";
import { sanitizeEndpoint } from "./utils/checkURL";
import { AzureLogger, createClientLogger } from "@azure/logger";

/** @hidden */
const log = logger("ClientContext");
const logger: AzureLogger = createClientLogger("ClientContext");

const QueryJsonContentType = "application/query+json";

Expand Down Expand Up @@ -177,16 +176,16 @@ export class ClientContext {
}
}
this.applySessionToken(request);
log.info(
logger.info(
"query " +
requestId +
" started" +
(request.partitionKeyRangeId ? " pkrid: " + request.partitionKeyRangeId : "")
);
log.silly(request);
logger.verbose(request);
const start = Date.now();
const response = await executeRequest(request);
log.info("query " + requestId + " finished - " + (Date.now() - start) + "ms");
logger.info("query " + requestId + " finished - " + (Date.now() - start) + "ms");
this.captureSessionToken(undefined, path, OperationType.Query, response.headers);
return this.processQueryFeedResponse(response, !!query, resultFn);
}
Expand Down
77 changes: 5 additions & 72 deletions sdk/cosmosdb/cosmos/src/common/logger.ts
Original file line number Diff line number Diff line change
@@ -1,75 +1,8 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import debugLib from "debug";
import { createClientLogger, AzureLogger } from "@azure/logger";

/** @hidden */
let cosmosLevelFilter = "warn|error";

if (typeof process !== "undefined" && process.env && process.env.COSMOS_LOG_LEVEL) {
cosmosLevelFilter = process.env.COSMOS_LOG_LEVEL;
}

/** @hidden */
const cosmosDebug = debugLib("cosmos");

/** @hidden */
type logLevel = "silly" | "debug" | "info" | "warn" | "error";

/** @hidden */
const levelLogger = (namespaceLogger: debugLib.Debugger, level: logLevel) => {
return (message: string | { [key: string]: any }) => {
if (cosmosLevelFilter.includes(level)) {
namespaceLogger("[" + new Date().toISOString() + "][" + level + "]: %o", message);
}
};
};

/** @hidden */
export const logger = (
namespace: string
): {
silly: (
message:
| string
| {
[key: string]: any;
}
) => void;
debug: (
message:
| string
| {
[key: string]: any;
}
) => void;
info: (
message:
| string
| {
[key: string]: any;
}
) => void;
warn: (
message:
| string
| {
[key: string]: any;
}
) => void;
error: (
message:
| string
| {
[key: string]: any;
}
) => void;
} => {
const namespaceLogger = cosmosDebug.extend(namespace);
return {
silly: levelLogger(namespaceLogger, "silly"),
debug: levelLogger(namespaceLogger, "debug"),
info: levelLogger(namespaceLogger, "info"),
warn: levelLogger(namespaceLogger, "warn"),
error: levelLogger(namespaceLogger, "error")
};
};
/**
* The \@azure/logger configuration for this package.
*/
export const defaultLogger: AzureLogger = createClientLogger("cosmosdb");
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { AzureLogger, createClientLogger } from "@azure/logger";
import { Constants } from "../common";
import { logger } from "../common/logger";
import { ClientSideMetrics, QueryMetrics } from "../queryMetrics";
import { FeedOptions, Response } from "../request";
import { getInitialHeader } from "./headerUtils";
import { ExecutionContext } from "./index";

/** @hidden */
const log = logger("defaultQueryExecutionContext");

const logger: AzureLogger = createClientLogger("ClientContext");
/** @hidden */
export type FetchFunctionCallback = (options: FeedOptions) => Promise<Response<any>>;

Expand Down Expand Up @@ -133,11 +131,11 @@ export class DefaultQueryExecutionContext implements ExecutionContext {
try {
let p: Promise<Response<any>>;
if (this.nextFetchFunction !== undefined) {
log.debug("using prefetch");
logger.verbose("using prefetch");
p = this.nextFetchFunction;
this.nextFetchFunction = undefined;
} else {
log.debug("using fresh fetch");
logger.verbose("using fresh fetch");
p = this.fetchFunctions[this.currentPartitionIndex](this.options);
}
const response = await p;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import PriorityQueue from "priorityqueuejs";
import semaphore from "semaphore";
import { ClientContext } from "../ClientContext";
import { logger } from "../common/logger";
import { AzureLogger, createClientLogger } from "@azure/logger";
import { StatusCodes, SubStatusCodes } from "../common/statusCodes";
import { FeedOptions, Response } from "../request";
import { PartitionedQueryExecutionInfo } from "../request/ErrorResponse";
Expand All @@ -16,7 +16,7 @@ import { getInitialHeader, mergeHeaders } from "./headerUtils";
import { SqlQuerySpec } from "./SqlQuerySpec";

/** @hidden */
const log = logger("parallelQueryExecutionContextBase");
const logger: AzureLogger = createClientLogger("parallelQueryExecutionContextBase");

/** @hidden */
export enum ParallelQueryExecutionContextBaseStates {
Expand Down Expand Up @@ -92,7 +92,7 @@ export abstract class ParallelQueryExecutionContextBase implements ExecutionCont
? targetPartitionRanges.length
: Math.min(options.maxDegreeOfParallelism, targetPartitionRanges.length);

log.info(
logger.info(
"Query starting against " +
targetPartitionRanges.length +
" ranges with parallelism of " +
Expand Down
7 changes: 3 additions & 4 deletions sdk/cosmosdb/cosmos/src/request/RequestHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
} from "@azure/core-rest-pipeline";
import { trimSlashes } from "../common";
import { Constants } from "../common/constants";
import { logger } from "../common/logger";
import { executePlugins, PluginOn } from "../plugins/Plugin";
import * as RetryUtility from "../retry/retryUtility";
import { defaultHttpAgent, defaultHttpsAgent } from "./defaultAgent";
Expand All @@ -19,9 +18,9 @@ import { Response as CosmosResponse } from "./Response";
import { TimeoutError } from "./TimeoutError";
import { URL } from "../utils/url";
import { getCachedDefaultHttpClient } from "../utils/cachedClient";
import { AzureLogger, createClientLogger } from "@azure/logger";

/** @hidden */
const log = logger("RequestHandler");
const logger: AzureLogger = createClientLogger("RequestHandler");

async function executeRequest(requestContext: RequestContext): Promise<CosmosResponse<any>> {
return executePlugins(requestContext, httpRequest, PluginOn.request);
Expand Down Expand Up @@ -112,7 +111,7 @@ async function httpRequest(
if (response.status >= 400) {
const errorResponse: ErrorResponse = new Error(result.message);

log.warn(
logger.warning(
response.status +
" " +
requestContext.endpoint +
Expand Down