evanderkoogh / otel-cf-workers

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

[feature request]: Support for Cloudflare Pages #96

Open vanstinator opened 6 months ago

vanstinator commented 6 months ago

We're starting to use Cloudflare Pages at Plex for a new layer in our API. We're also heavy users of Datadog, and would like to be able to auto-instrument our Pages codebase so we have e2e traces across our backend stack.

I've been hacking on some support for this, and we have it working internally. Would you be interested in a taking a PR that adds support for CF Pages auto-instrumentation?

I have an in-progress hacked together branch on my fork https://github.com/evanderkoogh/otel-cf-workers/compare/main...vanstinator:otel-cf-workers:feat/cf-pages

The code ended up being almost identical to the fetch instrumentation. I think it will be relatively trivial to clean up my exploration work and land on a solution that extends the fetch functionality with a few additional lines of code and another function export.

If this sounds good I can probably schedule work to productionize the patch in the next month or two.

jahands commented 6 months ago

Hey @vanstinator! Your branch looks like a pretty good start to me. Definitely welcome to PRs to add Pages support!

dustinsmith1024 commented 6 months ago

@vanstinator - does Datadog provide a public trace endpoint or do you run your own public agent to send the data to?

vanstinator commented 6 months ago

For the time being we're going to be running an agent. I'm not sure how we'll expose it yet, those discussions are still happening internally.

jfsiii commented 5 months ago

I'd love to see this! We're running Remix on Workers Sites for now, but we won't be able to for long. The latest Remix (using Vite vs esbuild) doesn't support Workers Sites any longer because they're deprecated for full-stack apps

Screenshot 2024-04-13 at 4 04 55 PM

I'm working on the replacement now, and would be happy to help test this out

jfsiii commented 5 months ago

@vanstinator are you opposed to opening the PR now so this can be merged and allow others to debug/contribute?

As I mentioned we'll soon need to use Pages for our Remix app and I'd love to have this (or be able to debug/fix any issues I find while testing)

vanstinator commented 5 months ago

Hey @jfsiii I think I can make that happen. I'll lightly clean up my branch today and get a PR open!

vanstinator commented 5 months ago

The PR is up!

Pelps12 commented 1 month ago

Any progress on this issue?

evanderkoogh commented 4 weeks ago

Unfortunately not. I was forced to step back from maintaining this for the better part of a year and @jahands and co have done an amazing job at keeping the lights on, but didn't have a lot of time to work on adding new features.

I am back, so will spend some time over the next week or so to get my bearing and work on it again.

My first priority is to ship a 1.0 and get any breaking changes out of the way as much as I can. My next priority is to go through some of the PRs that implement new features and incorporate those too. That includes this one.

vanstinator commented 4 weeks ago

I left the job that was building this out, and I don't have any personal projects on CF-workers where I'd need this unfortunately.

n3oney commented 3 weeks ago

fwiw this seems to work for Next.js:

// instrumentation.ts

import { OTLPExporter } from "@microlabs/otel-cf-workers";
import { SimpleSpanProcessor } from "@opentelemetry/sdk-trace-node";
import { registerOTel } from "@vercel/otel";

export function register() {
  registerOTel({
    serviceName: "nextjs-app",
    spanProcessors: [
      // @ts-expect-error  for some reason the type doesn't match but it actually works
      new SimpleSpanProcessor(
        new OTLPExporter({
          url: "yourURL",
          headers: {
            // req headers
          },
        }),
      ),
    ],
  });
}