@fluidframework/telemetry-utils 2.0.0-internal.6.4.0 → 2.0.0-internal.7.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.
Files changed (55) hide show
  1. package/CHANGELOG.md +63 -0
  2. package/api-extractor.json +9 -1
  3. package/api-report/telemetry-utils.api.md +444 -0
  4. package/dist/config.d.ts +1 -1
  5. package/dist/config.d.ts.map +1 -1
  6. package/dist/error.d.ts.map +1 -1
  7. package/dist/error.js +2 -1
  8. package/dist/error.js.map +1 -1
  9. package/dist/errorLogging.js +6 -6
  10. package/dist/errorLogging.js.map +1 -1
  11. package/dist/index.d.ts +1 -1
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +2 -1
  14. package/dist/index.js.map +1 -1
  15. package/dist/logger.d.ts +49 -5
  16. package/dist/logger.d.ts.map +1 -1
  17. package/dist/logger.js +89 -35
  18. package/dist/logger.js.map +1 -1
  19. package/dist/telemetry-utils-alpha.d.ts +668 -0
  20. package/dist/telemetry-utils-beta.d.ts +668 -0
  21. package/dist/telemetry-utils-public.d.ts +668 -0
  22. package/dist/telemetry-utils.d.ts +909 -0
  23. package/dist/telemetryTypes.d.ts +2 -2
  24. package/dist/telemetryTypes.d.ts.map +1 -1
  25. package/dist/tsdoc-metadata.json +1 -1
  26. package/dist/utils.d.ts +45 -0
  27. package/dist/utils.d.ts.map +1 -1
  28. package/dist/utils.js +50 -1
  29. package/dist/utils.js.map +1 -1
  30. package/lib/config.d.ts +1 -1
  31. package/lib/config.d.ts.map +1 -1
  32. package/lib/error.d.ts.map +1 -1
  33. package/lib/error.js +2 -1
  34. package/lib/error.js.map +1 -1
  35. package/lib/errorLogging.js +6 -6
  36. package/lib/errorLogging.js.map +1 -1
  37. package/lib/index.d.ts +1 -1
  38. package/lib/index.d.ts.map +1 -1
  39. package/lib/index.js +1 -1
  40. package/lib/index.js.map +1 -1
  41. package/lib/logger.d.ts +49 -5
  42. package/lib/logger.d.ts.map +1 -1
  43. package/lib/logger.js +88 -34
  44. package/lib/logger.js.map +1 -1
  45. package/lib/telemetryTypes.d.ts +2 -2
  46. package/lib/telemetryTypes.d.ts.map +1 -1
  47. package/lib/utils.d.ts +45 -0
  48. package/lib/utils.d.ts.map +1 -1
  49. package/lib/utils.js +48 -0
  50. package/lib/utils.js.map +1 -1
  51. package/package.json +17 -17
  52. package/src/error.ts +7 -3
  53. package/src/index.ts +1 -1
  54. package/src/logger.ts +74 -6
  55. package/src/utils.ts +85 -0
