Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Context cannot be transferred across services #418

Open
Tiper-In-Github opened this issue Aug 13, 2024 · 5 comments
Open

Context cannot be transferred across services #418

Tiper-In-Github opened this issue Aug 13, 2024 · 5 comments

Comments

@Tiper-In-Github
Copy link
Contributor

description

I tried passing the context in RPC() and RPCTo() in V2, but the receiving end always received an empty context. I checked the context when sending through a breakpoint and confirmed that it contained the information I expected.
Is this by design or an exception?
(💡which prevents me from using opentelemetry to track links across services)

Code Snippet:

// Send
newCtx = context.WithValue(newCtx, "Test", "119991")
if err := app.RPC(newCtx, "Preview.Remote.sync", rpcResp, rpcReq); err != nil {
  logger.Log.Errorf("%v%v rpcFail:", logPrefix, err.Error())
  span.AddEvent("rpcFail:" + err.Error())
  return false
}

// Receiver
func (r *PreviewRemoteHandler) Sync(c context.Context, req *rpcProtobuf.ReqSync) (*rpcProtobuf.RespSync, error) {
	logger.Log.Infof("test context:%v", c.Value("Test"))
        ......
}

Expected results:

test context:119991

Actual results:

test context:<nil>

@Tiper-In-Github
Copy link
Contributor Author

@felipejfc Hope to see this issue soon

@felipejfc
Copy link
Contributor

You're right, ctx is currently not propagated. However, there's default integration with Opentelemetry already in master branch. See the docs. Here
If you want to propagate more values between calls you can use the "Propagated Context" utility which is the same one we use for default opentelemetry integration.
See here https://github.com/topfreegames/pitaya/blob/main/pkg/context/context.go#L30-L44

@Tiper-In-Github
Copy link
Contributor Author

Thanks,In the future, are there plans to support propagation to enable cross-service link tracking?

@felipejfc
Copy link
Contributor

Can you be more specific about which kind of key/values you will be propagating?
Also, does this manual propagation method fits your needs?

I'm thinking about a more transparent way of context propagation that will happen automatically, so gathering some info on use cases would be helpful

@Tiper-In-Github
Copy link
Contributor Author

We hope to use OpenTelemetry while passing the engine's existing 'request_id' to provide more detailed and convenient tracking and logging.Since we are using V2, we are connecting to opentelemetry ourselves

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants