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

Instrumentation breaks new RPC style service calls #116

Open
johtso opened this issue Apr 6, 2024 · 12 comments
Open

Instrumentation breaks new RPC style service calls #116

johtso opened this issue Apr 6, 2024 · 12 comments

Comments

@johtso
Copy link

johtso commented Apr 6, 2024

https://blog.cloudflare.com/javascript-native-rpc

If you instrument your worker, and it tries to call a method on a bound service using the new RPC style, you get a TypeError: Illegal invocation error.

[wrangler:err] TypeError: Illegal invocation
    at [object Object]
    at Object.get (file:///xxxxxx/node_modules/.pnpm/@[email protected]/node_modules/@microlabs/otel-cf-workers/src/instrumentation/kv.ts:114:23)
    at proxyHandler.get (file:///xxxxxx/node_modules/.pnpm/@[email protected]/node_modules/@microlabs/otel-cf-workers/src/wrap.ts:23:20)
    at xxxxxxx
@DaniFoldi
Copy link
Contributor

Hey,

Thanks for filing this. I think #104 should fix this (skip any RPC bindings for now until we have proper instrumentation for them). cc @jahands what do you think about a prerelease?

@jahands
Copy link
Collaborator

jahands commented Apr 7, 2024

Should be fixed in @microlabs/[email protected] @johtso can you please test and confirm?

@johtso
Copy link
Author

johtso commented Apr 7, 2024

Should be fixed in @microlabs/[email protected] @johtso can you please test and confirm?

Seems to be working!

I'm guessing there's no way to get tracing between a worker and a called RPC service atm, even with manual steps right?

Do you think there might be a way to at least do manual traces from inside a named service?

@johtso
Copy link
Author

johtso commented Apr 7, 2024

Hmm, also my custom spans don't seem to be working anymore..

	await ping()
	const span = tracer.startSpan('parsePdf');
	const pdfData = await env.PDFPARSER_SERVICE.parsePdf(request);
	await ping()
	span.end()

@DaniFoldi
Copy link
Contributor

Hey, could you elaborate on "don't seem to be working" a bit, please - please make sure you have no sampling on, and for debugging could you console.log spans (and return spans) in your postProcessor, making sure to redact any sensitive information before posting.

@johtso
Copy link
Author

johtso commented Apr 9, 2024

@DaniFoldi ah, it was this issue and this fix.. #115 (comment)

@DaniFoldi
Copy link
Contributor

Glad to hear you managed to fix it. I have it on my todo list to set up peerDependencies properly

@khiller-cf
Copy link

Should be fixed in @microlabs/[email protected] @johtso can you please test and confirm?

The fix released here appears to have broken regular service bindings (no RPC). The isJRPC call matches any service bound worker, not just the JS-native RPC calls. I'm trying to find a fix for this, but identifying a way to discriminate between them accurately has proved elusive.

@DaniFoldi
Copy link
Contributor

Hey @khiller-cf,

I believe you're right, since there are no _non_JSRPC service bindings, we currently miss instrumenting all of them. The initial fix was just to avoid matching them as anything, as they would've had all imaginable properties.

Are you able to test the following change in instrumentation/env.ts:

			if (isJSRPC(item)) {
				// TODO instrument JSRPC and maybe remove serviceBinding?
				return instrumentServiceBinding(item, String(prop))
			} else if (isKVNamespace(item)) {

The current (temporary) solution passes any JSRPC found back without instrumentation, this change would at least instrument fetch again. We'll have to figure out a way to pass context around without interfering with user code for the true RPC stuff.

@khiller-cf
Copy link

That resolves the issue for me. Appreciate you looking at this!

@DaniFoldi
Copy link
Contributor

Glad to hear, I have a PR #135 open that upstreams this change. Now we just need @jahands to approve and release 😁

@jahands
Copy link
Collaborator

jahands commented May 6, 2024

Released in 1.0.0-rc.38 - thanks!

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

4 participants