Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
b0e27ea
grpc baggage
cicoyle Apr 4, 2025
def023a
http aligns with grpc tracing tests
cicoyle Apr 4, 2025
bd19e66
update import
cicoyle Apr 4, 2025
4a0c6aa
handle multiple baggage headers
cicoyle Apr 4, 2025
704e721
add baggage IT tests
cicoyle Apr 4, 2025
11d52bd
fix import
cicoyle Apr 7, 2025
2ee9d67
fix output binding tests
cicoyle Apr 7, 2025
3e5aaf2
update go.mod
cicoyle Apr 7, 2025
1bd501d
update components contrib commit to use newer avro version to not ove…
cicoyle Apr 7, 2025
0cf5a2f
fix conflicts
cicoyle Apr 9, 2025
e8ec7e5
fix go.sum
cicoyle Apr 10, 2025
be6bdd5
Merge branch 'master' into feat-baggage
cicoyle Apr 10, 2025
27f6303
fix conflicts
cicoyle Apr 14, 2025
cb7e481
ensure http ctx + header propagation aligns with otel and use otel pa…
cicoyle Apr 16, 2025
5c92a76
align with otel support
cicoyle Apr 16, 2025
873b487
rm baggage consts since handled by otel, but still use in tests
cicoyle Apr 16, 2025
335e896
rm consts from tests + use string literals
cicoyle Apr 16, 2025
228a01c
fix conflicts
cicoyle Apr 16, 2025
e1f6a75
update with latest commit
cicoyle Apr 17, 2025
017ee13
updates for output binding
cicoyle Apr 17, 2025
2b670f8
update grpc code for baggage handling
cicoyle Apr 20, 2025
389f69d
test for multiple baggage values
cicoyle Apr 20, 2025
0fd7fce
align http with grpc
cicoyle Apr 21, 2025
77dc61e
use merged contrib PR sha
cicoyle Apr 23, 2025
3d7b90a
clean up diff
cicoyle Apr 23, 2025
f0b7584
update import
cicoyle Apr 24, 2025
01390ee
fix lint
cicoyle Apr 24, 2025
e4582f3
fix go.mod
cicoyle Apr 24, 2025
cd901ff
fix govuln check things
cicoyle Apr 24, 2025
2eb9f30
fix go.mod againn
cicoyle Apr 24, 2025
6cd2e13
fix lint
cicoyle Apr 24, 2025
0716833
rm err2 and return malformed req if invalid baggage
cicoyle May 6, 2025
adb23de
fix http_tracing_test
cicoyle May 6, 2025
beae30b
check baggage contents in IT
cicoyle May 6, 2025
e4eb831
align output binding with other tests
cicoyle May 6, 2025
a617360
fix go.mod conflicts
cicoyle May 6, 2025
b62d289
fix govet
cicoyle May 6, 2025
525dbe2
Merge branch 'master' into feat-baggage
cicoyle May 19, 2025
4579e61
pull invoke + binding baggage to baggage dir
cicoyle May 19, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/argoproj/argo-rollouts v1.4.1
github.com/cenkalti/backoff/v4 v4.3.0
github.com/cloudevents/sdk-go/v2 v2.15.2
github.com/dapr/components-contrib v1.15.1-0.20250409220637-70c99725fd12
github.com/dapr/components-contrib v1.15.1-0.20250423123324-b2c31ceba20b
github.com/dapr/durabletask-go v0.6.5
github.com/dapr/kit v0.15.2
github.com/diagridio/go-etcd-cron v0.6.2
Expand Down Expand Up @@ -286,7 +286,7 @@ require (
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.3 // indirect
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed // indirect
github.com/hamba/avro/v2 v2.25.1 // indirect
github.com/hamba/avro/v2 v2.28.0 // indirect
github.com/hashicorp/consul/api v1.25.1 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -502,8 +502,8 @@ github.com/dancannon/gorethink v4.0.0+incompatible h1:KFV7Gha3AuqT+gr0B/eKvGhbjm
github.com/dancannon/gorethink v4.0.0+incompatible/go.mod h1:BLvkat9KmZc1efyYwhz3WnybhRZtgF1K929FD8z1avU=
github.com/danieljoos/wincred v1.1.2 h1:QLdCxFs1/Yl4zduvBdcHB8goaYk9RARS2SgLLRuAyr0=
github.com/danieljoos/wincred v1.1.2/go.mod h1:GijpziifJoIBfYh+S7BbkdUTU4LfM+QnGqR5Vl2tAx0=
github.com/dapr/components-contrib v1.15.1-0.20250409220637-70c99725fd12 h1:VETULsWb8KIjzuqmEiXCv6BHw0QVgkjMkP7tztIv9NI=
github.com/dapr/components-contrib v1.15.1-0.20250409220637-70c99725fd12/go.mod h1:0yFCUv1c6TMWvC6sQYdv0FMWmdCeEpWGE8AYp9cb6Ic=
github.com/dapr/components-contrib v1.15.1-0.20250423123324-b2c31ceba20b h1:u1xUF4CuNsTlv8pZsrX6XH1FolmMCjJ0Kyfef0wJkzY=
github.com/dapr/components-contrib v1.15.1-0.20250423123324-b2c31ceba20b/go.mod h1:mDA9c8w/KGAOx18yCTaMXHkfWS6mFHR/o3FjI6a14dA=
github.com/dapr/durabletask-go v0.6.5 h1:aWcxMfYudojpgRjJRdUr7yyZ7rGcvLtWXUuA4cGHBR0=
github.com/dapr/durabletask-go v0.6.5/go.mod h1:nTZ5fCbJLnZbVdi6Z2YxdDF1OgQZL3LroogGuetrwuA=
github.com/dapr/kit v0.15.2 h1:5H9IhKScU/SpE2Hxvr5vUlmYN1e2MJN15RoT8/KSziU=
Expand Down Expand Up @@ -946,8 +946,8 @@ github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c h1:6rhixN/i8
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c/go.mod h1:NMPJylDgVpX0MLRlPy15sqSwOFv/U1GZ2m21JhFfek0=
github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed h1:5upAirOpQc1Q53c0bnx2ufif5kANL7bfZWcc6VJWJd8=
github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed/go.mod h1:tMWxXQ9wFIaZeTI9F+hmhFiGpFmhOHzyShyFUhRm0H4=
github.com/hamba/avro/v2 v2.25.1 h1:t8cOyv0wkNAPF6/khArMtR0nK9HtGa+WKbp9q+KdFZQ=
github.com/hamba/avro/v2 v2.25.1/go.mod h1:I8glyswHnpED3Nlx2ZdUe+4LJnCOOyiCzLMno9i/Uu0=
github.com/hamba/avro/v2 v2.28.0 h1:E8J5D27biyAulWKNiEBhV85QPc9xRMCUCGJewS0KYCE=
github.com/hamba/avro/v2 v2.28.0/go.mod h1:9TVrlt1cG1kkTUtm9u2eO5Qb7rZXlYzoKqPt8TSH+TA=
github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q=
github.com/hashicorp/consul/api v1.3.0/go.mod h1:MmDNSzIMUjNpY/mQ398R4bk2FnqQLoPndWW5VkKPlCE=
github.com/hashicorp/consul/api v1.25.1 h1:CqrdhYzc8XZuPnhIYZWH45toM0LB9ZeYr/gvpLVI3PE=
Expand Down
23 changes: 18 additions & 5 deletions pkg/api/grpc/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ import (
"net/http"
"slices"
"strconv"
"strings"
"sync"
"sync/atomic"
"time"

otelbaggage "go.opentelemetry.io/otel/baggage"
otelTrace "go.opentelemetry.io/otel/trace"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
Expand All @@ -47,6 +49,7 @@ import (
stateLoader "github.com/dapr/dapr/pkg/components/state"
"github.com/dapr/dapr/pkg/config"
diag "github.com/dapr/dapr/pkg/diagnostics"
diagConsts "github.com/dapr/dapr/pkg/diagnostics/consts"
diagUtils "github.com/dapr/dapr/pkg/diagnostics/utils"
"github.com/dapr/dapr/pkg/encryption"
"github.com/dapr/dapr/pkg/messages"
Expand Down Expand Up @@ -505,23 +508,33 @@ func (a *api) InvokeBinding(ctx context.Context, in *runtimev1pb.InvokeBindingRe
sc := span.SpanContext()
tp := diag.SpanContextToW3CString(sc)
if span != nil {
if _, ok := req.Metadata[diag.TraceparentHeader]; !ok {
req.Metadata[diag.TraceparentHeader] = tp
if _, ok := req.Metadata[diagConsts.TraceparentHeader]; !ok {
req.Metadata[diagConsts.TraceparentHeader] = tp
}
if _, ok := req.Metadata[diag.TracestateHeader]; !ok {
if _, ok := req.Metadata[diagConsts.TracestateHeader]; !ok {
if sc.TraceState().Len() > 0 {
req.Metadata[diag.TracestateHeader] = diag.TraceStateToW3CString(sc)
req.Metadata[diagConsts.TracestateHeader] = diag.TraceStateToW3CString(sc)
}
}
}

// Allow for distributed tracing by passing context metadata.
if incomingMD, ok := metadata.FromIncomingContext(ctx); ok {
if baggageValues := incomingMD[diagConsts.BaggageHeader]; len(baggageValues) > 0 {
baggageString := strings.Join(baggageValues, ",")
baggage, err := otelbaggage.Parse(baggageString)
if err != nil {
return nil, err
}
ctx = otelbaggage.ContextWithBaggage(ctx, baggage)
req.Metadata[diagConsts.BaggageHeader] = baggageString
}

for key, val := range incomingMD {
sanitizedKey := invokev1.ReservedGRPCMetadataToDaprPrefixHeader(key)
// Not to overwrite the existing metadata
// But if the key is traceparent or tracestate, we allow overwrite the existing metadata.
if _, exist := req.Metadata[sanitizedKey]; !exist || (key == diag.TraceparentHeader || key == diag.TracestateHeader) {
if _, exist := req.Metadata[sanitizedKey]; !exist || (key == diagConsts.TraceparentHeader || key == diagConsts.TracestateHeader) {
req.Metadata[sanitizedKey] = val[0]
}
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/api/grpc/proxy/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (

"github.com/dapr/dapr/pkg/api/grpc/proxy/codec"
"github.com/dapr/dapr/pkg/diagnostics"
diagConsts "github.com/dapr/dapr/pkg/diagnostics/consts"
"github.com/dapr/dapr/pkg/resiliency"
"github.com/dapr/kit/utils"
)
Expand Down Expand Up @@ -96,7 +97,7 @@ func (s *handler) handler(srv any, serverStream grpc.ServerStream) error {
// Fetch the AppId so we can reference it for resiliency.
ctx := serverStream.Context()
md, _ := metadata.FromIncomingContext(ctx)
v := md[diagnostics.GRPCProxyAppIDKey]
v := md[diagConsts.GRPCProxyAppIDKey]

// The app id check is handled in the StreamDirector. If we don't have it here, we just use a NoOp policy since we know the request is impossible.
var policyDef *resiliency.PolicyDefinition
Expand Down
13 changes: 7 additions & 6 deletions pkg/api/grpc/proxy/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import (
pb "github.com/dapr/dapr/pkg/api/grpc/proxy/testservice"
"github.com/dapr/dapr/pkg/config"
diag "github.com/dapr/dapr/pkg/diagnostics"
diagConsts "github.com/dapr/dapr/pkg/diagnostics/consts"
"github.com/dapr/dapr/pkg/resiliency"
"github.com/dapr/kit/logger"
"github.com/dapr/kit/retry"
Expand Down Expand Up @@ -440,7 +441,7 @@ func (s *proxyTestSuite) TestResiliencyUnary() {

ctx, cancel := s.ctx()
defer cancel()
ctx = metadata.NewOutgoingContext(ctx, metadata.Pairs(diag.GRPCProxyAppIDKey, testAppID))
ctx = metadata.NewOutgoingContext(ctx, metadata.Pairs(diagConsts.GRPCProxyAppIDKey, testAppID))

// Reset callCount before this test
s.service.pingCallCount.Store(0)
Expand Down Expand Up @@ -476,7 +477,7 @@ func (s *proxyTestSuite) TestResiliencyUnary() {

setupMetrics(s)

ctx := metadata.NewOutgoingContext(t.Context(), metadata.Pairs(diag.GRPCProxyAppIDKey, testAppID))
ctx := metadata.NewOutgoingContext(t.Context(), metadata.Pairs(diagConsts.GRPCProxyAppIDKey, testAppID))

_, err := s.testClient.Ping(ctx, &pb.PingRequest{Value: message})
require.Error(t, err, "Ping should fail due to timeouts")
Expand Down Expand Up @@ -515,7 +516,7 @@ func (s *proxyTestSuite) TestResiliencyUnary() {
go func(i int) {
for j := range numOperations {
pingMsg := fmt.Sprintf("%d:%d", i, j)
ctx := metadata.NewOutgoingContext(t.Context(), metadata.Pairs(diag.GRPCProxyAppIDKey, testAppID))
ctx := metadata.NewOutgoingContext(t.Context(), metadata.Pairs(diagConsts.GRPCProxyAppIDKey, testAppID))
res, err := s.testClient.Ping(ctx, &pb.PingRequest{Value: pingMsg})
require.NoErrorf(t, err, "Ping should succeed for operation %d:%d", i, j)
require.NotNilf(t, res, "Response should not be nil for operation %d:%d", i, j)
Expand Down Expand Up @@ -584,7 +585,7 @@ func (s *proxyTestSuite) TestResiliencyStreaming() {
ctx, cancel := context.WithTimeout(t.Context(), time.Minute)
defer cancel()
ctx = metadata.NewOutgoingContext(ctx, metadata.Pairs(
diag.GRPCProxyAppIDKey, "test",
diagConsts.GRPCProxyAppIDKey, "test",
"dapr-test", t.Name(),
))

Expand Down Expand Up @@ -622,7 +623,7 @@ func (s *proxyTestSuite) TestResiliencyStreaming() {
setupMetrics(s)

ctx = metadata.NewOutgoingContext(ctx, metadata.Pairs(
diag.GRPCProxyAppIDKey, testAppID,
diagConsts.GRPCProxyAppIDKey, testAppID,
StreamMetadataKey, "1",
"dapr-test", t.Name(),
))
Expand Down Expand Up @@ -673,7 +674,7 @@ func (s *proxyTestSuite) TestResiliencyStreaming() {
setupMetrics(s)

ctx = metadata.NewOutgoingContext(ctx, metadata.Pairs(
diag.GRPCProxyAppIDKey, testAppID,
diagConsts.GRPCProxyAppIDKey, testAppID,
StreamMetadataKey, "1",
"dapr-test", t.Name(),
))
Expand Down
17 changes: 16 additions & 1 deletion pkg/api/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (

"github.com/go-chi/chi/v5"
"github.com/mitchellh/mapstructure"
otelBaggage "go.opentelemetry.io/otel/baggage"
"go.opentelemetry.io/otel/trace"

"github.com/dapr/components-contrib/bindings"
Expand Down Expand Up @@ -410,7 +411,8 @@ func (a *api) onOutputBindingMessage(w nethttp.ResponseWriter, r *nethttp.Reques
return
}

b, err := json.Marshal(req.Data)
var b []byte
b, err = json.Marshal(req.Data)
if err != nil {
resp := messages.NewAPIErrorHTTP(fmt.Sprintf(messages.ErrMalformedRequestData, err), errorcodes.CommonMalformedRequestData, nethttp.StatusInternalServerError)
respondWithError(w, resp)
Expand All @@ -433,6 +435,19 @@ func (a *api) onOutputBindingMessage(w nethttp.ResponseWriter, r *nethttp.Reques
}
}

if baggageHeaders := r.Header.Values(diagConsts.BaggageHeader); len(baggageHeaders) > 0 {
baggageString := strings.Join(baggageHeaders, ",")
if _, err = otelBaggage.Parse(baggageString); err != nil {
resp := messages.NewAPIErrorHTTP(fmt.Sprintf("invalid baggage header: %v", err), errorcodes.CommonMalformedRequest, nethttp.StatusBadRequest)
respondWithError(w, resp)
return
}
if req.Metadata == nil {
req.Metadata = map[string]string{}
}
req.Metadata[diagConsts.BaggageHeader] = baggageString
}

start := time.Now()
resp, err := a.sendToOutputBindingFn(r.Context(), name, &bindings.InvokeRequest{
Metadata: req.Metadata,
Expand Down
15 changes: 15 additions & 0 deletions pkg/diagnostics/consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,21 @@ const (
// Keys used in the context's metadata for streaming calls
// Note: these keys must always be all-lowercase
DaprCallLocalStreamMethodKey = "__dapr_calllocalstream_method"

// We have leveraged the code from opencensus-go plugin to adhere the w3c trace context.
// Reference : https://github.com/census-instrumentation/opencensus-go/blob/master/plugin/ochttp/propagation/tracecontext/propagation.go
// Trace context headers
TraceparentHeader = "traceparent"
TracestateHeader = "tracestate"
BaggageHeader = "baggage"

GRPCTraceContextKey = "grpc-trace-bin"
GRPCProxyAppIDKey = "dapr-app-id"

// Trace sampling constants
SupportedVersion = 0
MaxVersion = 254
MaxTracestateLen = 512
)

// GrpcAppendSpanAttributesFn is the interface that applies to gRPC requests that add span attributes.
Expand Down
5 changes: 3 additions & 2 deletions pkg/diagnostics/grpc_monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"google.golang.org/protobuf/proto"

"github.com/dapr/dapr/pkg/api/grpc/metadata"
diagConsts "github.com/dapr/dapr/pkg/diagnostics/consts"
diagUtils "github.com/dapr/dapr/pkg/diagnostics/utils"
)

Expand Down Expand Up @@ -264,7 +265,7 @@ func (g *grpcMetrics) StreamingServerInterceptor() grpc.StreamServerInterceptor
return func(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error {
ctx := ss.Context()
md, _ := metadata.FromIncomingContext(ctx)
vals, ok := md[GRPCProxyAppIDKey]
vals, ok := md[diagConsts.GRPCProxyAppIDKey]
if !ok || len(vals) == 0 {
return handler(srv, ss)
}
Expand All @@ -285,7 +286,7 @@ func (g *grpcMetrics) StreamingClientInterceptor() grpc.StreamServerInterceptor
return func(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error {
ctx := ss.Context()
md, _ := metadata.FromIncomingContext(ctx)
vals, ok := md[GRPCProxyAppIDKey]
vals, ok := md[diagConsts.GRPCProxyAppIDKey]
if !ok || len(vals) == 0 {
return handler(srv, ss)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/diagnostics/grpc_monitoring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (f *fakeProxyStream) Context() context.Context {
}

ctx := context.Background()
ctx = grpcMetadata.NewIncomingContext(ctx, grpcMetadata.New(map[string]string{GRPCProxyAppIDKey: f.appID}))
ctx = grpcMetadata.NewIncomingContext(ctx, grpcMetadata.New(map[string]string{"dapr-app-id": f.appID}))
ctx, _ = metadata.SetMetadataInTapHandle(ctx, nil)
return ctx
}
Expand Down
Loading
Loading