Deno
Traces | Metrics | App Logs | Custom Logs | Profiling |
---|---|---|---|---|
✅ | ✖ | ✖ | ✅ | ✖ |
This guide walks you through setting up Application Performance Monitoring (APM) on a Deno application. These instructions can also be found on the Installation page in your Middleware Account. View example code here.
Prerequisites
1 MW Host Agent
Middleware Host Agent (MW Agent). To install the MW Agent, see our Installation Guide.
2 Deno Version
Deno version 1.41.2
or above. Check your Deno version with the following command:
Shell
deno --version
Install
Step 1: Import dependencies
Import necessary packages into your Deno project from the Deno standard library and middlewareio library:
index.ts
import { serve } from "https://deno.land/[email protected]/http/server.ts"; import { track, httpTracer, info, warn, error, debug } from "https://deno.land/x/[email protected]/mod.ts";
Step 2: Configure Tracing
Trace network requests with the following track()
function:
track({ serviceName: '{SERVICE_NAME}', target: 'https://{ACCOUNT-UID}.middleware.io:443', accessToken: "<MW_API_KEY>", })
Step 3: Define Request Handler
Define how your server responds to incoming HTTP requests with the following function:
index.ts
function handler(_req: Request): Response { const data = { message: `Hello world!`, }; return new Response(JSON.stringify(data), { headers: { 'Content-Type': 'application/json' } }); }
Step 4: Start Your Server
Start an HTTP server with the serve
function:
index.ts
await serve(httpTracer(handler));
Step 5: Logging [Optional]
Add additional logging information with the following functions:
index.ts
info("info"); warn("warn"); error("error"); debug("debug");
Hono Framework
To use Middleware with the Hono framework, follow the example below:
import { Hono } from "https://deno.land/x/[email protected]/mod.ts"; import { debug, error, httpTracer, info, track, warn, } from "https://deno.land/x/[email protected]/mod.ts";
Need assistance or want to learn more about Middleware? Contact our support team in Slack.