evanderkoogh / otel-cf-workers

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

Unable to use ConsoleSpanExporter #12

Closed lboynton closed 1 year ago

lboynton commented 1 year ago

As briefly discussed on Discord, I was hoping to be able to conditionally use the ConsoleSpanExporter in local development and not send traces to an external source. It seems like this should be possible since ExportConfig allows you to pass in a SpanExporter instance here, but doing the following:

import { ConsoleSpanExporter } from '@opentelemetry/sdk-trace-base';

const config: ResolveConfigFn = (env: Env, trigger) => {
    return {
        exporter: new ConsoleSpanExporter(),
        service: {
            name: name,
            version: version,
        },
    };
};

export default instrument(handler, config);

Results in this error:

Error reporting spans to exporter: TypeError: Cannot read properties of undefined (reading 'url')
    at checkedFetch (index.js:34:75)
    at OTLPExporter.send (index.js:6454:25)
    at index.js:6440:14
    at new Promise (<anonymous>)
    at OTLPExporter._export (index.js:6438:12)
    at OTLPExporter.export (index.js:6431:10)
    at index.js:6946:22
    at new Promise (<anonymous>)
    at Object.startExport (index.js:6945:21)
    at nextState (index.js:180:148
evanderkoogh commented 1 year ago

Yeah, that is certainly an issue then. It shouldn't be trying to initialise the OTLPExporter ofc. I'll take a look once I wrapped up the sampling stuff. I am soo close on that :)

evanderkoogh commented 1 year ago

Could you give 1.0.0-alpha.6 a go? I just released it and I technically got it to work. The only issues seems to be that the ConsoleSpanExporter uses console.dir, which I don't think isn't as well supported in workerd?

If that is indeed the case with you as well, I'll probably end up writing a proper console exporter a bit later..

lboynton commented 1 year ago

Yep this is working with the latest version now (1.0.0-rc.1), thanks! 🙏