@borderless/worker-aws-xray
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

Worker AWS X-Ray

NPM version NPM downloads Build status Test coverage

AWS X-Ray client for Cloudflare Workers using fetch.

Installation

npm install @borderless/worker-aws-xray --save

Usage

import { AwsXray, Segment, captureFetch } from "@borderless/worker-aws-xray";

// Capture `fetch` with tracing support.
const fetch = captureFetch(globalThis.fetch);

// Create an AWS X-Ray client wrapper (for sending segments later).
const client = new AwsXray({
  region: "us-west-2",
  accessKeyId: "abc",
  secretAccessKey: "123",
});

addEventListener("fetch", async (event) => {
  const segment = new Segment("worker");

  // Create a subsegment attached to `segment`.
  const subsegment = segment.startSegment();

  // Trace `fetch` requests with our captured client.
  const res = await fetch("http://example.com", { segment: subsegment });

  // Segments must be ended before tracing.
  subsegment.end();
  segment.end();

  // Forward traced segments to AWS.
  event.waitUntil(client.traceSegment(segment));

  // Finally respond to Cloudflare request.
  event.respondWith(res);
});

License

MIT

Dependents (0)

Package Sidebar

Install

npm i @borderless/worker-aws-xray

Weekly Downloads

3

Version

1.1.1

License

MIT

Unpacked Size

65.8 kB

Total Files

9

Last publish

Collaborators

  • blakeembrey