@@ -1 +1 @@
1
- {"version":3,"file":"errorLogging.js","sourceRoot":"","sources":["../src/errorLogging.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAQH,+BAAkC;AAClC,qDAK0B;AAG1B;;GAEG;AACH,MAAM,eAAe,GAAG,CAAC,KAAc,EAAW,EAAE;IACnD,OAAO,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAC;AAC7E,CAAC,CAAC;AAEF;;;;GAIG;AACH,SAAgB,6BAA6B,CAC5C,KAAc,EACd,aAAsB;IAMtB,MAAM,sBAAsB,GAAG,CAAC,KAAa,EAAE,SAAkB,EAAU,EAAE;QAC5E,IAAI,CAAC,aAAa,EAAE;YACnB,OAAO,KAAK,CAAC;SACb;QACD,MAAM,WAAW,GAAG,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACtC,WAAW,CAAC,KAAK,EAAE,CAAC,CAAC,uCAAuC;QAC5D,IAAI,SAAS,KAAK,SAAS,EAAE;YAC5B,WAAW,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,oBAAoB;SACpD;QACD,OAAO,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC,CAAC;IAEF,MAAM,OAAO,GACZ,OAAQ,KAAwB,EAAE,OAAO,KAAK,QAAQ;QACrD,CAAC,CAAE,KAAe,CAAC,OAAO;Q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O;YACrB,eAAe,EAAE,IAAI,CAAC,gBAAgB;SACtC,CAAC;IACH,CAAC;CACD;AA7ED,oCA6EC;AAED;;;;GAIG;AACU,QAAA,qBAAqB,GAAG,cAAc,CAAC;AAEpD;;;;GAIG;AACH,MAAM,sBAAuB,SAAQ,YAAY;IAKhD,YAAY,UAAsD;QACjE,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QAL3B,2EAA2E;QAC3E,2EAA2E;QAC3E,cAAS,GAAG,6BAAqB,CAAC;QAKjC,IAAI,UAAU,CAAC,KAAK,KAAK,SAAS,EAAE;YACnC,cAAc,CAAC,IAAI,EAAE,UAAU,CAAC,KAAK,CAAC,CAAC;SACvC;IACF,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tILoggingError,\n\tITelemetryBaseProperties,\n\tTelemetryBaseEventPropertyType,\n\tTagged,\n} from \"@fluidframework/core-interfaces\";\nimport { v4 as uuid } from \"uuid\";\nimport {\n\thasErrorInstanceId,\n\tIFluidErrorBase,\n\tisFluidError,\n\tisValidLegacyError,\n} from \"./fluidErrorBase\";\nimport { ITelemetryLoggerExt, TelemetryEventPropertyTypeExt } from \"./telemetryTypes\";\n\n/**\n * Determines if the provided value is an object but neither null nor an array.\n */\nconst isRegularObject = (value: unknown): boolean => {\n\treturn value !== null && !Array.isArray(value) && typeof value === \"object\";\n};\n\n/**\n * Inspect the given error for common \"safe\" props and return them.\n *\n * @internal\n */\nexport function extractLogSafeErrorProperties(\n\terror: unknown,\n\tsanitizeStack: boolean,\n): {\n\tmessage: string;\n\terrorType?: string | undefined;\n\tstack?: string | undefined;\n} {\n\tconst removeMessageFromStack = (stack: string, errorName?: string): string => {\n\t\tif (!sanitizeStack) {\n\t\t\treturn stack;\n\t\t}\n\t\tconst stackFrames = stack.split(\"\\n\");\n\t\tstackFrames.shift(); // Remove \"[ErrorName]: [ErrorMessage]\"\n\t\tif (errorName !== undefined) {\n\t\t\tstackFrames.unshift(errorName); // Add \"[ErrorName]\"\n\t\t}\n\t\treturn stackFrames.join(\"\\n\");\n\t};\n\n\tconst message =\n\t\ttypeof (error as Partial<Error>)?.message === \"string\"\n\t\t\t? (error as Error).message\n\t\t\t: String(error);\n\n\tconst safeProps: { message: string; errorType?: string; stack?: string } = {\n\t\tmessage,\n\t};\n\n\tif (isRegularObject(error)) {\n\t\tconst { errorType, stack, name } = error as Partial<IFluidErrorBase>;\n\n\t\tif (typeof errorType === \"string\") {\n\t\t\tsafeProps.errorType = errorType;\n\t\t}\n\n\t\tif (typeof stack === \"string\") {\n\t\t\tconst errorName = typeof name === \"string\" ? name : undefined;\n\t\t\tsafeProps.stack = removeMessageFromStack(stack, errorName);\n\t\t}\n\t}\n\n\treturn safeProps;\n}\n\n/**\n * type guard for ILoggingError interface\n */\nexport const isILoggingError = (x: unknown): x is ILoggingError =>\n\ttypeof (x as Partial<ILoggingError>)?.getTelemetryProperties === \"function\";\n\n/**\n * Copy props from source onto target, but do not overwrite an existing prop that matches\n */\nfunction copyProps(\n\ttarget: ITelemetryBaseProperties | LoggingError,\n\tsource: ITelemetryBaseProperties,\n): void {\n\tfor (const key of Object.keys(source)) {\n\t\tif (target[key] === undefined) {\n\t\t\ttarget[key] = source[key];\n\t\t}\n\t}\n}\n\n/**\n * Metadata to annotate an error object when annotating or normalizing it\n *\n * @internal\n */\nexport interface IFluidErrorAnnotations {\n\t/**\n\t * Telemetry props to log with the error\n\t */\n\tprops?: ITelemetryBaseProperties;\n}\n\n/**\n * For backwards compatibility with pre-errorInstanceId valid errors\n */\nfunction patchLegacyError(\n\tlegacyError: Omit<IFluidErrorBase, \"errorInstanceId\">,\n): asserts legacyError is IFluidErrorBase {\n\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-explicit-any\n\tconst patchMe: { -readonly [P in \"errorInstanceId\"]?: IFluidErrorBase[P] } = legacyError as any;\n\tif (patchMe.errorInstanceId === undefined) {\n\t\tpatchMe.errorInstanceId = uuid();\n\t}\n}\n\n/**\n * Normalize the given error yielding a valid Fluid Error\n * @returns A valid Fluid Error with any provided annotations applied\n * @param error - The error to normalize\n * @param annotations - Annotations to apply to the normalized error\n *\n * @internal\n */\nexport function normalizeError(\n\terror: unknown,\n\tannotations: IFluidErrorAnnotations = {},\n): IFluidErrorBase {\n\t// Back-compat, while IFluidErrorBase is rolled out\n\tif (isValidLegacyError(error)) {\n\t\tpatchLegacyError(error);\n\t}\n\n\tif (isFluidError(error)) {\n\t\t// We can simply add the telemetry props to the error and return it\n\t\terror.addTelemetryProperties(annotations.props ?? {});\n\t\treturn error;\n\t}\n\n\t// We have to construct a new Fluid Error, copying safe properties over\n\tconst { message, stack } = extractLogSafeErrorProperties(error, false /* sanitizeStack */);\n\tconst fluidError: IFluidErrorBase = new NormalizedLoggingError({\n\t\tmessage,\n\t\tstack,\n\t});\n\n\t// We need to preserve these properties which are used in a non-typesafe way throughout driver code (see #8743)\n\t// Anywhere they are set should be on a valid Fluid Error that would have been returned above,\n\t// but we can't prove it with the types, so adding this defensive measure.\n\tif (typeof error === \"object\" && error !== null) {\n\t\tconst maybeHasRetry: Partial<Record<\"canRetry\" | \"retryAfterSeconds\", unknown>> = error;\n\t\tlet retryProps: Partial<Record<\"canRetry\" | \"retryAfterSeconds\", unknown>> | undefined;\n\t\tif (\"canRetry\" in error) {\n\t\t\tretryProps ??= {};\n\t\t\tretryProps.canRetry = maybeHasRetry.canRetry;\n\t\t}\n\t\tif (\"retryAfterSeconds\" in error) {\n\t\t\tretryProps ??= {};\n\t\t\tretryProps.retryAfterSeconds = maybeHasRetry.retryAfterSeconds;\n\t\t}\n\t\tif (retryProps !== undefined) {\n\t\t\tObject.assign(fluidError, retryProps);\n\t\t}\n\t}\n\n\tif (typeof error !== \"object\") {\n\t\t// This is only interesting for non-objects\n\t\tfluidError.addTelemetryProperties({ typeofError: typeof error });\n\t}\n\n\tconst errorTelemetryProps = LoggingError.typeCheck(error)\n\t\t? error.getTelemetryProperties()\n\t\t: { untrustedOrigin: 1 }; // This will let us filter errors that did not originate from our own codebase\n\n\tfluidError.addTelemetryProperties({\n\t\t...errorTelemetryProps,\n\t\t...annotations.props,\n\t});\n\n\treturn fluidError;\n}\n\nlet stackPopulatedOnCreation: boolean | undefined;\n\n/**\n * The purpose of this function is to provide ability to capture stack context quickly.\n * Accessing new Error().stack is slow, and the slowest part is accessing stack property itself.\n * There are scenarios where we generate error with stack, but error is handled in most cases and\n * stack property is not accessed.\n * For such cases it's better to not read stack property right away, but rather delay it until / if it's needed\n * Some browsers will populate stack right away, others require throwing Error, so we do auto-detection on the fly.\n * @returns Error object that has stack populated.\n *\n * @internal\n */\nexport function generateErrorWithStack(): Error {\n\tconst err = new Error(\"<<generated stack>>\");\n\n\tif (stackPopulatedOnCreation === undefined) {\n\t\tstackPopulatedOnCreation = err.stack !== undefined;\n\t}\n\n\tif (stackPopulatedOnCreation) {\n\t\treturn err;\n\t}\n\n\ttry {\n\t\tthrow err;\n\t} catch (error) {\n\t\treturn error as Error;\n\t}\n}\n\n/**\n * Generate a stack at this callsite as if an error were thrown from here.\n * @returns the callstack (does not throw)\n *\n * @internal\n */\nexport function generateStack(): string | undefined {\n\treturn generateErrorWithStack().stack;\n}\n\n/**\n * Create a new error using newErrorFn, wrapping and caused by the given unknown error.\n * Copies the inner error's stack, errorInstanceId and telemetry props over to the new error if present\n * @param innerError - An error from untrusted/unknown origins\n * @param newErrorFn - callback that will create a new error given the original error's message\n * @returns A new error object \"wrapping\" the given error\n *\n * @internal\n */\nexport function wrapError<T extends LoggingError>(\n\tinnerError: unknown,\n\tnewErrorFn: (message: string) => T,\n): T {\n\tconst { message, stack } = extractLogSafeErrorProperties(innerError, false /* sanitizeStack */);\n\n\tconst newError = newErrorFn(message);\n\n\tif (stack !== undefined) {\n\t\toverwriteStack(newError, stack);\n\t}\n\n\t// Mark external errors with untrustedOrigin flag\n\tif (isExternalError(innerError)) {\n\t\tnewError.addTelemetryProperties({ untrustedOrigin: 1 });\n\t}\n\n\t// Reuse errorInstanceId\n\tif (hasErrorInstanceId(innerError)) {\n\t\tnewError.overwriteErrorInstanceId(innerError.errorInstanceId);\n\n\t\t// For \"back-compat\" in the logs\n\t\tnewError.addTelemetryProperties({ innerErrorInstanceId: innerError.errorInstanceId });\n\t}\n\n\t// Lastly, copy over all other telemetry properties. Note these will not overwrite existing properties\n\t// This will include the untrustedOrigin property if the inner error itself was created from an external error\n\tif (isILoggingError(innerError)) {\n\t\tnewError.addTelemetryProperties(innerError.getTelemetryProperties());\n\t}\n\n\treturn newError;\n}\n\n/**\n * The same as wrapError, but also logs the innerError, including the wrapping error's instance ID.\n *\n * @typeParam T - The kind of wrapper error to create.\n *\n * @internal\n */\nexport function wrapErrorAndLog<T extends LoggingError>(\n\tinnerError: unknown,\n\tnewErrorFn: (message: string) => T,\n\tlogger: ITelemetryLoggerExt,\n): T {\n\tconst newError = wrapError(innerError, newErrorFn);\n\n\t// This will match innerError.errorInstanceId if present (see wrapError)\n\tconst errorInstanceId = newError.errorInstanceId;\n\n\t// For \"back-compat\" in the logs\n\tconst wrappedByErrorInstanceId = errorInstanceId;\n\n\tlogger.sendTelemetryEvent(\n\t\t{\n\t\t\teventName: \"WrapError\",\n\t\t\terrorInstanceId,\n\t\t\twrappedByErrorInstanceId,\n\t\t},\n\t\tinnerError,\n\t);\n\n\treturn newError;\n}\n\n/**\n * Attempts to overwrite the error's stack\n *\n * There have been reports of certain JS environments where overwriting stack will throw.\n * If that happens, this adds the given stack as the telemetry property \"stack2\"\n *\n * @internal\n */\nexport function overwriteStack(error: IFluidErrorBase | LoggingError, stack: string): void {\n\ttry {\n\t\tObject.assign(error, { stack });\n\t} catch {\n\t\terror.addTelemetryProperties({ stack2: stack });\n\t}\n}\n\n/**\n * True for any error object that is an (optionally normalized) external error\n * False for any error we created and raised within the FF codebase via LoggingError base class,\n * or wrapped in a well-known error type\n *\n * @internal\n */\nexport function isExternalError(error: unknown): boolean {\n\t// LoggingErrors are an internal FF error type. However, an external error can be converted\n\t// into a LoggingError if it is normalized. In this case we must use the untrustedOrigin flag to\n\t// determine whether the original error was infact external.\n\tif (LoggingError.typeCheck(error)) {\n\t\tif ((error as NormalizedLoggingError).errorType === NORMALIZED_ERROR_TYPE) {\n\t\t\treturn error.getTelemetryProperties().untrustedOrigin === 1;\n\t\t}\n\t\treturn false;\n\t}\n\treturn !isValidLegacyError(error);\n}\n\n/**\n * Type guard to identify if a particular telemetry property appears to be a tagged telemetry property\n */\nexport function isTaggedTelemetryPropertyValue(\n\tx: Tagged<TelemetryEventPropertyTypeExt> | TelemetryEventPropertyTypeExt,\n): x is Tagged<TelemetryEventPropertyTypeExt> {\n\treturn typeof (x as Partial<Tagged<unknown>>)?.tag === \"string\";\n}\n\n/**\n * Filter serializable telemetry properties\n * @param x - Any telemetry prop\n * @returns As-is if x is primitive. returns stringified if x is an array of primitive.\n * otherwise returns null since this is what we support at the moment.\n */\nfunction filterValidTelemetryProps(x: unknown, key: string): TelemetryBaseEventPropertyType {\n\tif (Array.isArray(x) && x.every((val) => isTelemetryEventPropertyValue(val))) {\n\t\treturn JSON.stringify(x);\n\t}\n\tif (isTelemetryEventPropertyValue(x)) {\n\t\treturn x;\n\t}\n\t// We don't support logging arbitrary objects\n\tconsole.error(`UnSupported Format of Logging Error Property for key ${key}:`, x);\n\treturn \"REDACTED (arbitrary object)\";\n}\n\n// checking type of x, returns false if x is null\nfunction isTelemetryEventPropertyValue(x: unknown): x is TelemetryBaseEventPropertyType {\n\tswitch (typeof x) {\n\t\tcase \"string\":\n\t\tcase \"number\":\n\t\tcase \"boolean\":\n\t\tcase \"undefined\": {\n\t\t\treturn true;\n\t\t}\n\t\tdefault: {\n\t\t\treturn false;\n\t\t}\n\t}\n}\n\n/**\n * Walk an object's enumerable properties to find those fit for telemetry.\n */\nfunction getValidTelemetryProps(obj: object, keysToOmit: Set<string>): ITelemetryBaseProperties {\n\tconst props: ITelemetryBaseProperties = {};\n\tfor (const key of Object.keys(obj)) {\n\t\tif (keysToOmit.has(key)) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst val = obj[key] as\n\t\t\t| TelemetryEventPropertyTypeExt\n\t\t\t| Tagged<TelemetryEventPropertyTypeExt>;\n\n\t\t// ensure only valid props get logged, since props of logging error could be in any shape\n\t\tprops[key] = isTaggedTelemetryPropertyValue(val)\n\t\t\t? {\n\t\t\t\t\tvalue: filterValidTelemetryProps(val.value, key),\n\t\t\t\t\ttag: val.tag,\n\t\t\t }\n\t\t\t: filterValidTelemetryProps(val, key);\n\t}\n\treturn props;\n}\n\n/**\n * Borrowed from\n * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Cyclic_object_value#examples}\n * Avoids runtime errors with circular references.\n * Not ideal, as will cut values that are not necessarily circular references.\n * Could be improved by implementing Node's util.inspect() for browser (minus all the coloring code)\n *\n * @internal\n */\n// TODO: Use `unknown` instead (API breaking change)\n/* eslint-disable @typescript-eslint/no-explicit-any */\nexport const getCircularReplacer = (): ((key: string, value: unknown) => any) => {\n\tconst seen = new WeakSet();\n\treturn (key: string, value: unknown): any => {\n\t\tif (typeof value === \"object\" && value !== null) {\n\t\t\tif (seen.has(value)) {\n\t\t\t\treturn \"<removed/circular>\";\n\t\t\t}\n\t\t\tseen.add(value);\n\t\t}\n\t\treturn value;\n\t};\n};\n/* eslint-enable @typescript-eslint/no-explicit-any */\n\n/**\n * Base class for \"trusted\" errors we create, whose properties can generally be logged to telemetry safely.\n * All properties set on the object, or passed in (via the constructor or addTelemetryProperties),\n * will be logged in accordance with their tag, if present.\n *\n * PLEASE take care to avoid setting sensitive data on this object without proper tagging!\n *\n * @internal\n */\nexport class LoggingError\n\textends Error\n\timplements ILoggingError, Omit<IFluidErrorBase, \"errorType\">\n{\n\tprivate _errorInstanceId = uuid();\n\tget errorInstanceId(): string {\n\t\treturn this._errorInstanceId;\n\t}\n\toverwriteErrorInstanceId(id: string): void {\n\t\tthis._errorInstanceId = id;\n\t}\n\n\t/**\n\t * Backwards compatibility to appease {@link isFluidError} in old code that may handle this error.\n\t */\n\t// @ts-expect-error - This field shouldn't be referenced in the current version, but needs to exist at runtime.\n\t// eslint-disable-next-line @typescript-eslint/prefer-as-const\n\tprivate readonly fluidErrorCode: \"-\" = \"-\";\n\n\t/**\n\t * Create a new LoggingError\n\t * @param message - Error message to use for Error base class\n\t * @param props - telemetry props to include on the error for when it's logged\n\t * @param omitPropsFromLogging - properties by name to omit from telemetry props\n\t */\n\tconstructor(\n\t\tmessage: string,\n\t\tprops?: ITelemetryBaseProperties,\n\t\tprivate readonly omitPropsFromLogging: Set<string> = new Set(),\n\t) {\n\t\tsuper(message);\n\n\t\t// Don't log this list itself, or the private _errorInstanceId\n\t\tomitPropsFromLogging.add(\"omitPropsFromLogging\");\n\t\tomitPropsFromLogging.add(\"_errorInstanceId\");\n\n\t\tif (props) {\n\t\t\tthis.addTelemetryProperties(props);\n\t\t}\n\t}\n\n\t/**\n\t * Determines if a given object is an instance of a LoggingError\n\t * @param object - any object\n\t * @returns true if the object is an instance of a LoggingError, false if not.\n\t */\n\tpublic static typeCheck(object: unknown): object is LoggingError {\n\t\tif (typeof object === \"object\" && object !== null) {\n\t\t\treturn (\n\t\t\t\ttypeof (object as LoggingError).addTelemetryProperties === \"function\" &&\n\t\t\t\ttypeof (object as LoggingError).getTelemetryProperties === \"function\" &&\n\t\t\t\ttypeof (object as LoggingError).errorInstanceId === \"string\"\n\t\t\t);\n\t\t}\n\t\treturn false;\n\t}\n\n\t/**\n\t * Add additional properties to be logged\n\t */\n\tpublic addTelemetryProperties(props: ITelemetryBaseProperties): void {\n\t\tcopyProps(this, props);\n\t}\n\n\t/**\n\t * Get all properties fit to be logged to telemetry for this error\n\t */\n\tpublic getTelemetryProperties(): ITelemetryBaseProperties {\n\t\tconst taggableProps = getValidTelemetryProps(this, this.omitPropsFromLogging);\n\t\t// Include non-enumerable props that are not returned by getValidTelemetryProps\n\t\treturn {\n\t\t\t...taggableProps,\n\t\t\tstack: this.stack,\n\t\t\tmessage: this.message,\n\t\t\terrorInstanceId: this._errorInstanceId,\n\t\t};\n\t}\n}\n\n/**\n * The Error class used when normalizing an external error\n *\n * @internal\n */\nexport const NORMALIZED_ERROR_TYPE = \"genericError\";\n\n/**\n * Subclass of LoggingError returned by normalizeError\n *\n * @internal\n */\nclass NormalizedLoggingError extends LoggingError {\n\t// errorType \"genericError\" is used as a default value throughout the code.\n\t// Note that this matches ContainerErrorType/DriverErrorType's genericError\n\terrorType = NORMALIZED_ERROR_TYPE;\n\n\tconstructor(errorProps: Pick<IFluidErrorBase, \"message\" | \"stack\">) {\n\t\tsuper(errorProps.message);\n\n\t\tif (errorProps.stack !== undefined) {\n\t\t\toverwriteStack(this, errorProps.stack);\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"errorLogging.js","sourceRoot":"","sources":["../src/errorLogging.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAQH,+BAAkC;AAClC,qDAK0B;AAG1B;;GAEG;AACH,MAAM,eAAe,GAAG,CAAC,KAAc,EAAW,EAAE;IACnD,OAAO,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAC;AAC7E,CAAC,CAAC;AAEF;;;;GAIG;AACH,SAAgB,6BAA6B,CAC5C,KAAc,EACd,aAAsB;IAMtB,MAAM,sBAAsB,GAAG,CAAC,KAAa,EAAE,SAAkB,EAAU,EAAE;QAC5E,IAAI,CAAC,aAAa,EAAE;YACnB,OAAO,KAAK,CAAC;SACb;QACD,MAAM,WAAW,GAAG,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACtC,WAAW,CAAC,KAAK,EAAE,CAAC,CAAC,uCAAuC;QAC5D,IAAI,SAAS,KAAK,SAAS,EAAE;YAC5B,WAAW,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,oBAAoB;SACpD;QACD,OA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IAAI,EAAE,IAAI,CAAC,oBAAoB,CAAC,CAAC;QAC9E,+EAA+E;QAC/E,OAAO;YACN,GAAG,aAAa;YAChB,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,eAAe,EAAE,IAAI,CAAC,gBAAgB;SACtC,CAAC;IACH,CAAC;CACD;AA7ED,oCA6EC;AAED;;;;GAIG;AACU,QAAA,qBAAqB,GAAG,cAAc,CAAC;AAEpD;;;;GAIG;AACH,MAAM,sBAAuB,SAAQ,YAAY;IAKhD,YAAY,UAAsD;QACjE,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QAL3B,2EAA2E;QAC3E,2EAA2E;QAC3E,cAAS,GAAG,6BAAqB,CAAC;QAKjC,IAAI,UAAU,CAAC,KAAK,KAAK,SAAS,EAAE;YACnC,cAAc,CAAC,IAAI,EAAE,UAAU,CAAC,KAAK,CAAC,CAAC;SACvC;IACF,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tILoggingError,\n\tITelemetryBaseProperties,\n\tTelemetryBaseEventPropertyType,\n\tTagged,\n} from \"@fluidframework/core-interfaces\";\nimport { v4 as uuid } from \"uuid\";\nimport {\n\thasErrorInstanceId,\n\tIFluidErrorBase,\n\tisFluidError,\n\tisValidLegacyError,\n} from \"./fluidErrorBase\";\nimport { ITelemetryLoggerExt, TelemetryEventPropertyTypeExt } from \"./telemetryTypes\";\n\n/**\n * Determines if the provided value is an object but neither null nor an array.\n */\nconst isRegularObject = (value: unknown): boolean => {\n\treturn value !== null && !Array.isArray(value) && typeof value === \"object\";\n};\n\n/**\n * Inspect the given error for common \"safe\" props and return them.\n *\n * @internal\n */\nexport function extractLogSafeErrorProperties(\n\terror: unknown,\n\tsanitizeStack: boolean,\n): {\n\tmessage: string;\n\terrorType?: string | undefined;\n\tstack?: string | undefined;\n} {\n\tconst removeMessageFromStack = (stack: string, errorName?: string): string => {\n\t\tif (!sanitizeStack) {\n\t\t\treturn stack;\n\t\t}\n\t\tconst stackFrames = stack.split(\"\\n\");\n\t\tstackFrames.shift(); // Remove \"[ErrorName]: [ErrorMessage]\"\n\t\tif (errorName !== undefined) {\n\t\t\tstackFrames.unshift(errorName); // Add \"[ErrorName]\"\n\t\t}\n\t\treturn stackFrames.join(\"\\n\");\n\t};\n\n\tconst message =\n\t\ttypeof (error as Partial<Error>)?.message === \"string\"\n\t\t\t? (error as Error).message\n\t\t\t: String(error);\n\n\tconst safeProps: { message: string; errorType?: string; stack?: string } = {\n\t\tmessage,\n\t};\n\n\tif (isRegularObject(error)) {\n\t\tconst { errorType, stack, name } = error as Partial<IFluidErrorBase>;\n\n\t\tif (typeof errorType === \"string\") {\n\t\t\tsafeProps.errorType = errorType;\n\t\t}\n\n\t\tif (typeof stack === \"string\") {\n\t\t\tconst errorName = typeof name === \"string\" ? name : undefined;\n\t\t\tsafeProps.stack = removeMessageFromStack(stack, errorName);\n\t\t}\n\t}\n\n\treturn safeProps;\n}\n\n/**\n * type guard for ILoggingError interface\n */\nexport const isILoggingError = (x: unknown): x is ILoggingError =>\n\ttypeof (x as Partial<ILoggingError>)?.getTelemetryProperties === \"function\";\n\n/**\n * Copy props from source onto target, but do not overwrite an existing prop that matches\n */\nfunction copyProps(\n\ttarget: ITelemetryBaseProperties | LoggingError,\n\tsource: ITelemetryBaseProperties,\n): void {\n\tfor (const key of Object.keys(source)) {\n\t\tif (target[key] === undefined) {\n\t\t\ttarget[key] = source[key];\n\t\t}\n\t}\n}\n\n/**\n * Metadata to annotate an error object when annotating or normalizing it\n *\n * @internal\n */\nexport interface IFluidErrorAnnotations {\n\t/**\n\t * Telemetry props to log with the error\n\t */\n\tprops?: ITelemetryBaseProperties;\n}\n\n/**\n * For backwards compatibility with pre-errorInstanceId valid errors\n */\nfunction patchLegacyError(\n\tlegacyError: Omit<IFluidErrorBase, \"errorInstanceId\">,\n): asserts legacyError is IFluidErrorBase {\n\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-explicit-any\n\tconst patchMe: { -readonly [P in \"errorInstanceId\"]?: IFluidErrorBase[P] } = legacyError as any;\n\tif (patchMe.errorInstanceId === undefined) {\n\t\tpatchMe.errorInstanceId = uuid();\n\t}\n}\n\n/**\n * Normalize the given error yielding a valid Fluid Error\n * @returns A valid Fluid Error with any provided annotations applied\n * @param error - The error to normalize\n * @param annotations - Annotations to apply to the normalized error\n *\n * @internal\n */\nexport function normalizeError(\n\terror: unknown,\n\tannotations: IFluidErrorAnnotations = {},\n): IFluidErrorBase {\n\t// Back-compat, while IFluidErrorBase is rolled out\n\tif (isValidLegacyError(error)) {\n\t\tpatchLegacyError(error);\n\t}\n\n\tif (isFluidError(error)) {\n\t\t// We can simply add the telemetry props to the error and return it\n\t\terror.addTelemetryProperties(annotations.props ?? {});\n\t\treturn error;\n\t}\n\n\t// We have to construct a new Fluid Error, copying safe properties over\n\tconst { message, stack } = extractLogSafeErrorProperties(error, false /* sanitizeStack */);\n\tconst fluidError: IFluidErrorBase = new NormalizedLoggingError({\n\t\tmessage,\n\t\tstack,\n\t});\n\n\t// We need to preserve these properties which are used in a non-typesafe way throughout driver code (see #8743)\n\t// Anywhere they are set should be on a valid Fluid Error that would have been returned above,\n\t// but we can't prove it with the types, so adding this defensive measure.\n\tif (typeof error === \"object\" && error !== null) {\n\t\tconst maybeHasRetry: Partial<Record<\"canRetry\" | \"retryAfterSeconds\", unknown>> = error;\n\t\tlet retryProps: Partial<Record<\"canRetry\" | \"retryAfterSeconds\", unknown>> | undefined;\n\t\tif (\"canRetry\" in error) {\n\t\t\tretryProps ??= {};\n\t\t\tretryProps.canRetry = maybeHasRetry.canRetry;\n\t\t}\n\t\tif (\"retryAfterSeconds\" in error) {\n\t\t\tretryProps ??= {};\n\t\t\tretryProps.retryAfterSeconds = maybeHasRetry.retryAfterSeconds;\n\t\t}\n\t\tif (retryProps !== undefined) {\n\t\t\tObject.assign(fluidError, retryProps);\n\t\t}\n\t}\n\n\tif (typeof error !== \"object\") {\n\t\t// This is only interesting for non-objects\n\t\tfluidError.addTelemetryProperties({ typeofError: typeof error });\n\t}\n\n\tconst errorTelemetryProps = LoggingError.typeCheck(error)\n\t\t? error.getTelemetryProperties()\n\t\t: { untrustedOrigin: 1 }; // This will let us filter errors that did not originate from our own codebase\n\n\tfluidError.addTelemetryProperties({\n\t\t...errorTelemetryProps,\n\t\t...annotations.props,\n\t});\n\n\treturn fluidError;\n}\n\nlet stackPopulatedOnCreation: boolean | undefined;\n\n/**\n * The purpose of this function is to provide ability to capture stack context quickly.\n * Accessing new Error().stack is slow, and the slowest part is accessing stack property itself.\n * There are scenarios where we generate error with stack, but error is handled in most cases and\n * stack property is not accessed.\n * For such cases it's better to not read stack property right away, but rather delay it until / if it's needed\n * Some browsers will populate stack right away, others require throwing Error, so we do auto-detection on the fly.\n * @returns Error object that has stack populated.\n *\n * @internal\n */\nexport function generateErrorWithStack(): Error {\n\tconst err = new Error(\"<<generated stack>>\");\n\n\tif (stackPopulatedOnCreation === undefined) {\n\t\tstackPopulatedOnCreation = err.stack !== undefined;\n\t}\n\n\tif (stackPopulatedOnCreation) {\n\t\treturn err;\n\t}\n\n\ttry {\n\t\tthrow err;\n\t} catch (error) {\n\t\treturn error as Error;\n\t}\n}\n\n/**\n * Generate a stack at this callsite as if an error were thrown from here.\n * @returns the callstack (does not throw)\n *\n * @internal\n */\nexport function generateStack(): string | undefined {\n\treturn generateErrorWithStack().stack;\n}\n\n/**\n * Create a new error using newErrorFn, wrapping and caused by the given unknown error.\n * Copies the inner error's stack, errorInstanceId and telemetry props over to the new error if present\n * @param innerError - An error from untrusted/unknown origins\n * @param newErrorFn - callback that will create a new error given the original error's message\n * @returns A new error object \"wrapping\" the given error\n *\n * @internal\n */\nexport function wrapError<T extends LoggingError>(\n\tinnerError: unknown,\n\tnewErrorFn: (message: string) => T,\n): T {\n\tconst { message, stack } = extractLogSafeErrorProperties(innerError, false /* sanitizeStack */);\n\n\tconst newError = newErrorFn(message);\n\n\tif (stack !== undefined) {\n\t\toverwriteStack(newError, stack);\n\t}\n\n\t// Mark external errors with untrustedOrigin flag\n\tif (isExternalError(innerError)) {\n\t\tnewError.addTelemetryProperties({ untrustedOrigin: 1 });\n\t}\n\n\t// Reuse errorInstanceId\n\tif (hasErrorInstanceId(innerError)) {\n\t\tnewError.overwriteErrorInstanceId(innerError.errorInstanceId);\n\n\t\t// For \"back-compat\" in the logs\n\t\tnewError.addTelemetryProperties({ innerErrorInstanceId: innerError.errorInstanceId });\n\t}\n\n\t// Lastly, copy over all other telemetry properties. Note these will not overwrite existing properties\n\t// This will include the untrustedOrigin property if the inner error itself was created from an external error\n\tif (isILoggingError(innerError)) {\n\t\tnewError.addTelemetryProperties(innerError.getTelemetryProperties());\n\t}\n\n\treturn newError;\n}\n\n/**\n * The same as wrapError, but also logs the innerError, including the wrapping error's instance ID.\n *\n * @typeParam T - The kind of wrapper error to create.\n *\n * @internal\n */\nexport function wrapErrorAndLog<T extends LoggingError>(\n\tinnerError: unknown,\n\tnewErrorFn: (message: string) => T,\n\tlogger: ITelemetryLoggerExt,\n): T {\n\tconst newError = wrapError(innerError, newErrorFn);\n\n\t// This will match innerError.errorInstanceId if present (see wrapError)\n\tconst errorInstanceId = newError.errorInstanceId;\n\n\t// For \"back-compat\" in the logs\n\tconst wrappedByErrorInstanceId = errorInstanceId;\n\n\tlogger.sendTelemetryEvent(\n\t\t{\n\t\t\teventName: \"WrapError\",\n\t\t\terrorInstanceId,\n\t\t\twrappedByErrorInstanceId,\n\t\t},\n\t\tinnerError,\n\t);\n\n\treturn newError;\n}\n\n/**\n * Attempts to overwrite the error's stack\n *\n * There have been reports of certain JS environments where overwriting stack will throw.\n * If that happens, this adds the given stack as the telemetry property \"stack2\"\n *\n * @internal\n */\nexport function overwriteStack(error: IFluidErrorBase | LoggingError, stack: string): void {\n\ttry {\n\t\tObject.assign(error, { stack });\n\t} catch {\n\t\terror.addTelemetryProperties({ stack2: stack });\n\t}\n}\n\n/**\n * True for any error object that is an (optionally normalized) external error\n * False for any error we created and raised within the FF codebase via LoggingError base class,\n * or wrapped in a well-known error type\n *\n * @internal\n */\nexport function isExternalError(error: unknown): boolean {\n\t// LoggingErrors are an internal FF error type. However, an external error can be converted\n\t// into a LoggingError if it is normalized. In this case we must use the untrustedOrigin flag to\n\t// determine whether the original error was infact external.\n\tif (LoggingError.typeCheck(error)) {\n\t\tif ((error as NormalizedLoggingError).errorType === NORMALIZED_ERROR_TYPE) {\n\t\t\treturn error.getTelemetryProperties().untrustedOrigin === 1;\n\t\t}\n\t\treturn false;\n\t}\n\treturn !isValidLegacyError(error);\n}\n\n/**\n * Type guard to identify if a particular telemetry property appears to be a tagged telemetry property\n */\nexport function isTaggedTelemetryPropertyValue(\n\tx: Tagged<TelemetryEventPropertyTypeExt> | TelemetryEventPropertyTypeExt,\n): x is Tagged<TelemetryEventPropertyTypeExt> {\n\treturn typeof (x as Partial<Tagged<unknown>>)?.tag === \"string\";\n}\n\n/**\n * Filter serializable telemetry properties\n * @param x - Any telemetry prop\n * @returns As-is if x is primitive. returns stringified if x is an array of primitive.\n * otherwise returns null since this is what we support at the moment.\n */\nfunction filterValidTelemetryProps(x: unknown, key: string): TelemetryBaseEventPropertyType {\n\tif (Array.isArray(x) && x.every((val) => isTelemetryEventPropertyValue(val))) {\n\t\treturn JSON.stringify(x);\n\t}\n\tif (isTelemetryEventPropertyValue(x)) {\n\t\treturn x;\n\t}\n\t// We don't support logging arbitrary objects\n\tconsole.error(`UnSupported Format of Logging Error Property for key ${key}:`, x);\n\treturn \"REDACTED (arbitrary object)\";\n}\n\n// checking type of x, returns false if x is null\nfunction isTelemetryEventPropertyValue(x: unknown): x is TelemetryBaseEventPropertyType {\n\tswitch (typeof x) {\n\t\tcase \"string\":\n\t\tcase \"number\":\n\t\tcase \"boolean\":\n\t\tcase \"undefined\": {\n\t\t\treturn true;\n\t\t}\n\t\tdefault: {\n\t\t\treturn false;\n\t\t}\n\t}\n}\n\n/**\n * Walk an object's enumerable properties to find those fit for telemetry.\n */\nfunction getValidTelemetryProps(obj: object, keysToOmit: Set<string>): ITelemetryBaseProperties {\n\tconst props: ITelemetryBaseProperties = {};\n\tfor (const key of Object.keys(obj)) {\n\t\tif (keysToOmit.has(key)) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst val = obj[key] as\n\t\t\t| TelemetryEventPropertyTypeExt\n\t\t\t| Tagged<TelemetryEventPropertyTypeExt>;\n\n\t\t// ensure only valid props get logged, since props of logging error could be in any shape\n\t\tprops[key] = isTaggedTelemetryPropertyValue(val)\n\t\t\t? {\n\t\t\t\t\tvalue: filterValidTelemetryProps(val.value, key),\n\t\t\t\t\ttag: val.tag,\n\t\t\t }\n\t\t\t: filterValidTelemetryProps(val, key);\n\t}\n\treturn props;\n}\n\n/**\n * Borrowed from\n * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Cyclic_object_value#examples}\n * Avoids runtime errors with circular references.\n * Not ideal, as will cut values that are not necessarily circular references.\n * Could be improved by implementing Node's util.inspect() for browser (minus all the coloring code)\n *\n * @internal\n */\n// TODO: Use `unknown` instead (API breaking change)\n/* eslint-disable @typescript-eslint/no-explicit-any */\nexport const getCircularReplacer = (): ((key: string, value: unknown) => any) => {\n\tconst seen = new WeakSet();\n\treturn (key: string, value: unknown): any => {\n\t\tif (typeof value === \"object\" && value !== null) {\n\t\t\tif (seen.has(value)) {\n\t\t\t\treturn \"<removed/circular>\";\n\t\t\t}\n\t\t\tseen.add(value);\n\t\t}\n\t\treturn value;\n\t};\n};\n/* eslint-enable @typescript-eslint/no-explicit-any */\n\n/**\n * Base class for \"trusted\" errors we create, whose properties can generally be logged to telemetry safely.\n * All properties set on the object, or passed in (via the constructor or addTelemetryProperties),\n * will be logged in accordance with their tag, if present.\n *\n * PLEASE take care to avoid setting sensitive data on this object without proper tagging!\n *\n * @internal\n */\nexport class LoggingError\n\textends Error\n\timplements ILoggingError, Omit<IFluidErrorBase, \"errorType\">\n{\n\tprivate _errorInstanceId = uuid();\n\tget errorInstanceId(): string {\n\t\treturn this._errorInstanceId;\n\t}\n\toverwriteErrorInstanceId(id: string): void {\n\t\tthis._errorInstanceId = id;\n\t}\n\n\t/**\n\t * Backwards compatibility to appease {@link isFluidError} in old code that may handle this error.\n\t */\n\t// @ts-expect-error - This field shouldn't be referenced in the current version, but needs to exist at runtime.\n\t// eslint-disable-next-line @typescript-eslint/prefer-as-const\n\tprivate readonly fluidErrorCode: \"-\" = \"-\";\n\n\t/**\n\t * Create a new LoggingError\n\t * @param message - Error message to use for Error base class\n\t * @param props - telemetry props to include on the error for when it's logged\n\t * @param omitPropsFromLogging - properties by name to omit from telemetry props\n\t */\n\tconstructor(\n\t\tmessage: string,\n\t\tprops?: ITelemetryBaseProperties,\n\t\tprivate readonly omitPropsFromLogging: Set<string> = new Set(),\n\t) {\n\t\tsuper(message);\n\n\t\t// Don't log this list itself, or the private _errorInstanceId\n\t\tomitPropsFromLogging.add(\"omitPropsFromLogging\");\n\t\tomitPropsFromLogging.add(\"_errorInstanceId\");\n\n\t\tif (props) {\n\t\t\tthis.addTelemetryProperties(props);\n\t\t}\n\t}\n\n\t/**\n\t * Determines if a given object is an instance of a LoggingError\n\t * @param object - any object\n\t * @returns true if the object is an instance of a LoggingError, false if not.\n\t */\n\tpublic static typeCheck(object: unknown): object is LoggingError {\n\t\tif (typeof object === \"object\" && object !== null) {\n\t\t\treturn (\n\t\t\t\ttypeof (object as LoggingError).addTelemetryProperties === \"function\" &&\n\t\t\t\ttypeof (object as LoggingError).getTelemetryProperties === \"function\" &&\n\t\t\t\ttypeof (object as LoggingError).errorInstanceId === \"string\"\n\t\t\t);\n\t\t}\n\t\treturn false;\n\t}\n\n\t/**\n\t * Add additional properties to be logged\n\t */\n\tpublic addTelemetryProperties(props: ITelemetryBaseProperties): void {\n\t\tcopyProps(this, props);\n\t}\n\n\t/**\n\t * Get all properties fit to be logged to telemetry for this error\n\t */\n\tpublic getTelemetryProperties(): ITelemetryBaseProperties {\n\t\tconst taggableProps = getValidTelemetryProps(this, this.omitPropsFromLogging);\n\t\t// Include non-enumerable props that are not returned by getValidTelemetryProps\n\t\treturn {\n\t\t\t...taggableProps,\n\t\t\tstack: this.stack,\n\t\t\tmessage: this.message,\n\t\t\terrorInstanceId: this._errorInstanceId,\n\t\t};\n\t}\n}\n\n/**\n * The Error class used when normalizing an external error\n *\n * @internal\n */\nexport const NORMALIZED_ERROR_TYPE = \"genericError\";\n\n/**\n * Subclass of LoggingError returned by normalizeError\n *\n * @internal\n */\nclass NormalizedLoggingError extends LoggingError {\n\t// errorType \"genericError\" is used as a default value throughout the code.\n\t// Note that this matches ContainerErrorType/DriverErrorType's genericError\n\terrorType = NORMALIZED_ERROR_TYPE;\n\n\tconstructor(errorProps: Pick<IFluidErrorBase, \"message\" | \"stack\">) {\n\t\tsuper(errorProps.message);\n\n\t\tif (errorProps.stack !== undefined) {\n\t\t\toverwriteStack(this, errorProps.stack);\n\t\t}\n\t}\n}\n"]}
package/dist/index.d.ts CHANGED
@@ -12,6 +12,6 @@ export { eventNamespaceSeparator, createChildLogger, createMultiSinkLogger, form
12
12
  export { MockLogger } from "./mockLogger";
13
13
  export { ThresholdCounter } from "./thresholdCounter";
14
14
  export { SampledTelemetryHelper } from "./sampledTelemetryHelper";
15
- export { logIfFalse } from "./utils";
15
+ export { logIfFalse, createSampledLogger, IEventSampler, ISampledTelemetryLogger } from "./utils";
16
16
  export { TelemetryEventPropertyTypeExt, ITelemetryEventExt, ITelemetryGenericEventExt, ITelemetryErrorEventExt, ITelemetryPerformanceEventExt, ITelemetryLoggerExt, ITaggedTelemetryPropertyTypeExt, ITelemetryPropertiesExt, TelemetryEventCategory, } from "./telemetryTypes";
17
17
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;A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,mBAAmB,EACnB,+BAA+B,EAC/B,uBAAuB,EACvB,sBAAsB,GACtB,MAAM,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EACN,4BAA4B,EAC5B,iBAAiB,EACjB,mBAAmB,EACnB,4BAA4B,EAC5B,sBAAsB,EACtB,eAAe,EACf,WAAW,EACX,yBAAyB,GACzB,MAAM,UAAU,CAAC;AAClB,OAAO,EACN,mBAAmB,EACnB,mBAAmB,EACnB,gCAAgC,EAChC,YAAY,EACZ,UAAU,GACV,MAAM,SAAS,CAAC;AACjB,OAAO,EACN,6BAA6B,EAC7B,sBAAsB,EACtB,aAAa,EACb,mBAAmB,EACnB,sBAAsB,EACtB,eAAe,EACf,eAAe,EACf,8BAA8B,EAC9B,YAAY,EACZ,qBAAqB,EACrB,cAAc,EACd,cAAc,EACd,SAAS,EACT,eAAe,GACf,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAChF,OAAO,EACN,kBAAkB,EAClB,qBAAqB,EACrB,mBAAmB,EACnB,cAAc,GACd,MAAM,UAAU,CAAC;AAClB,OAAO,EACN,kBAAkB,EAClB,eAAe,EACf,YAAY,EACZ,kBAAkB,GAClB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACN,uBAAuB,EACvB,iBAAiB,EACjB,qBAAqB,EACrB,UAAU,EACV,wBAAwB,EACxB,2BAA2B,EAC3B,4BAA4B,EAC5B,gBAAgB,EAChB,gBAAgB,EAChB,mBAAmB,EACnB,OAAO,EACP,gBAAgB,EAChB,gBAAgB,EAChB,2BAA2B,EAC3B,mBAAmB,GACnB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,aAAa,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAClG,OAAO,EACN,6BAA6B,EAC7B,kBAAkB,EAClB,yBAAyB,EACzB,uBAAuB,EACvB,6BAA6B,EAC7B,mBAAmB,EACnB,+BAA+B,EAC/B,uBAAuB,EACvB,sBAAsB,GACtB,MAAM,kBAAkB,CAAC"}
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.logIfFalse = exports.SampledTelemetryHelper = exports.ThresholdCounter = exports.MockLogger = exports.TelemetryNullLogger = exports.TelemetryDataTag = exports.tagCodeArtifacts = exports.tagData = exports.TaggedLoggerAdapter = exports.PerformanceEvent = exports.numberFromString = exports.formatTick = exports.createMultiSinkLogger = exports.createChildLogger = exports.eventNamespaceSeparator = exports.isValidLegacyError = exports.isFluidError = exports.hasErrorInstanceId = exports.safeRaiseEvent = exports.raiseConnectedEvent = exports.disconnectedEventName = exports.connectedEventName = exports.EventEmitterWithErrorHandling = exports.wrapErrorAndLog = exports.wrapError = exports.overwriteStack = exports.normalizeError = exports.NORMALIZED_ERROR_TYPE = exports.LoggingError = exports.isTaggedTelemetryPropertyValue = exports.isILoggingError = exports.isExternalError = exports.getCircularReplacer = exports.generateStack = exports.generateErrorWithStack = exports.extractLogSafeErrorProperties = exports.UsageError = exports.GenericError = exports.extractSafePropertiesFromMessage = exports.DataProcessingError = exports.DataCorruptionError = exports.loggerToMonitoringContext = exports.mixinMonitoringContext = exports.sessionStorageConfigProvider = exports.createChildMonitoringContext = void 0;
3
+ exports.createSampledLogger = exports.logIfFalse = exports.SampledTelemetryHelper = exports.ThresholdCounter = exports.MockLogger = exports.TelemetryNullLogger = exports.TelemetryDataTag = exports.tagCodeArtifacts = exports.tagData = exports.TaggedLoggerAdapter = exports.PerformanceEvent = exports.numberFromString = exports.formatTick = exports.createMultiSinkLogger = exports.createChildLogger = exports.eventNamespaceSeparator = exports.isValidLegacyError = exports.isFluidError = exports.hasErrorInstanceId = exports.safeRaiseEvent = exports.raiseConnectedEvent = exports.disconnectedEventName = exports.connectedEventName = exports.EventEmitterWithErrorHandling = exports.wrapErrorAndLog = exports.wrapError = exports.overwriteStack = exports.normalizeError = exports.NORMALIZED_ERROR_TYPE = exports.LoggingError = exports.isTaggedTelemetryPropertyValue = exports.isILoggingError = exports.isExternalError = exports.getCircularReplacer = exports.generateStack = exports.generateErrorWithStack = exports.extractLogSafeErrorProperties = exports.UsageError = exports.GenericError = exports.extractSafePropertiesFromMessage = exports.DataProcessingError = exports.DataCorruptionError = exports.loggerToMonitoringContext = exports.mixinMonitoringContext = exports.sessionStorageConfigProvider = exports.createChildMonitoringContext = void 0;
4
4
  /*!
5
5
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
6
6
  * Licensed under the MIT License.
@@ -61,4 +61,5 @@ var sampledTelemetryHelper_1 = require("./sampledTelemetryHelper");
61
61
  Object.defineProperty(exports, "SampledTelemetryHelper", { enumerable: true, get: function () { return sampledTelemetryHelper_1.SampledTelemetryHelper; } });
62
62
  var utils_1 = require("./utils");
63
63
  Object.defineProperty(exports, "logIfFalse", { enumerable: true, get: function () { return utils_1.logIfFalse; } });
64
+ Object.defineProperty(exports, "createSampledLogger", { enumerable: true, get: function () { return utils_1.createSampledLogger; } });
64
65
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,mCASkB;AARjB,sHAAA,4BAA4B,OAAA;AAG5B,sHAAA,4BAA4B,OAAA;AAC5B,gHAAA,sBAAsB,OAAA;AAGtB,mHAAA,yBAAyB,OAAA;AAE1B,iCAMiB;AALhB,4GAAA,mBAAmB,OAAA;AACnB,4GAAA,mBAAmB,OAAA;AACnB,yHAAA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MIT License.\n */\nexport {\n\tcreateChildMonitoringContext,\n\tMonitoringContext,\n\tIConfigProviderBase,\n\tsessionStorageConfigProvider,\n\tmixinMonitoringContext,\n\tIConfigProvider,\n\tConfigTypes,\n\tloggerToMonitoringContext,\n} from \"./config\";\nexport {\n\tDataCorruptionError,\n\tDataProcessingError,\n\textractSafePropertiesFromMessage,\n\tGenericError,\n\tUsageError,\n} from \"./error\";\nexport {\n\textractLogSafeErrorProperties,\n\tgenerateErrorWithStack,\n\tgenerateStack,\n\tgetCircularReplacer,\n\tIFluidErrorAnnotations,\n\tisExternalError,\n\tisILoggingError,\n\tisTaggedTelemetryPropertyValue,\n\tLoggingError,\n\tNORMALIZED_ERROR_TYPE,\n\tnormalizeError,\n\toverwriteStack,\n\twrapError,\n\twrapErrorAndLog,\n} from \"./errorLogging\";\nexport { EventEmitterWithErrorHandling } from \"./eventEmitterWithErrorHandling\";\nexport {\n\tconnectedEventName,\n\tdisconnectedEventName,\n\traiseConnectedEvent,\n\tsafeRaiseEvent,\n} from \"./events\";\nexport {\n\thasErrorInstanceId,\n\tIFluidErrorBase,\n\tisFluidError,\n\tisValidLegacyError,\n} from \"./fluidErrorBase\";\nexport {\n\teventNamespaceSeparator,\n\tcreateChildLogger,\n\tcreateMultiSinkLogger,\n\tformatTick,\n\tIPerformanceEventMarkers,\n\tITelemetryLoggerPropertyBag,\n\tITelemetryLoggerPropertyBags,\n\tnumberFromString,\n\tPerformanceEvent,\n\tTaggedLoggerAdapter,\n\ttagData,\n\ttagCodeArtifacts,\n\tTelemetryDataTag,\n\tTelemetryEventPropertyTypes,\n\tTelemetryNullLogger,\n} from \"./logger\";\nexport { MockLogger } from \"./mockLogger\";\nexport { ThresholdCounter } from \"./thresholdCounter\";\nexport { SampledTelemetryHelper } from \"./sampledTelemetryHelper\";\nexport { logIfFalse } from \"./utils\";\nexport {\n\tTelemetryEventPropertyTypeExt,\n\tITelemetryEventExt,\n\tITelemetryGenericEventExt,\n\tITelemetryErrorEventExt,\n\tITelemetryPerformanceEventExt,\n\tITelemetryLoggerExt,\n\tITaggedTelemetryPropertyTypeExt,\n\tITelemetryPropertiesExt,\n\tTelemetryEventCategory,\n} from \"./telemetryTypes\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,mCASkB;AARjB,sHAAA,4BAA4B,OAAA;AAG5B,sHAAA,4BAA4B,OAAA;AAC5B,gHAAA,sBAAsB,OAAA;AAGtB,mHAAA,yBAAyB,OAAA;AAE1B,iCAMiB;AALhB,4GAAA,mBAAmB,OAAA;AACnB,4GAAA,mBAAmB,OAAA;AACnB,yHAAA,gCAAgC,OAAA;AAChC,qGAAA,YAAY,OAAA;AACZ,mGAAA,UAAU,OAAA;AAEX,+CAewB;AAdvB,6HAAA,6BAA6B,OAAA;AAC7B,sHAAA,sBAAsB,OAAA;AACtB,6GAAA,aAAa,OAAA;AACb,mHAAA,mBAAmB,OAAA;AAEnB,+GAAA,eAAe,OAAA;AACf,+GAAA,eAAe,OAAA;AACf,8HAAA,8BAA8B,OAAA;AAC9B,4GAAA,YAAY,OAAA;AACZ,qHAAA,qBAAqB,OAAA;AACrB,8GAAA,cAAc,OAAA;AACd,8GAAA,cAAc,OAAA;AACd,yGAAA,SAAS,OAAA;AACT,+GAAA,eAAe,OAAA;AAEhB,iFAAgF;AAAvE,8IAAA,6BAA6B,OAAA;AACtC,mCAKkB;AAJjB,4GAAA,kBAAkB,OAAA;AAClB,+GAAA,qBAAqB,OAAA;AACrB,6GAAA,mBAAmB,OAAA;AACnB,wGAAA,cAAc,OAAA;AAEf,mDAK0B;AAJzB,oHAAA,kBAAkB,OAAA;AAElB,8GAAA,YAAY,OAAA;AACZ,oHAAA,kBAAkB,OAAA;AAEnB,mCAgBkB;AAfjB,iHAAA,uBAAuB,OAAA;AACvB,2GAAA,iBAAiB,OAAA;AACjB,+GAAA,qBAAqB,OAAA;AACrB,oGAAA,UAAU,OAAA;AAIV,0GAAA,gBAAgB,OAAA;AAChB,0GAAA,gBAAgB,OAAA;AAChB,6GAAA,mBAAmB,OAAA;AACnB,iGAAA,OAAO,OAAA;AACP,0GAAA,gBAAgB,OAAA;AAChB,0GAAA,gBAAgB,OAAA;AAEhB,6GAAA,mBAAmB,OAAA;AAEpB,2CAA0C;AAAjC,wGAAA,UAAU,OAAA;AACnB,uDAAsD;AAA7C,oHAAA,gBAAgB,OAAA;AACzB,mEAAkE;AAAzD,gIAAA,sBAAsB,OAAA;AAC/B,iCAAkG;AAAzF,mGAAA,UAAU,OAAA;AAAE,4GAAA,mBAAmB,OAAA","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nexport {\n\tcreateChildMonitoringContext,\n\tMonitoringContext,\n\tIConfigProviderBase,\n\tsessionStorageConfigProvider,\n\tmixinMonitoringContext,\n\tIConfigProvider,\n\tConfigTypes,\n\tloggerToMonitoringContext,\n} from \"./config\";\nexport {\n\tDataCorruptionError,\n\tDataProcessingError,\n\textractSafePropertiesFromMessage,\n\tGenericError,\n\tUsageError,\n} from \"./error\";\nexport {\n\textractLogSafeErrorProperties,\n\tgenerateErrorWithStack,\n\tgenerateStack,\n\tgetCircularReplacer,\n\tIFluidErrorAnnotations,\n\tisExternalError,\n\tisILoggingError,\n\tisTaggedTelemetryPropertyValue,\n\tLoggingError,\n\tNORMALIZED_ERROR_TYPE,\n\tnormalizeError,\n\toverwriteStack,\n\twrapError,\n\twrapErrorAndLog,\n} from \"./errorLogging\";\nexport { EventEmitterWithErrorHandling } from \"./eventEmitterWithErrorHandling\";\nexport {\n\tconnectedEventName,\n\tdisconnectedEventName,\n\traiseConnectedEvent,\n\tsafeRaiseEvent,\n} from \"./events\";\nexport {\n\thasErrorInstanceId,\n\tIFluidErrorBase,\n\tisFluidError,\n\tisValidLegacyError,\n} from \"./fluidErrorBase\";\nexport {\n\teventNamespaceSeparator,\n\tcreateChildLogger,\n\tcreateMultiSinkLogger,\n\tformatTick,\n\tIPerformanceEventMarkers,\n\tITelemetryLoggerPropertyBag,\n\tITelemetryLoggerPropertyBags,\n\tnumberFromString,\n\tPerformanceEvent,\n\tTaggedLoggerAdapter,\n\ttagData,\n\ttagCodeArtifacts,\n\tTelemetryDataTag,\n\tTelemetryEventPropertyTypes,\n\tTelemetryNullLogger,\n} from \"./logger\";\nexport { MockLogger } from \"./mockLogger\";\nexport { ThresholdCounter } from \"./thresholdCounter\";\nexport { SampledTelemetryHelper } from \"./sampledTelemetryHelper\";\nexport { logIfFalse, createSampledLogger, IEventSampler, ISampledTelemetryLogger } from \"./utils\";\nexport {\n\tTelemetryEventPropertyTypeExt,\n\tITelemetryEventExt,\n\tITelemetryGenericEventExt,\n\tITelemetryErrorEventExt,\n\tITelemetryPerformanceEventExt,\n\tITelemetryLoggerExt,\n\tITaggedTelemetryPropertyTypeExt,\n\tITelemetryPropertiesExt,\n\tTelemetryEventCategory,\n} from \"./telemetryTypes\";\n"]}
package/dist/logger.d.ts CHANGED
@@ -25,7 +25,7 @@ export declare enum TelemetryDataTag {
25
25
  */
26
26
  UserData = "UserData"
27
27
  }
