-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Correctly access FPX_ENDPOINT in a Node runtime * Add a log statement where something is going wrong in node.js apps * Add sample node app * Update readme * Fix the "always crashing" support in Node * Remove console.log * Use a utility to detect whether or not to serialize env * Record env vars in node * Add a POST route to node api * Format sample node app * Fix the typing of app.fetch for Node envs * Update get started to include Node, and write a simple Platform component * Update callout * Stop fighting biome. Whatever. * Update tab keys for platforms * Use double quotes * Clean up Platforms.astro * Manually format like a goober * Update client library otel package json * Refactor how we access env vars a bit to tidy things up * Pass the og env to the measured fetch function * Gosh darn website linting * Format format format * Do not lint my examples i sorry * Okay do not use ts extension for example code i soz * Clean up accessing FPX_ENDPOINT * Patch issue with logging functions
- Loading branch information
Showing
20 changed files
with
336 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
FPX_ENDPOINT=http://localhost:8788/v1/traces |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# dev | ||
.yarn/ | ||
!.yarn/releases | ||
.vscode/* | ||
!.vscode/launch.json | ||
!.vscode/*.code-snippets | ||
.idea/workspace.xml | ||
.idea/usage.statistics.xml | ||
.idea/shelf | ||
|
||
# deps | ||
node_modules/ | ||
|
||
# env | ||
.env | ||
.env.production | ||
|
||
# logs | ||
logs/ | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
pnpm-debug.log* | ||
lerna-debug.log* | ||
|
||
# misc | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
```sh | ||
pnpm install | ||
cp .env.example .env | ||
pnpm dev | ||
``` | ||
|
||
```sh | ||
open http://localhost:8787 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "node-api", | ||
"scripts": { | ||
"dev": "tsx watch src/index.ts", | ||
"debug": "tsx --inspect-brk src/index.ts" | ||
}, | ||
"dependencies": { | ||
"@fiberplane/hono-otel": "workspace:*", | ||
"@hono/node-server": "^1.12.2", | ||
"hono": "^4.5.9" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^20.11.17", | ||
"tsx": "^4.7.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { instrument } from "@fiberplane/hono-otel"; | ||
import { serve } from "@hono/node-server"; | ||
import { config } from "dotenv"; | ||
import { Hono } from "hono"; | ||
|
||
// Load environment variables from .env file | ||
config(); | ||
|
||
const app = new Hono(); | ||
|
||
app.get("/", (c) => { | ||
console.log("Hello Hono!"); | ||
return c.text("Hello Hono!"); | ||
}); | ||
|
||
app.get("/function", (c) => { | ||
helloFunction(); | ||
console.log(helloFunction, "that was a function"); | ||
return c.text("Hello function!"); | ||
}); | ||
|
||
function helloFunction() { | ||
console.log("Hello function!"); | ||
} | ||
|
||
app.post("/json", async (c) => { | ||
const body = await c.req.json(); | ||
console.log("json body", body); | ||
return c.json({ message: "Hello Json!", body }); | ||
}); | ||
|
||
const port = 8787; | ||
console.log(`Server is running on port http://localhost:${port}`); | ||
|
||
serve({ | ||
fetch: instrument(app).fetch, | ||
port, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ESNext", | ||
"module": "ESNext", | ||
"moduleResolution": "Bundler", | ||
"strict": true, | ||
"skipLibCheck": true, | ||
"types": [ | ||
"node" | ||
], | ||
"jsx": "react-jsx", | ||
"jsxImportSource": "hono/jsx", | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
"author": "Fiberplane<[email protected]>", | ||
"type": "module", | ||
"main": "dist/index.js", | ||
"version": "0.1.0-beta.12", | ||
"version": "0.2.0-beta.1", | ||
"dependencies": { | ||
"@opentelemetry/api": "~1.9.0", | ||
"@opentelemetry/exporter-trace-otlp-http": "^0.52.1", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* In Hono-node environments, env vars are not available on the `env` object that's passed to `app.fetch`. | ||
* This helper will also check process.env and fallback to that if the env var is not present on the `env` object. | ||
*/ | ||
export function getFromEnv(honoEnv: unknown, key: string) { | ||
const env = getNodeSafeEnv(honoEnv); | ||
|
||
return typeof env === "object" && env !== null | ||
? (env as Record<string, string | null>)?.[key] | ||
: null; | ||
} | ||
|
||
/** | ||
* Return `process.env` if we're in Node.js, otherwise `honoEnv` | ||
* | ||
* Used to get the env object for accessing and recording env vars. | ||
* This eixsts because in Node.js, the `env` object passed to `app.fetch` is different from the env object in other runtimes. | ||
* | ||
* @param honoEnv - The env object from the `app.fetch` method. | ||
* @returns - `process.env` if we're in Node.js, otherwise `honoEnv`. | ||
*/ | ||
export function getNodeSafeEnv(honoEnv: unknown) { | ||
const hasProcessEnv = runtimeHasProcessEnv(); | ||
const isRunningInHonoNode = isHonoNodeEnv(honoEnv); | ||
return hasProcessEnv && isRunningInHonoNode ? process.env : honoEnv; | ||
} | ||
|
||
function runtimeHasProcessEnv() { | ||
if (typeof process !== "undefined" && typeof process.env !== "undefined") { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* Helper to determine if the env is coming from a Hono node environment. | ||
* | ||
* In Node.js, the `env` passed to `app.fetch` is an object with keys "incoming" and "outgoing", | ||
* one of which has circular references. We don't want to serialize this. | ||
*/ | ||
function isHonoNodeEnv(env: unknown) { | ||
if (typeof env !== "object" || env === null) { | ||
return false; | ||
} | ||
const envKeys = Object.keys(env).map((key) => key.toLowerCase()); | ||
return ( | ||
envKeys.length === 2 && | ||
envKeys.includes("incoming") && | ||
envKeys.includes("outgoing") | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.