Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remix instrumentation with Vercel Examples #36

Open
Rocinante89 opened this issue Feb 20, 2023 · 6 comments
Open

Remix instrumentation with Vercel Examples #36

Rocinante89 opened this issue Feb 20, 2023 · 6 comments

Comments

@Rocinante89
Copy link

Rocinante89 commented Feb 20, 2023

Hey! I'm trying to set up opentelemetry instrumentation with Remix hosted on Vercel. Will be outputting to DataDog, but that's another story. I currently have:

tracing.js

const { getNodeAutoInstrumentations } = require('@opentelemetry/auto-instrumentations-node');
const { NodeTracerProvider, ConsoleSpanExporter } = require('@opentelemetry/sdk-trace-node');
const { registerInstrumentations } = require('@opentelemetry/instrumentation');
const { RemixInstrumentation } = require('opentelemetry-instrumentation-remix');

const traceExporter = new ConsoleSpanExporter();
const tracerProvider = new NodeTracerProvider();

tracerProvider.addSpanProcessor(traceExporter);

tracerProvider.register();

registerInstrumentations({
  instrumentations: [
    getNodeAutoInstrumentations(),
    new RemixInstrumentation()
  ]
});

and package.json

"scripts": {
        "build:remix-routes": "remix-routes -o ./types",
        "build:remix": "remix build",
        "build": "run-s build:*",
        "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf .cache && rm -rf coverage && rm -rf api",
        "dev:remix-routes": "remix-routes -w -o ./types",
        "dev:open-telemetry": "node -r ./tracing.js",
        "dev:remix": "PORT=3000 REMIX_DEV_SERVER_WS_PORT=8002 remix dev",
        "dev": "run-p \"dev:*\"",
        "lint": "eslint --fix"
    },

I'm not sure if its working locally as nothing is being emitted from the ConsoleSpanExporter. I found the above tracing.js example in the repo, but on the Remix discord there was a different method. Can't get either to work as of yet. Any help would be really appreciated

@gnohj
Copy link

gnohj commented Apr 12, 2023

Any progress w/ this?

@Rocinante89
Copy link
Author

@gnohj didn't have time to continue with it

@WesleyYue
Copy link

Also have been trying to get the basic example with node -r ./tracing.js node_modules/.bin/remix dev working but don't see any traces in the console. Bumping this thread incase you guys made any progress?

@WesleyYue
Copy link

WesleyYue commented Jul 21, 2023

Ok, I figured out that you need to use the instrumentation with remix-serve, not remix dev, so you can use the node/express server. (I'm not sure what magic goes in remix dev). So to get it running locally, you need to:
yarn remix build
node -r ./tracing.js node_modules/.bin/remix-serve ./build

The part I still haven't figured out is how to achieve the --require flag when deployed on Vercel with the @vercel/remix run time. I asked here and here

@WesleyYue
Copy link

I've come to the conclusion that this is not possible at the moment because there is no way to inject the tracing.js before the remix/express server on Vercel. Even in Vercel's official otel integrations documentation, they are calling instrumentation.ts in the framework code, which would be too late. https://vercel.com/docs/concepts/observability/otel-overview/quickstart

I'm just going to manually trace the handleRequest and handleDataRequest in entry.server.ts

@unflxw
Copy link
Contributor

unflxw commented Jul 24, 2023

@WesleyYue Did you try setting NODE_OPTIONS="--require ./tracing.js as an environment variable? I have not tried it, but that, or a small wrapper script that calls node with the right arguments, might work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants