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

Reduce coupling to TelemetryLogger #16464

Merged

Conversation

anthony-murphy
Copy link
Contributor

In a previous PR I deprecated the telemetry logger implementation. This change further decouple existing code from the TelemetryLogger, including a future change that will modify MockLogger to no longer inherit from TelemetryLogger, and only implement ITelemetryBaseLogger.

@anthony-murphy anthony-murphy requested review from a team as code owners July 20, 2023 00:02
@github-actions github-actions bot added area: dds Issues related to distributed data structures area: dds: tree area: driver Driver related issues area: loader Loader related issues area: odsp-driver area: runtime Runtime related issues area: tests Tests to add, test infrastructure improvements, etc labels Jul 20, 2023
@github-actions github-actions bot added the base: main PRs targeted against main branch label Jul 20, 2023
@@ -238,14 +260,13 @@ export abstract class TelemetryLogger implements ITelemetryLoggerExt {
const value =
typeof getterOrValue === "function" ? getterOrValue() : getterOrValue;
if (value !== undefined) {
// @ts-expect-error what
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was a leftover artifact of the previous PR, #16385, this is just a bit of clean up to remove the expected error, which was spurious, just had to find typing to work around it.

@github-actions github-actions bot added the public api change Changes to a public API label Jul 20, 2023
@msfluid-bot
Copy link
Collaborator

@fluid-example/bundle-size-tests: +7.71 KB
Metric NameBaseline SizeCompare SizeSize Diff
aqueduct.js 455.11 KB 456.78 KB +1.67 KB
connectionState.js 680 Bytes 680 Bytes No change
containerRuntime.js 244.54 KB 245.95 KB +1.42 KB
loader.js 151.23 KB 151.59 KB +372 Bytes
map.js 47.19 KB 48.01 KB +845 Bytes
matrix.js 147.86 KB 148.6 KB +760 Bytes
odspDriver.js 93.68 KB 94.07 KB +399 Bytes
odspPrefetchSnapshot.js 44.51 KB 44.87 KB +365 Bytes
sharedString.js 164.77 KB 165.72 KB +974 Bytes
sharedTree2.js 243.4 KB 244.36 KB +986 Bytes
Total Size 1.71 MB 1.72 MB +7.71 KB

Baseline commit: 65c8073

Generated by 🚫 dangerJS against 88de372

Copy link
Contributor

@alexvy86 alexvy86 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the rationale for ITelemetryLoggerExt -> ITelemetryBaseLogger? When we pass loggers Internally it seems fine to be clear about "this one supports logging arrays/objects", whether the receiver leverages that or not.

Comment on lines +241 to +242
private extendProperties<T extends ITelemetryLoggerPropertyBag = ITelemetryLoggerPropertyBag>(
toExtend: T,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still a bit confused here. The object we're passing as first parameter is typed as ITelemetryBaseEvent (external interface, from core-interfaces) which extends ITelemetryProperties, a "subset" of the internal ITelemetryLoggerPropertyBag (the latter supports getters as values). The function doesn't check the passed toExtend for getter-values, only TelemetryLogger's own properties. Would this be more appropriate?

Suggested change
private extendProperties<T extends ITelemetryLoggerPropertyBag = ITelemetryLoggerPropertyBag>(
toExtend: T,
private extendProperties<T extends ITelemetryProperties = ITelemetryProperties>(
toExtend: T,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i didn't really change this code, i just moved it, it actually wasn't even necessary to move, it was an artifact of some other changes i was porting over from a different branch. if you look at prepare event, which is the only place this is called, and where it used to live, that code takes ITelemetryBaseEvent which extents ITelemetryLoggerPropertyBag, so i think this change is correct.

I agree the typing is messed up here. It actually looks like a problem with ITelemetryPropertiesExt which probably should support getters, @markfields who should probably look into that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't actually get ITelemetryPropertiesExt, or how that works with general object vs tagged objects, seems complicated, i'm also not sure i see the benefit to logging arrays and objects.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah the property bag types don't have Ext verions. See https://dev.azure.com/fluidframework/internal/_queries/edit/4552, it's a leftover/low-pri todo from the work to add array support.

Tony, happy to discuss the "why" of supporting arrays and objects elsewhere

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anthony-murphy why isn't it just this? There's only one caller and it passes an ITelemetryBaseEvent.

Suggested change
private extendProperties<T extends ITelemetryLoggerPropertyBag = ITelemetryLoggerPropertyBag>(
toExtend: T,
private extendProperties(eventLike: ITelemetryBaseEvent,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its because i shouldn't have originally include it. i want to add a function to pull the properties off a logger to add to errors, which will reuse this, and has really been my end goal all along :)

@anthony-murphy
Copy link
Contributor Author

anthony-murphy commented Jul 20, 2023

What's the rationale for ITelemetryLoggerExt -> ITelemetryBaseLogger? When we pass loggers Internally it seems fine to be clear about "this one supports logging arrays/objects", whether the receiver leverages that or not.

I'm deprecating TelemetryLogger, which in turn will make MockLogger a ITelemetryBaseLogger. These places all have unit tests that use MockLogger, so will break. To get around this we can wrap the MockLogger in a child logger to make it a ITelemetryLoggerExt, but in these cases that is also unnecessary as the cases already create a child logger with the passed in logger, so downgrading the type they take to ITelemetryBaseLogger will make the change to MockLogger transparent.

Overall, i think we should move away from passing around ITelemetryLoggerExt. I actually think we should make it internal. We will then pass around ITelemetryBaseLogger and create child loggers where necessary, and maybe add some internal helper functions for the few case were we pass ITelemetryLoggerExt into a func, only to call a single method on it, like sendError. Overall, this would make things much more consistent, e.g. always use ITelemetryBaseLogger, which also makes testing easier, as the interface is simpler. I'm trying to get it such that we have a single pattern for doing things, not multiple that are kind of the same, but have nuances why they are different, as i think it makes it harder for us to get right, which can lead to inconsistency for consumers.

@@ -56,7 +56,7 @@ const defaultNumberSummarizationAttempts = 2; // only up to 2 attempts
*/
export class RunningSummarizer implements IDisposable {
public static async start(
logger: ITelemetryLoggerExt,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels like within the runtime we should be fine to pass around ITelemetryLoggerExt, why the change?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found the existing convo, got it.

@markfields
Copy link
Member

Overall, i think we should move away from passing around ITelemetryLoggerExt. I actually think we should make it internal. We will then pass around ITelemetryBaseLogger

Can you write up a one-pager and post on Dev and/or bring it to Design Review? Seems reasonable but would be good to discuss even briefly to check pros/cons

@anthony-murphy
Copy link
Contributor Author

Overall, i think we should move away from passing around ITelemetryLoggerExt. I actually think we should make it internal. We will then pass around ITelemetryBaseLogger

Can you write up a one-pager and post on Dev and/or bring it to Design Review? Seems reasonable but would be good to discuss even briefly to check pros/cons

is there any documentation for how the current types work? it seems like a bit of a mess. my proposal is make it not a mess.

@anthony-murphy anthony-murphy merged commit fc7f327 into microsoft:main Jul 20, 2023
@anthony-murphy anthony-murphy deleted the reduce-telemetrylogger-coupling branch July 20, 2023 22:34
@markfields
Copy link
Member

@anthony-murphy let's revisit the "mess" after that ADO item about removing the old/duplicate types is done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: dds: tree area: dds Issues related to distributed data structures area: driver Driver related issues area: loader Loader related issues area: odsp-driver area: runtime Runtime related issues area: tests Tests to add, test infrastructure improvements, etc base: main PRs targeted against main branch public api change Changes to a public API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants