diff --git a/filter/filter_impl/generic_service_filter.go b/filter/filter_impl/generic_service_filter.go index da33f13e5ef29a7164c3776b65cc5cabd4b43888..44cb5751e5a5d4840f4537d2ab4060949d77604c 100644 --- a/filter/filter_impl/generic_service_filter.go +++ b/filter/filter_impl/generic_service_filter.go @@ -106,6 +106,7 @@ func (ef *GenericServiceFilter) Invoke(invoker protocol.Invoker, invocation prot newParams[i] = newParam } newInvocation := invocation2.NewRPCInvocation(methodName, newParams, invocation.Attachments()) + newInvocation.SetContext(invocation.Context()) newInvocation.SetReply(invocation.Reply()) return invoker.Invoke(newInvocation) } diff --git a/filter/filter_impl/tracing_filter.go b/filter/filter_impl/tracing_filter.go index d1d68de87106ff227223cd821670b54d01054083..dc1e8c314a01e68e3eae0e525834607603755e14 100644 --- a/filter/filter_impl/tracing_filter.go +++ b/filter/filter_impl/tracing_filter.go @@ -56,7 +56,7 @@ func (tf *tracingFilter) Invoke(invoker protocol.Invoker, invocation protocol.In // withTimeout after we support the timeout between different ends. invCtx, cancel := context.WithCancel(invocation.Context()) span, spanCtx := opentracing.StartSpanFromContext(invCtx, operationName) - invocation.SetContext(protocol.NewContextWith(spanCtx)) + invocation.SetContext(spanCtx) defer func() { span.Finish() cancel() diff --git a/protocol/context.go b/protocol/context.go deleted file mode 100644 index e2d22785ef695e907ed72481cd7d5aa5d124d6ad..0000000000000000000000000000000000000000 --- a/protocol/context.go +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package protocol - -import ( - "context" -) - -type Context struct { - context.Context -} - -func NewContext() Context { - return NewContextWith(context.Background()) -} -func NewContextWith(ctx context.Context) Context { - return Context{Context: ctx} -} diff --git a/protocol/invocation.go b/protocol/invocation.go index 5bc82e77e3338c69640286e35afd40b39090d1cb..baf6e5c0836395d104c03f912d4d26aedfcc038a 100644 --- a/protocol/invocation.go +++ b/protocol/invocation.go @@ -18,6 +18,7 @@ package protocol import ( + "context" "reflect" ) @@ -29,6 +30,6 @@ type Invocation interface { Attachments() map[string]string AttachmentsByKey(string, string) string Invoker() Invoker - Context() Context - SetContext(ctx Context) + Context() context.Context + SetContext(ctx context.Context) } diff --git a/protocol/invocation/rpcinvocation.go b/protocol/invocation/rpcinvocation.go index f56c9e9d04e225efca4512d000fd6a340fc7b16a..91a377a13c379625230df69f8f7eb2cb797e989b 100644 --- a/protocol/invocation/rpcinvocation.go +++ b/protocol/invocation/rpcinvocation.go @@ -18,6 +18,7 @@ package invocation import ( + "context" "reflect" "sync" ) @@ -39,7 +40,7 @@ type RPCInvocation struct { attachments map[string]string invoker protocol.Invoker lock sync.RWMutex - ctx protocol.Context + ctx context.Context } func NewRPCInvocation(methodName string, arguments []interface{}, attachments map[string]string) *RPCInvocation { @@ -47,11 +48,14 @@ func NewRPCInvocation(methodName string, arguments []interface{}, attachments ma methodName: methodName, arguments: arguments, attachments: attachments, + ctx: context.Background(), } } func NewRPCInvocationWithOptions(opts ...option) *RPCInvocation { - invo := &RPCInvocation{} + invo := &RPCInvocation{ + ctx: context.Background(), + } for _, opt := range opts { opt(invo) } @@ -120,11 +124,11 @@ func (r *RPCInvocation) SetCallBack(c interface{}) { r.callBack = c } -func (r *RPCInvocation) Context() protocol.Context { +func (r *RPCInvocation) Context() context.Context { return r.ctx } -func (r *RPCInvocation) SetContext(ctx protocol.Context) { +func (r *RPCInvocation) SetContext(ctx context.Context) { r.ctx = ctx }