28
- export declare type TelemetryEventPropertyTypes = ITelemetryBaseProperties[string];
28
+ export type TelemetryEventPropertyTypes = ITelemetryBaseProperties[string];
29
29
  export interface ITelemetryLoggerPropertyBag {
30
30
  [index: string]: TelemetryEventPropertyTypes | (() => TelemetryEventPropertyTypes);
31
31
  }
@@ -213,15 +213,57 @@ export declare class PerformanceEvent {
213
213
  private readonly logger;
214
214
  private readonly markers;
215
215
  private readonly recordHeapSize;
216
- static start(logger: ITelemetryLoggerExt, event: ITelemetryGenericEvent, markers?: IPerformanceEventMarkers, recordHeapSize?: boolean): PerformanceEvent;
217
- static timedExec<T>(logger: ITelemetryLoggerExt, event: ITelemetryGenericEvent, callback: (event: PerformanceEvent) => T, markers?: IPerformanceEventMarkers): T;
218
- static timedExecAsync<T>(logger: ITelemetryLoggerExt, event: ITelemetryGenericEvent, callback: (event: PerformanceEvent) => Promise<T>, markers?: IPerformanceEventMarkers, recordHeapSize?: boolean): Promise<T>;
216
+ private readonly emitLogs;
217
+ /**
218
+ * Creates an instance of {@link PerformanceEvent} and starts measurements
219
+ * @param logger - the logger to be used for publishing events
220
+ * @param event - the logging event details which will be published with the performance measurements
221
+ * @param markers - See {@link IPerformanceEventMarkers}
222
+ * @param recordHeapSize - whether or not to also record memory performance
223
+ * @param emitLogs - should this instance emit logs. If set to false, logs will not be emitted to the logger,
224
+ * but measurements will still be performed and any specified markers will be generated.
225
+ * @returns An instance of {@link PerformanceEvent}
226
+ */
227
+ static start(logger: ITelemetryLoggerExt, event: ITelemetryGenericEvent, markers?: IPerformanceEventMarkers, recordHeapSize?: boolean, emitLogs?: boolean): PerformanceEvent;
228
+ /**
229
+ * Measure a synchronous task
230
+ * @param logger - the logger to be used for publishing events
231
+ * @param event - the logging event details which will be published with the performance measurements
232
+ * @param callback - the task to be executed and measured
233
+ * @param markers - See {@link IPerformanceEventMarkers}
234
+ * @param sampleThreshold - events with the same name and category will be sent to the logger
235
+ * only when we hit this many executions of the task. If unspecified, all events will be sent.
236
+ * @returns The results of the executed task
237
+ *
238
+ * @remarks Note that if the "same" event (category + eventName) would be emitted by different
239
+ * tasks (`callback`), `sampleThreshold` is still applied only based on the event's category + eventName,
240
+ * so executing either of the tasks will increase the internal counter and they
241
+ * effectively "share" the sampling rate for the event.
242
+ */
243
+ static timedExec<T>(logger: ITelemetryLoggerExt, event: ITelemetryGenericEvent, callback: (event: PerformanceEvent) => T, markers?: IPerformanceEventMarkers, sampleThreshold?: number): T;
244
+ /**
245
+ * Measure an asynchronous task
246
+ * @param logger - the logger to be used for publishing events
247
+ * @param event - the logging event details which will be published with the performance measurements
248
+ * @param callback - the task to be executed and measured
249
+ * @param markers - See {@link IPerformanceEventMarkers}
250
+ * @param recordHeapSize - whether or not to also record memory performance
251
+ * @param sampleThreshold - events with the same name and category will be sent to the logger
252
+ * only when we hit this many executions of the task. If unspecified, all events will be sent.
253
+ * @returns The results of the executed task
254
+ *
255
+ * @remarks Note that if the "same" event (category + eventName) would be emitted by different
256
+ * tasks (`callback`), `sampleThreshold` is still applied only based on the event's category + eventName,
257
+ * so executing either of the tasks will increase the internal counter and they
258
+ * effectively "share" the sampling rate for the event.
259
+ */
260
+ static timedExecAsync<T>(logger: ITelemetryLoggerExt, event: ITelemetryGenericEvent, callback: (event: PerformanceEvent) => Promise<T>, markers?: IPerformanceEventMarkers, recordHeapSize?: boolean, sampleThreshold?: number): Promise<T>;
219
261
  get duration(): number;
220
262
  private event?;
221
263
  private readonly startTime;
222
264
  private startMark?;
223
265
  private startMemoryCollection;
224
- protected constructor(logger: ITelemetryLoggerExt, event: ITelemetryGenericEvent, markers?: IPerformanceEventMarkers, recordHeapSize?: boolean);
266
+ protected constructor(logger: ITelemetryLoggerExt, event: ITelemetryGenericEvent, markers?: IPerformanceEventMarkers, recordHeapSize?: boolean, emitLogs?: boolean);
225
267
  reportProgress(props?: ITelemetryProperties, eventNameSuffix?: string): void;
226
268
  private autoEnd;
227
269
  end(props?: ITelemetryProperties): void;
@@ -231,6 +273,8 @@ export declare class PerformanceEvent {
231
273
  * Report the event, if it hasn't already been reported.
232
274
  */
233
275
  reportEvent(eventNameSuffix: string, props?: ITelemetryProperties, error?: unknown): void;
276
+ private static readonly eventHits;
277
+ private static shouldReport;
234
278
  }
235
279
  /**
236
280
  * Null logger that no-ops for all telemetry events passed to it.
@@ -1 +1 @@
1
- {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,mBAAmB,EACnB,oBAAoB,EACpB,oBAAoB,EACpB,sBAAsB,EACtB,0BAA0B,EAC1B,oBAAoB,EACpB,8BAA8B,IAAI,0BAA0B,EAC5D,QAAQ,EACR,MAAM,EACN,wBAAwB,EACxB,8BAA8B,EAC9B,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,qBAAqB,EA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I;IAClE,oBAAoB,CAAC,KAAK,EAAE,0BAA0B,EAAE,KAAK,CAAC,EAAE,OAAO,GAAG,IAAI;CACrF;AAmBD;;;;;;;;GAQG;AACH,wBAAgB,yBAAyB,CACxC,CAAC,EAAE,6BAA6B,GAAG,MAAM,CAAC,6BAA6B,CAAC,GACtE,0BAA0B,GAAG,MAAM,CAAC,0BAA0B,CAAC,CAOjE;AA0BD,eAAO,MAAM,OAAO,sIAIsB,8BAA8B,gEAOhD,8BAA8B;;;;;;oDA4BhB,CAAC;AAEvC;;;GAGG;AACH,eAAO,MAAM,gBAAgB,0GAGa,8BAA8B,wDAMhD,8BAA8B;;SAG3C,iBAAiB,YAAY;;;SAI7B,iBAAiB,YAAY;oDAG6C,CAAC"}
package/dist/logger.js CHANGED
@@ -23,7 +23,7 @@ var TelemetryDataTag;
23
23
  * Personal data of a variety of classifications that pertains to the user
24
24
  */
25
25
  TelemetryDataTag["UserData"] = "UserData";
26
- })(TelemetryDataTag = exports.TelemetryDataTag || (exports.TelemetryDataTag = {}));
26
+ })(TelemetryDataTag || (exports.TelemetryDataTag = TelemetryDataTag = {}));
27
27
  /**
28
28
  * Attempts to parse number from string.
29
29
  * If fails,returns original string.
@@ -50,10 +50,6 @@ exports.eventNamespaceSeparator = ":";
50
50
  * Creates sub-logger that appends properties to all events
51
51
  */
