Skip to content

Commit 66e05df

Browse files
authored
fix(triple): preserve otel traceparent in TripleInvoker (#3285)
* remove the config package from package client * fix(client): fail fast on invalid registry and method config * restore WithMethod in Server * fix lint of action_test * refactor: split processURL to reduce cognitive complexity * migrate the ValidateRegistryIDs to internal * fix the cmt * remove the validateRegistryIDs * fix 3240 * fix lint * fix the constant or use http.CanonicalHeaderKey (staticcheck)
1 parent 5efce61 commit 66e05df

3 files changed

Lines changed: 310 additions & 52 deletions

File tree

protocol/triple/triple_invoker.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import (
2121
"context"
2222
"errors"
2323
"fmt"
24+
"net/http"
25+
"strings"
2426
"sync"
2527
)
2628

@@ -161,20 +163,28 @@ func mergeAttachmentToOutgoing(ctx context.Context, inv base.Invocation) (contex
161163
if timeout, ok := inv.GetAttachment(constant.TimeoutKey); ok {
162164
ctx = context.WithValue(ctx, tri.TimeoutKey{}, timeout)
163165
}
166+
header := cloneOutgoingHeader(tri.ExtractFromOutgoingContext(ctx))
164167
for key, valRaw := range inv.Attachments() {
168+
lowerKey := strings.ToLower(key)
165169
if str, ok := valRaw.(string); ok {
166-
ctx = tri.AppendToOutgoingContext(ctx, key, str)
170+
header[lowerKey] = []string{str}
167171
continue
168172
}
169173
if strs, ok := valRaw.([]string); ok {
170-
for _, str := range strs {
171-
ctx = tri.AppendToOutgoingContext(ctx, key, str)
172-
}
174+
header[lowerKey] = append([]string(nil), strs...)
173175
continue
174176
}
175177
return ctx, fmt.Errorf("triple attachments value with key = %s is invalid, which should be string or []string", key)
176178
}
177-
return ctx, nil
179+
return tri.NewOutgoingContext(ctx, header), nil
180+
}
181+
182+
func cloneOutgoingHeader(header http.Header) http.Header {
183+
cloned := make(http.Header, len(header))
184+
for key, vals := range header {
185+
cloned[strings.ToLower(key)] = append([]string(nil), vals...)
186+
}
187+
return cloned
178188
}
179189

180190
// parseInvocation retrieves information from invocation.
@@ -202,18 +212,8 @@ func parseInvocation(ctx context.Context, url *common.URL, invocation base.Invoc
202212
return callType, inRaw, method, nil
203213
}
204214

205-
// parseAttachments retrieves attachments from users passed-in and URL, then injects them into ctx
215+
// parseAttachments injects pre-defined URL attachments into invocation.
206216
func parseAttachments(ctx context.Context, url *common.URL, invocation base.Invocation) {
207-
// retrieve users passed-in attachment
208-
attaRaw := ctx.Value(constant.AttachmentKey)
209-
if attaRaw != nil {
210-
if userAtta, ok := attaRaw.(map[string]any); ok {
211-
for key, val := range userAtta {
212-
invocation.SetAttachment(key, val)
213-
}
214-
}
215-
}
216-
// set pre-defined attachments
217217
for _, key := range triAttachmentKeys {
218218
if val := url.GetParam(key, ""); len(val) > 0 {
219219
invocation.SetAttachment(key, val)

0 commit comments

Comments
 (0)