evanderkoogh / otel-cf-workers

An OpenTelemetry compatible library for instrumenting and exporting traces for Cloudflare Workers
BSD 3-Clause "New" or "Revised" License
208 stars 39 forks source link

getTracer + startActiveSpan not working due to missing global patch #109

Closed hunterclarke closed 2 months ago

hunterclarke commented 3 months ago

Hi! Having some trouble creating new tracers and spans.

"@microlabs/otel-cf-workers": "1.0.0-rc.29",
"@opentelemetry/api": "^1.8.0",

You can see my handler here: https://github.com/spackleso/spackle/blob/main/apps/api/src/index.ts#L69 and my middleware here: https://github.com/spackleso/spackle/blob/main/apps/api/src/lib/hono/otel.ts

I believe the problem is similar to https://github.com/evanderkoogh/otel-cf-workers/issues/75. However, in this case, the global patch works fine for the otel-cf-workers tracers (I see fetchHandler and export) but not for any outside of the library.

So any traces coming from my custom tracer never make it to the exporter.

Any ideas? Thanks!

DaniFoldi commented 2 months ago

Hi,

I believe you're also running into the same issue as https://github.com/evanderkoogh/otel-cf-workers/issues/115#issuecomment-2041365703 - please see my comment there for a detailed explanation. The current solution is to pin opentelemetry/api to 1.6.x, which resolves to the same version that the lib uses internally, so it should work.

hunterclarke commented 2 months ago

That fixed it. I'll close this in favor of the other issue. Thanks!