@logtail/next
Version:
Better Stack Telemetry Next.js client
59 lines • 2.46 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const shared_1 = require("../shared");
const config_1 = require("../config");
// This is the generic config class for all platforms that doesn't have a special
// implementation (e.g: vercel, netlify). All config classes extends this one.
class GenericConfig {
constructor() {
this.proxyPath = '/_betterstack';
this.shouldSendEdgeReport = false;
this.token = process.env.NEXT_PUBLIC_BETTER_STACK_SOURCE_TOKEN || process.env.BETTER_STACK_SOURCE_TOKEN || process.env.NEXT_PUBLIC_LOGTAIL_SOURCE_TOKEN || process.env.LOGTAIL_SOURCE_TOKEN;
this.environment = process.env.NODE_ENV;
this.ingestingUrl = process.env.NEXT_PUBLIC_BETTER_STACK_INGESTING_URL || process.env.BETTER_STACK_INGESTING_URL || process.env.NEXT_PUBLIC_LOGTAIL_URL || process.env.LOGTAIL_URL;
this.region = process.env.REGION || undefined;
this.customEndpoint = process.env.NEXT_PUBLIC_BETTER_STACK_CUSTOM_ENDPOINT;
}
isEnvVarsSet() {
return !!(this.ingestingUrl && this.token) || !!this.customEndpoint;
}
getIngestURL(_) {
return this.ingestingUrl || "";
}
getLogsEndpoint() {
if (config_1.isBrowser && this.customEndpoint) {
return this.customEndpoint;
}
return config_1.isBrowser ? `${this.proxyPath}/logs` : this.getIngestURL(shared_1.EndpointType.logs);
}
getWebVitalsEndpoint() {
if (config_1.isBrowser && this.customEndpoint) {
return this.customEndpoint;
}
return config_1.isBrowser ? `${this.proxyPath}/web-vitals` : this.getIngestURL(shared_1.EndpointType.webVitals);
}
wrapWebVitalsObject(metrics) {
return metrics.map(m => ({
webVital: m,
dt: new Date().getTime(),
platform: {
environment: this.environment,
source: 'web-vital',
},
source: 'web-vital'
}));
}
injectPlatformMetadata(logEvent, source) {
logEvent.source = source;
logEvent.platform = {
environment: this.environment,
region: this.region,
source: source,
};
}
getHeaderOrDefault(req, headerName, defaultValue) {
return req.headers[headerName] ? req.headers[headerName] : defaultValue;
}
}
exports.default = GenericConfig;
//# sourceMappingURL=generic.js.map