open-feature / open-feature/go-sdk

[BUG] telemetry: feature_flag.context.id is emitted as an empty string when no targeting key is set

Open Beginner friendly
#563 0 comments 0 reactions 0 assignees View on GitHub
bug good first issue
Dominant language
Go
Stars
249
Forks
61
Avg merge
2d 10h
Merged PRs (30d)
20

Description

## Observed behavior

`CreateEvaluationEvent` assigns the context ID unconditionally from the targeting key, then lets flag metadata override it:

https://github.com/open-feature/go-sdk/blob/6b0824c6c7b9b69e40f26aedcc4406ad4d3a5cec/openfeature/telemetry/telemetry.go#L66-L70

With no targeting key and no `contextId` metadata, the event carries `feature_flag.context.id: ""` rather than omitting the attribute.

## Expected Behavior

[Appendix D](https://openfeature.dev/specification/appendix-d) types this attribute as `string` and says the targeting key is used only *"if not available"* — i.e. as a fallback for `contextId`.

All three siblings guard the assignment, and all three check **metadata first**, falling back to the targeting key:

- **JS** — `if (contextId)`.
- **Python** — `if context_id:`.
- **Java** — `if (contextId != null) … else …` (though Java's else-branch can still pass a null targeting key, so it's only partially better).

Go's inverted precedence is what produces the empty string; matching the sibling ordering fixes both the empty-attribute case and the precedence difference at once.

## Steps to reproduce

```go
// empty targeting key, no contextId in flag metadata
event := telemetry.CreateEvaluationEvent(hookContext, details)
v, ok := event.Attributes["feature_flag.context.id"]
fmt.Println(ok, fmt.Sprintf("%q", v)) // true "" — want the attribute omitted
```

Contributor guide

Open the contributing guide

Research direction

Start in openfeature/telemetry/telemetry.go at CreateEvaluationEvent, especially the lines linked in the issue. Check the sibling implementations and the metadata-versus-targeting-key behavior described there. Done means the context.id attribute is omitted when both values are unavailable, while metadata takes precedence over the targeting key; verify with the provided reproduction.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
observability-sre
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
88/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.