52
52
  class TelemetryLogger {
53
- constructor(namespace, properties) {
54
- this.namespace = namespace;
55
- this.properties = properties;
56
- }
57
53
  static sanitizePkgName(name) {
58
54
  return name.replace("@", "").replace("/", "-");
59
55
  }
@@ -86,6 +82,10 @@ class TelemetryLogger {
86
82
  event.stack = (0, errorLogging_1.generateStack)();
87
83
  }
88
84
  }
85
+ constructor(namespace, properties) {
86
+ this.namespace = namespace;
87
+ this.properties = properties;
88
+ }
89
89
  /**
90
90
  * Send a telemetry event with the logger
91
91
  *
@@ -254,14 +254,6 @@ exports.createChildLogger = createChildLogger;
254
254
  * Creates sub-logger that appends properties to all events
255
255
  */
256
256
  class ChildLogger extends TelemetryLogger {
257
- constructor(baseLogger, namespace, properties) {
258
- super(namespace, properties);
259
- this.baseLogger = baseLogger;
260
- // propagate the monitoring context
261
- if ((0, config_1.loggerIsMonitoringContext)(baseLogger)) {
262
- (0, config_1.mixinMonitoringContext)(this, new config_1.CachedConfigProvider(this, baseLogger.config));
263
- }
264
- }
265
257
  /**
266
258
  * Create child logger
267
259
  * @param baseLogger - Base logger to use to output events. If undefined, proper child logger
@@ -303,6 +295,14 @@ class ChildLogger extends TelemetryLogger {
303
295
  }
304
296
  return new ChildLogger(baseLogger ?? { send() { } }, namespace, properties);
305
297
  }
298
+ constructor(baseLogger, namespace, properties) {
299
+ super(namespace, properties);
300
+ this.baseLogger = baseLogger;
301
+ // propagate the monitoring context
302
+ if ((0, config_1.loggerIsMonitoringContext)(baseLogger)) {
303
+ (0, config_1.mixinMonitoringContext)(this, new config_1.CachedConfigProvider(this, baseLogger.config));
304
+ }
305
+ }
306
306
  get minLogLevel() {
307
307
  return this.baseLogger.minLogLevel;
308
308
  }
@@ -407,26 +407,37 @@ exports.MultiSinkLogger = MultiSinkLogger;
407
407
  * Helper class to log performance events
408
408
  */
409
409
  class PerformanceEvent {
410
- constructor(logger, event, markers = { end: true, cancel: "generic" }, recordHeapSize = false) {
411
- this.logger = logger;
412
- this.markers = markers;
413
- this.recordHeapSize = recordHeapSize;
414
- this.startTime = client_utils_1.performance.now();
415
- this.startMemoryCollection = 0;
416
- this.event = { ...event };
417
- if (this.markers.start) {
418
- this.reportEvent("start");
419
- }
420
- if (typeof window === "object" && window?.performance?.mark) {
421
- this.startMark = `${event.eventName}-start`;
422
- window.performance.mark(this.startMark);
423
- }
424
- }
425
- static start(logger, event, markers, recordHeapSize = false) {
426
- return new PerformanceEvent(logger, event, markers, recordHeapSize);
410
+ /**
411
+ * Creates an instance of {@link PerformanceEvent} and starts measurements
412
+ * @param logger - the logger to be used for publishing events
413
+ * @param event - the logging event details which will be published with the performance measurements
414
+ * @param markers - See {@link IPerformanceEventMarkers}
415
+ * @param recordHeapSize - whether or not to also record memory performance
416
+ * @param emitLogs - should this instance emit logs. If set to false, logs will not be emitted to the logger,
417
+ * but measurements will still be performed and any specified markers will be generated.
418
+ * @returns An instance of {@link PerformanceEvent}
419
+ */
420
+ static start(logger, event, markers, recordHeapSize = false, emitLogs = true) {
421
+ return new PerformanceEvent(logger, event, markers, recordHeapSize, emitLogs);
427
422
  }
428
- static timedExec(logger, event, callback, markers) {
429
- const perfEvent = PerformanceEvent.start(logger, event, markers);
423
+ /**
424
+ * Measure a synchronous task
425
+ * @param logger - the logger to be used for publishing events
426
+ * @param event - the logging event details which will be published with the performance measurements
427
+ * @param callback - the task to be executed and measured
428
+ * @param markers - See {@link IPerformanceEventMarkers}
429
+ * @param sampleThreshold - events with the same name and category will be sent to the logger
430
+ * only when we hit this many executions of the task. If unspecified, all events will be sent.
431
+ * @returns The results of the executed task
432
+ *
433
+ * @remarks Note that if the "same" event (category + eventName) would be emitted by different
434
+ * tasks (`callback`), `sampleThreshold` is still applied only based on the event's category + eventName,
435
+ * so executing either of the tasks will increase the internal counter and they
436
+ * effectively "share" the sampling rate for the event.
437
+ */
438
+ static timedExec(logger, event, callback, markers, sampleThreshold = 1) {
439
+ const perfEvent = PerformanceEvent.start(logger, event, markers, undefined, // recordHeapSize
440
+ PerformanceEvent.shouldReport(event, sampleThreshold));
430
441
  try {
431
442
  const ret = callback(perfEvent);
432
443
  perfEvent.autoEnd();
@@ -437,8 +448,24 @@ class PerformanceEvent {
437
448
  throw error;
438
449
  }
439
450
  }
440
- static async timedExecAsync(logger, event, callback, markers, recordHeapSize) {
441
- const perfEvent = PerformanceEvent.start(logger, event, markers, recordHeapSize);
451
+ /**
452
+ * Measure an asynchronous task
453
+ * @param logger - the logger to be used for publishing events
454
+ * @param event - the logging event details which will be published with the performance measurements
455
+ * @param callback - the task to be executed and measured
456
+ * @param markers - See {@link IPerformanceEventMarkers}
457
+ * @param recordHeapSize - whether or not to also record memory performance
458
+ * @param sampleThreshold - events with the same name and category will be sent to the logger
459
+ * only when we hit this many executions of the task. If unspecified, all events will be sent.
460
+ * @returns The results of the executed task
461
+ *
462
+ * @remarks Note that if the "same" event (category + eventName) would be emitted by different
463
+ * tasks (`callback`), `sampleThreshold` is still applied only based on the event's category + eventName,
464
+ * so executing either of the tasks will increase the internal counter and they
465
+ * effectively "share" the sampling rate for the event.
466
+ */
467
+ static async timedExecAsync(logger, event, callback, markers, recordHeapSize, sampleThreshold = 1) {
468
+ const perfEvent = PerformanceEvent.start(logger, event, markers, recordHeapSize, PerformanceEvent.shouldReport(event, sampleThreshold));
442
469
  try {
443
470
  const ret = await callback(perfEvent);
444
471
  perfEvent.autoEnd();
@@ -452,6 +479,22 @@ class PerformanceEvent {
452
479
  get duration() {
453
480
  return client_utils_1.performance.now() - this.startTime;
454
481
  }
482
+ constructor(logger, event, markers = { end: true, cancel: "generic" }, recordHeapSize = false, emitLogs = true) {
483
+ this.logger = logger;
484
+ this.markers = markers;
485
+ this.recordHeapSize = recordHeapSize;
486
+ this.emitLogs = emitLogs;
487
+ this.startTime = client_utils_1.performance.now();
488
+ this.startMemoryCollection = 0;
489
+ this.event = { ...event };
490
+ if (this.markers.start) {
491
+ this.reportEvent("start");
492
+ }
493
+ if (typeof window === "object" && window?.performance?.mark) {
494
+ this.startMark = `${event.eventName}-start`;
495
+ window.performance.mark(this.startMark);
496
+ }
497
+ }
455
498
  reportProgress(props, eventNameSuffix = "update") {
456
499
  this.reportEvent(eventNameSuffix, props);
457
500
  }
@@ -492,6 +535,9 @@ class PerformanceEvent {
492
535
  if (!this.event) {
493
536
  return;
494
537
  }
538
+ if (!this.emitLogs) {
539
+ return;
540
+ }
495
541
  const event = { ...this.event, ...props };
496
542
  event.eventName = `${event.eventName}_${eventNameSuffix}`;
497
543
  if (eventNameSuffix !== "start") {
@@ -506,12 +552,20 @@ class PerformanceEvent {
506
552
  }
507
553
  }
508
554
  else if (this.recordHeapSize) {
509
- this.startMemoryCollection = client_utils_1.performance?.memory?.usedJSHeapSize;
555
+ this.startMemoryCollection = client_utils_1.performance?.memory
556
+ ?.usedJSHeapSize;
510
557
  }
511
558
  this.logger.sendPerformanceEvent(event, error);
512
559
  }
560
+ static shouldReport(event, sampleThreshold) {
561
+ const eventKey = `.${event.category}.${event.eventName}`;
562
+ const hitCount = PerformanceEvent.eventHits.get(eventKey) ?? 0;
563
+ PerformanceEvent.eventHits.set(eventKey, hitCount >= sampleThreshold ? 1 : hitCount + 1);
564
+ return hitCount % sampleThreshold === 0;
565
+ }
513
566
  }
514
567
  exports.PerformanceEvent = PerformanceEvent;
568
+ PerformanceEvent.eventHits = new Map();
515
569
  /**
516
570
  * Null logger that no-ops for all telemetry events passed to it.
517
571
  * @deprecated - This will be removed in a future release.