next-axiom
Version:
Send WebVitals from your Next.js project to Axiom.
52 lines • 1.91 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const config_1 = require("../config");
const shared_1 = require("../shared");
const generic_1 = __importDefault(require("./generic"));
const ingestEndpoint = process.env.NEXT_PUBLIC_AXIOM_INGEST_ENDPOINT || process.env.AXIOM_INGEST_ENDPOINT || '';
class VercelConfig extends generic_1.default {
provider = 'vercel';
shouldSendEdgeReport = true;
region = process.env.VERCEL_REGION || undefined;
environment = process.env.NEXT_PUBLIC_VERCEL_ENV || process.env.VERCEL_ENV || process.env.NODE_ENV || '';
token = undefined;
axiomUrl = ingestEndpoint;
isEnvVarsSet() {
return (ingestEndpoint != undefined && ingestEndpoint != '') || !!this.customEndpoint;
}
getIngestURL(t) {
const url = new URL(this.axiomUrl);
url.searchParams.set('type', t.toString());
return url.toString();
}
getWebVitalsEndpoint() {
if (config_1.isBrowser && this.customEndpoint) {
return this.customEndpoint;
}
return `${this.proxyPath}/web-vitals`;
}
getLogsEndpoint() {
if (config_1.isBrowser && this.customEndpoint) {
return this.customEndpoint;
}
return config_1.isBrowser ? `${this.proxyPath}/logs` : this.getIngestURL(shared_1.EndpointType.logs);
}
wrapWebVitalsObject(metrics) {
return {
webVitals: metrics,
environment: this.environment,
};
}
injectPlatformMetadata(logEvent, source) {
logEvent.vercel = {
environment: this.environment,
region: this.region,
source: source,
};
}
}
exports.default = VercelConfig;
//# sourceMappingURL=vercel.js.map