-
Notifications
You must be signed in to change notification settings - Fork 536
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
feat(container-loader): Allow setting the container's logger at load time #13779
Conversation
@@ -542,6 +542,9 @@ export enum LoaderHeader { | |||
reconnect = "fluid-reconnect", | |||
sequenceNumber = "fluid-sequence-number", | |||
|
|||
// BREAKING CHANGE -- TODO: figure this out |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it a breaking change to add a new enum value? I would expect all usages to be against specific enums but maybe there's something I'm not thinking of.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Enums are a pain from a back-compat perspective. Adding a new value creates type incompatibility between the enum type. For example in our type testing code, this blows up if I add an enum value:
declare function get_current_EnumDeclaration_LoaderHeader():
TypeOnly<current.LoaderHeader>;
declare function use_old_EnumDeclaration_LoaderHeader(
use: TypeOnly<old.LoaderHeader>);
use_old_EnumDeclaration_LoaderHeader(
get_current_EnumDeclaration_LoaderHeader());
Argument of type 'TypeOnly<import("/home/tylerbu/code/release-1/packages/common/container-definitions/src/loader").LoaderHeader>' is not assignable to parameter of type 'TypeOnly<import("/home/tylerbu/code/release-1/node_modules/@fluidframework/container-definitions-previous/dist/loader").LoaderHeader>'.
Type 'LoaderHeader.cache' is not assignable to type 'TypeOnly<LoaderHeader>'.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ahh interesting, right, because one definition does not fit into the other. I wonder if we should come up with a general coding recommendation to avoid these
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, enums are not mapping to native JS. I think we have explored two alternatives: string unions (mostly on string types) and objects pattern. ex: https://github.com/microsoft/FluidFramework/pull/10149/files. I don't think we have concluded on one pattern fits all.
⯅ @fluid-example/bundle-size-tests: +140 Bytes
Baseline commit: 5d071c6 |
441139c
to
98e0754
Compare
98e0754
to
b2fae40
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Signing-off but starting a thread on future of Loader as concept.
Let's have a discussion first if we want to keep adding here, or start removing :)
I'm going to merge this because that will "lock in" the change and make it easiest to port to the release branch (less churn to worry about). If it's needed in a patch porting it should be straightforward and quick. Otherwise, we have until next week to change our minds and back it out before our internal 3.1 release. |
…time (microsoft#13779) Developers can now specify a logger that should be used by a container when it is loaded instead of always using the Loader's logger (`Loader.services.subLogger`). Today a container's logger is set based on the logger used in the Loader. This is not ideal in nested container scenarios, where a container is loading a data store within another container, which is itself within another container. Apps/hosts often augment the logger from the loader when loading a container, and when loading a nested container, it makes sense to provide an augmented logger to the container directly rather than using the one from the loader. This PR enables the scenario by adding a `fluid-base-logger` request header to the container load request. If set, then the container's `subLogger` will be set to the header value. If the override isn't set, then the container will use the loader's logger as it does today. For completeness, we should add a header to the LoaderHeaders enum. Doing so is a breaking change, though, so that will be done in a future commit.
…time (#14005) Cherry-pick of #13779 to the 3.0 release branch. Developers can now specify a logger that should be used by a container when it is loaded instead of always using the Loader's logger (`Loader.services.subLogger`). Today a container's logger is set based on the logger used in the Loader. This is not ideal in nested container scenarios, where a container is loading a data store within another container, which is itself within another container. Apps/hosts often augment the logger from the loader when loading a container, and when loading a nested container, it makes sense to provide an augmented logger to the container directly rather than using the one from the loader. This PR enables the scenario by adding a `fluid-base-logger` request header to the container load request. If set, then the container's `subLogger` will be set to the header value. If the override isn't set, then the container will use the loader's logger as it does today.
…time (microsoft#13779) ## Feature: set container logger at load time Developers can now specify a logger that should be used by a container when it is loaded instead of always using the Loader's logger (`Loader.services.subLogger`). ## Use cases and scenarios Today a container's logger is set based on the logger used in the Loader. This is not ideal in nested container scenarios, where a container is loading a data store within another container, which is itself within another container. Apps/hosts often augment the logger from the loader when loading a container, and when loading a nested container, it makes sense to provide an augmented logger to the container directly rather than using the one from the loader. ## Implementation details This PR enables the scenario by adding a `fluid-base-logger` request header to the container load request. If set, then the container's `subLogger` will be set to the header value. If the override isn't set, then the container will use the loader's logger as it does today. For completeness, we should add a header to the LoaderHeaders enum. Doing so is a breaking change, though, so that will be done in a future commit.
…ntime initialization (#14114) Related: #13779 Currently, the scope is set once (at Loader creation time). However, it's possible hosts may want to pass different scope information on a per-resolve basis. This is particularly true when the load is performed in a different context, e.g. a top-level container vs. loading a "guest" container as a sub-part of an experience. Normally we recommend against using scope, but it does serve a purpose here of allowing hosts to pass objects to their container runtime at initialization time. Since the initialization phase (instantiateRuntime) is buried in the Container, this is the best entrypoint we currently make available for host customization of that initialization.
Feature: set container logger at load time
Developers can now specify a logger that should be used by a container when it is loaded instead of always using the Loader's logger (
Loader.services.subLogger
).Use cases and scenarios
Today a container's logger is set based on the logger used in the Loader. This is not ideal in nested container scenarios, where a container is loading a data store within another container, which is itself within another container. Apps/hosts often augment the logger from the loader when loading a container, and when loading a nested container, it makes sense to provide an augmented logger to the container directly rather than using the one from the loader.
Implementation details
This PR enables the scenario by adding a
fluid-base-logger
request header to the container load request. If set, then the container'ssubLogger
will be set to the header value. If the override isn't set, then the container will use the loader's logger as it does today.For completeness, we should add a header to the LoaderHeaders enum. Doing so is a breaking change, though, so that will be done in a future commit.