Skip to content

Add flag key on Tracking Hook error stage #340

@danjuv

Description

@danjuv

It seems when a flag is successfully evaluated with the tracing hook added, we record the flag's key (and other data) in the span:

    "events": [
        {
            "name": "feature_flag.evaluation",
            "timestamp": "2026-02-07T12:10:02.045159Z",
            "attributes": {
                "feature_flag.key": "test-flag",
                "feature_flag.result.value": "true",
..
            }
        }

But if the flag evaluation errors (e.g. for a FLAG_NOT_FOUND error), the flag key isn't recorded:

    "events": [
        {
            "name": "exception",
            "timestamp": "2026-02-07T12:10:02.044985Z",
            "attributes": {
                "exception.type": "openfeature.exception.FlagNotFoundError",
                "exception.message": "",
                "exception.stacktrace": "openfeature.exception.FlagNotFoundError\n",
                "exception.escaped": "False"
            }
        },
        {
            "name": "feature_flag.evaluation",
            "timestamp": "2026-02-07T12:10:02.045159Z",
            "attributes": {
                "feature_flag.key": "test-flag",
                "feature_flag.result.value": "true",
            }
        }
    

Likely because we only set the flag_key attribute during a successful flag evaluation.

It'd be very helpful to see the associated flag key for an exception in trace time. It seems all we need to do is modify this. The Spec suggests hook context must include flag key

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions