launchdarkly / python-server-sdk

LaunchDarkly Server-side SDK for Python
https://docs.launchdarkly.com/sdk/server-side/python
Other
39 stars 45 forks source link

Warning flooding logs #298

Closed ppayun closed 3 months ago

ppayun commented 4 months ago

https://github.com/launchdarkly/python-server-sdk/blob/d152455b89cb70164d8487a1cc0b47f92017a5c4/ldclient/client.py#L471

We use default value for some flags, and this logic keep writing warnings to the logs, can the log level be changed to DEBUG?

    if not context.valid:
        log.warning("Context was invalid for flag evaluation (%s); returning default value" % context.error)
        return EvaluationDetail(default, None, error_reason('USER_NOT_SPECIFIED')), None
keelerm84 commented 4 months ago

This error should only be shown when the context you are providing is considered invalid. Is there a reason you are trying to use an invalid context?

The reason the context is invalid should be in the logged error.

ppayun commented 4 months ago

I just checked, for some reason, the code is using an empty context(see code below). We can definitely add some context info. But still why empty context is illegal and showing as warning?

        context_builder = Context.builder(client_id)

        for dict_key, dict_value in context_dict.items():  # this is empty, we didn't set any values
            context_builder.set(dict_key, dict_value)

        context = context_builder.build()
        value = ldclient.get().variation(key, context, default_value)
        return value
keelerm84 commented 4 months ago

@ppayun my apologies for the long delay in responding.

Providing a key is a requirement of our context model. We use the provided contexts to populate things like the context drop down list in our UI, and it is also used for aggregating metrics for things like experimentation, etc.

While we do not require many attributes to be set for a context, we do require a key and a valid kind (which will to default to 'user').

github-actions[bot] commented 3 months ago

This issue is marked as stale because it has been open for 30 days without activity. Remove the stale label or comment, or this will be closed in 7 days.