Compare commits
1 Commits
fix/react-
...
feat/opent
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a0a2047305 |
@@ -66,10 +66,15 @@ const config = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
serverExternalPackages: ["pino"],
|
serverExternalPackages: [
|
||||||
|
"pino",
|
||||||
|
"@opentelemetry/sdk-node",
|
||||||
|
"@opentelemetry/auto-instrumentations-node",
|
||||||
|
"@opentelemetry/exporter-trace-otlp-http",
|
||||||
|
],
|
||||||
|
|
||||||
experimental: {
|
experimental: {
|
||||||
// instrumentationHook: true,
|
instrumentationHook: true,
|
||||||
swcPlugins: [["@lingui/swc-plugin", {}]],
|
swcPlugins: [["@lingui/swc-plugin", {}]],
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,10 @@
|
|||||||
"@lingui/macro": "^5.3.2",
|
"@lingui/macro": "^5.3.2",
|
||||||
"@lingui/react": "^5.3.2",
|
"@lingui/react": "^5.3.2",
|
||||||
"@novu/api": "^3.11.0",
|
"@novu/api": "^3.11.0",
|
||||||
|
"@opentelemetry/api": "^1.9.0",
|
||||||
|
"@opentelemetry/auto-instrumentations-node": "^0.71.0",
|
||||||
|
"@opentelemetry/exporter-trace-otlp-http": "^0.213.0",
|
||||||
|
"@opentelemetry/sdk-node": "^0.213.0",
|
||||||
"@t3-oss/env-nextjs": "^0.11.1",
|
"@t3-oss/env-nextjs": "^0.11.1",
|
||||||
"@tailwindcss/typography": "^0.5.16",
|
"@tailwindcss/typography": "^0.5.16",
|
||||||
"@tanstack/react-query": "catalog:",
|
"@tanstack/react-query": "catalog:",
|
||||||
|
|||||||
32
apps/web/src/instrumentation.ts
Normal file
32
apps/web/src/instrumentation.ts
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
export async function register() {
|
||||||
|
if (
|
||||||
|
process.env.NEXT_RUNTIME !== "nodejs" ||
|
||||||
|
process.env.NEXT_PUBLIC_KAN_ENV !== "cloud" ||
|
||||||
|
!process.env.AXIOM_TOKEN ||
|
||||||
|
!process.env.AXIOM_DATASET
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { NodeSDK } = await import("@opentelemetry/sdk-node");
|
||||||
|
const { OTLPTraceExporter } = await import("@opentelemetry/exporter-trace-otlp-http");
|
||||||
|
const { getNodeAutoInstrumentations } = await import("@opentelemetry/auto-instrumentations-node");
|
||||||
|
|
||||||
|
const sdk = new NodeSDK({
|
||||||
|
serviceName: "kan",
|
||||||
|
traceExporter: new OTLPTraceExporter({
|
||||||
|
url: "https://api.axiom.co/v1/traces",
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${process.env.AXIOM_TOKEN}`,
|
||||||
|
"X-Axiom-Dataset": process.env.AXIOM_DATASET,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
instrumentations: [
|
||||||
|
getNodeAutoInstrumentations({
|
||||||
|
"@opentelemetry/instrumentation-fs": { enabled: false },
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
sdk.start();
|
||||||
|
}
|
||||||
@@ -20,6 +20,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@axiomhq/js": "^1.4.0",
|
"@axiomhq/js": "^1.4.0",
|
||||||
|
"@opentelemetry/api": "^1.9.0",
|
||||||
"pino": "^9.14.0",
|
"pino": "^9.14.0",
|
||||||
"pino-pretty": "^13.1.3"
|
"pino-pretty": "^13.1.3"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { Axiom } from "@axiomhq/js";
|
import { Axiom } from "@axiomhq/js";
|
||||||
|
import { trace } from "@opentelemetry/api";
|
||||||
import pino from "pino";
|
import pino from "pino";
|
||||||
|
|
||||||
const isDev = process.env.NODE_ENV !== "production";
|
const isDev = process.env.NODE_ENV !== "production";
|
||||||
@@ -9,7 +10,10 @@ const axiomToken = process.env.AXIOM_TOKEN;
|
|||||||
const axiomDataset = process.env.AXIOM_DATASET;
|
const axiomDataset = process.env.AXIOM_DATASET;
|
||||||
const useAxiom = isCloud && !!axiomToken && !!axiomDataset;
|
const useAxiom = isCloud && !!axiomToken && !!axiomDataset;
|
||||||
|
|
||||||
function createAxiomStream(token: string, dataset: string): pino.DestinationStream {
|
function createAxiomStream(
|
||||||
|
token: string,
|
||||||
|
dataset: string,
|
||||||
|
): pino.DestinationStream {
|
||||||
const client = new Axiom({ token });
|
const client = new Axiom({ token });
|
||||||
return {
|
return {
|
||||||
write(msg: string) {
|
write(msg: string) {
|
||||||
@@ -35,9 +39,25 @@ export const logger = useAxiom
|
|||||||
...(isDev && {
|
...(isDev && {
|
||||||
transport: {
|
transport: {
|
||||||
target: "pino-pretty",
|
target: "pino-pretty",
|
||||||
options: { colorize: true, ignore: "pid,hostname", translateTime: "HH:MM:ss" },
|
options: {
|
||||||
|
colorize: true,
|
||||||
|
ignore: "pid,hostname",
|
||||||
|
translateTime: "HH:MM:ss",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const createLogger = (module: string) => logger.child({ module });
|
function getTraceContext(): { traceId?: string; spanId?: string } {
|
||||||
|
try {
|
||||||
|
const span = trace.getActiveSpan();
|
||||||
|
if (!span) return {};
|
||||||
|
const ctx = span.spanContext();
|
||||||
|
return { traceId: ctx.traceId, spanId: ctx.spanId };
|
||||||
|
} catch {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const createLogger = (module: string) =>
|
||||||
|
logger.child({ module, ...getTraceContext() });
|
||||||
|
|||||||
1520
pnpm-lock.yaml
generated
1520
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user