Closed palp closed 1 year ago
Hmm.. that is certainly interesting. It shouldn't be possible for getActiveConfig
to return undefined
. But I just realised that it is possible to do a blockConcurrencyWhile
in the constructor. And it might be possible for there not to be a config set.
Do you have that scenario in this particular case?
Hmm.. that is certainly interesting. It shouldn't be possible for
getActiveConfig
to returnundefined
. But I just realised that it is possible to do ablockConcurrencyWhile
in the constructor. And it might be possible for there not to be a config set.Do you have that scenario in this particular case?
Yep, there is a call to storage inside a blockConcurrencyWhile
call which is triggering it.
Yes, I have confirmed reproduction with this test class:
import { instrumentDO, ResolveConfigFn } from '@microlabs/otel-cf-workers'
export interface Env {
OTEL_BASIC_AUTH: string;
OTEL_URL: string;
}
class TestDO implements DurableObject {
constructor(state: DurableObjectState, env: Env) {
state.blockConcurrencyWhile(async () => {
await state.storage.list({ prefix: 'test' })
})
}
async fetch(request: Request) {
return new Response('Hello world!', { status: 200 })
}
}
const config: ResolveConfigFn = (env: Env, _trigger) => {
return {
exporter: { url: env.OTEL_URL, headers: { 'Authorization': `Basic ${env.OTEL_BASIC_AUTH}` } },
service: { name: 'test'},
}
}
const TestOtelDO = instrumentDO(TestDO, config)
export { TestOtelDO }
Note it only fails if the worker calling the DO is also instrumented, otherwise it seems to work as expected.
Awesome! Thanks for the repro.. I am trying to work out the best way to fix this. Hopefully I'll have it fixed in the next few hours :)
Ok.. a fix for this should be released as part of 1.0.0-rc3
. The only annoying thing is that the constructor has to be in its own trace, because the fetch
method hasn't been called and thus we have no idea what trace (or traces even) are waiting for the constructor to finish.
I'm observing this issue when running tests locally with miniflare
where at some point getActiveConfig
starts returning undefined
. I'll continue investigating, I've opened https://github.com/evanderkoogh/otel-cf-workers/issues/20 as a workaround.
EDIT: it looks related to how miniflare re-initializes the DO in between requests.
Also got the error in production in a DurableObject, not sure why but the pattern is globally:
DOClass
this.something = new SomethingWithStorage(this.state.storage)
this.something.doSOmething()
which uses the storageUsing 1.0.0-rc.6
Also getting this same error, same exact situation and repro as @SamyPesse
I have not attempted a simple repro so I don't know the root cause of this, but this error occurs in my worker reliably:
I was able to resolve it by modifying
getActiveConfig
to return a default value instead of undefined, but this may or may not be appropriate/desired behavior. https://github.com/evanderkoogh/otel-cf-workers/compare/main...palp:otel-cf-workers:main