Skip to content

Preserve baggage items when appending new context data#6

Draft
rorua wants to merge 1 commit intomasterfrom
codex/find-and-fix-an-important-bug
Draft

Preserve baggage items when appending new context data#6
rorua wants to merge 1 commit intomasterfrom
codex/find-and-fix-an-important-bug

Conversation

@rorua
Copy link
Owner

@rorua rorua commented Aug 11, 2025

Summary

  • ensure AddBaggageItem and AddBaggageItems merge with existing baggage instead of overwriting
  • add tests covering baggage accumulation helpers

Testing

  • GOPROXY=direct go test ./... (fails: unrecognized import paths / network 403 errors)

https://chatgpt.com/codex/tasks/task_e_6899848cc4f08326bfe88bc0e6e837d2

@rorua rorua requested a review from Copilot August 11, 2025 05:58
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes baggage handling functions to preserve existing baggage items when adding new ones, instead of overwriting the entire baggage. The changes ensure that AddBaggageItem and AddBaggageItems accumulate baggage data rather than replacing it.

  • Modified AddBaggageItem to retrieve existing baggage and use SetMember instead of creating new baggage
  • Updated AddBaggageItems to iterate and set members on existing baggage rather than creating from scratch
  • Added comprehensive tests to verify baggage accumulation behavior

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
baggage.go Fixed functions to merge with existing baggage instead of overwriting
baggage_test.go Added tests to verify baggage accumulation works correctly

Comment on lines 15 to 29
func AddBaggageItem(ctx context.Context, key, value string) context.Context {
b := baggage.FromContext(ctx)
m, _ := baggage.NewMember(key, value)
b, _ := baggage.New(m)
b, _ = b.SetMember(m)
return baggage.ContextWithBaggage(ctx, b)
}

// AddBaggageItems adds multiple key-value pairs to the baggage.
func AddBaggageItems(ctx context.Context, items map[string]string) context.Context {
var members []baggage.Member
b := baggage.FromContext(ctx)
for key, value := range items {
m, _ := baggage.NewMember(key, value)
members = append(members, m)
b, _ = b.SetMember(m)
}
b, _ := baggage.New(members...)
return baggage.ContextWithBaggage(ctx, b)
Copy link

Copilot AI Aug 11, 2025

Choose a reason for hiding this comment

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

Error from b.SetMember(m) is ignored. Consider handling the error or at least documenting why it's safe to ignore.

Copilot uses AI. Check for mistakes.
Comment on lines 26 to +27
m, _ := baggage.NewMember(key, value)
members = append(members, m)
b, _ = b.SetMember(m)
Copy link

Copilot AI Aug 11, 2025

Choose a reason for hiding this comment

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

Error from b.SetMember(m) is ignored. Consider handling the error or at least documenting why it's safe to ignore.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant