Zuplo Changelog
We release improvements, new features, and fixes daily. Follow along here to see the most important updates.
New Relic Logging Plugin
We've expanded our range of third-party logging plugins yet again—this time with the addition of New Relic.
Full details can be found in the documentation, but usage follows the same pattern as all the other loggers.
Add the plugin to the Zuplo runtime and configure your options.
import {
RuntimeExtensions,
NewRelicLoggingPlugin,
environment,
} from "@zuplo/runtime";
export function runtimeInit(runtime: RuntimeExtensions) {
runtime.addPlugin(
new NewRelicLoggingPlugin({
// Optional, defaults to "https://log-api.newrelic.com/log/v1"
url: "https://log-api.newrelic.com/log/v1",
apiKey: environment.NEW_RELIC_API_KEY,
service: "MyAPI", // Optional, defaults to "Zuplo"
fields: {
field1: "value1",
field2: "value2",
},
}),
);
}
As with all our loggers, the New Relic Plugin supports custom fields in addition to the standard fields.
New Pre-Routing Hook
The new Pre-Routing Hook allows you to manipulate an incoming request before it's checked for routing. For example, if you want all routes to be case insensitive you could just lowercase the URL as it comes into the gateway, as shown below:
runtime.addPreRoutingHook(async (request) => {
const nr = new Request(request.url.toLowerCase(), request);
return nr;
});
Another example would be URL path normalization to remove trailing slashes:
runtime.addPreRoutingHook(async (request) => {
const url = new URL(request.url);
if (url.pathname.length > 1 && url.pathname.endsWith("/")) {
url.pathname = url.pathname.slice(0, -1);
const nr = new Request(url, request);
return nr;
}
return request;
});
Keep in mind that this will run on all requests so the code you use here needs to be appropriately performant and aware it can generate weird downstream effects by changing URLs and headers.
The method is async but reading and manipulating the request body is not recommended for performance reasons.
Custom Fields Available on All Logging Policies
A new fields
option is now available across all
logging plugins. This addition
enables you to append arbitrary custom fields to each log entry, providing
additional context and information in your logs.
For example, using our Google Cloud Logging plugin:
import {
RuntimeExtensions,
GoogleCloudLoggingPlugin,
environment,
} from "@zuplo/runtime";
export function runtimeInit(runtime: RuntimeExtensions) {
runtime.addPlugin(
new GoogleCloudLoggingPlugin({
logName: "projects/my-project/logs/my-api",
serviceAccountJson: environment.GCP_SERVICE_ACCOUNT,
fields: {
myCustomField: "value",
anotherCustomField: "value2",
},
}),
);
}
You can use this feature to include relevant metadata, application-specific details, or contextual information that may be useful for debugging or analysis purposes.
Better Local Dev Errors
When your API throws an error in local development, you will now see a formatted output that includes the error message and stack trace in a more readable format. This will help you quickly identify the issue and debug your application.
Local Development Log Enhancements
We have overhauled the local development logs to provide a cleaner and more useful output. The new logs make it easier to see the HTTP method, route, and status code for each request. This will help you quickly identify issues and debug your application.
The logs are now color-coded to make it easier to distinguish between different HTTP methods and errors are highlighted in red. Additionally, the logs are now formatted in a more readable way, making it easier to scan through the output.
Create Zuplo API Improvements
We have made a number of improvements to the create-zuplo-api
package to make
it even easier to start a Zuplo API project locally. The updated package
includes the following enhancements:
- Option to include ESLint and Prettier configuration files in the project
- Improved error handling and messaging
- Automatically installing dependencies after project creation