I am a little concerned that #43 and this follow-on commit may have broken things for users, but I'm also hopeful that some docs might clear things up. Wanted to surface this in case any other users encounter the same issue.
Here's the state of affairs: #43 and the follow-on commit added the ability to specify 1+ span processors for use by the SDK. When I try to pass the BatchTraceSpanProcessor in my config resolution function like so:
service core:user:example: Uncaught Error: Dynamic require of "node:buffer" is not supported
at index.js:12:9
at index.js:3965:25 in ../otel-cf-workers-example/node_modules/@microlabs/otel-cf-workers/dist/cjs/buffer.js
at index.js:18:50 in __require2
at index.js:14350:18 in ../otel-cf-workers-example/node_modules/@microlabs/otel-cf-workers/dist/cjs/index.js
at index.js:18:50 in __require2
at index.js:14369:29 in ../otel-cf-workers-example/dist/ResolveConfig.js
at index.js:18:50 in __require2
at index.js:14428:18 in ../otel-cf-workers-example/dist/index.js
at index.js:18:50 in __require2
I believe the error stems from this open workerd issue, which suggests that you must importNodeJS runtime APIs, rather than require them. If that's the case, then applications using this library would need to use the esmdist directory rather than the cjs one, since the cjs export includes the line const node_buffer_1 = require("node:buffer"); (whereas the esmdist directory uses import { Buffer } from 'node:buffer';).
I believe this issue is occurring because I have a package that was consuming otel-cf-workers as an ESM module but that package exported that package as a common JS module.
I am a little concerned that #43 and this follow-on commit may have broken things for users, but I'm also hopeful that some docs might clear things up. Wanted to surface this in case any other users encounter the same issue.
Here's the state of affairs: #43 and the follow-on commit added the ability to specify 1+ span processors for use by the SDK. When I try to pass the
BatchTraceSpanProcessor
in my config resolution function like so:I see the following when run my code in
wrangler
:I believe the error stems from this open
workerd
issue, which suggests that you mustimport
NodeJS runtime APIs, rather thanrequire
them. If that's the case, then applications using this library would need to use theesm
dist
directory rather than thecjs
one, since thecjs
export includes the lineconst node_buffer_1 = require("node:buffer");
(whereas theesm
dist
directory usesimport { Buffer } from 'node:buffer';
).This does not happen in
1.0.0-rc.7
, where we used to instantiate theBatchTraceSpanProcessor
within this library itself.Side note: is it possible to add a comment about why we're importing
Buffer
fromnode:buffer
here and adding it to theglobalThis
?I'll update this issue with my findings!