DEV Community

Hong Minhee
Hong Minhee

Posted on

Fedify 1.3.0: OpenTelemetry support & enhanced message queue

We're excited to announce the release of Fedify 1.3.0, bringing significant improvements in observability, message queue configuration, and developer experience. This version introduces several new features and enhancements that make it easier to build and monitor federated server applications.

OpenTelemetry integration

The headline feature of this release is comprehensive OpenTelemetry support. Fedify now automatically instruments various operations with OpenTelemetry spans, providing detailed insights into your application's behavior. This feature enables you to:

  • Track HTTP requests and responses with detailed timing information
  • Monitor actor and collection dispatching
  • Observe inbox and outbox operations
  • Analyze signature verification processes
  • And much more!

Setting up OpenTelemetry in your Fedify application is straightforward. Once you configure the OpenTelemetry SDK, Fedify automatically creates spans for various operations. Here's a quick example:

import { NodeSDK } from "@opentelemetry/sdk-node";
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-proto";

const sdk = new NodeSDK({
  serviceName: "my-fedify-app",
  traceExporter: new OTLPTraceExporter({
    url: "http://localhost:4317",
  }),
});

sdk.start();
Enter fullscreen mode Exit fullscreen mode

You can also integrate with Sentry's OpenTelemetry support:

import { createFederation } from "@fedify/fedify";
import { getClient } from "@sentry/node";

const federation = createFederation({
  tracerProvider: getClient()?.traceProvider,
  // ... other options
});
Enter fullscreen mode Exit fullscreen mode

Note that Sentry's OpenTelemetry integration is available since @sentry/node 8.0.0, but it's not yet available in @sentry/deno or @sentry/bun as of November 2024.

For a complete list of instrumented spans and their attributes, check out our OpenTelemetry documentation.

Enhanced message queue configuration

Fedify 1.3.0 introduces the ability to configure different message queues for incoming and outgoing activities. This feature provides greater flexibility in handling different types of activities. You can:

  • Use different message queues for incoming and outgoing activities
  • Use a message queue only for incoming activities
  • Use a message queue only for outgoing activities
  • Or any combination thereof

Here are some configuration examples:

Using different queues for incoming and outgoing activities:

import { createFederation } from "@fedify/fedify";
import { RedisMessageQueue } from "@fedify/redis";
import { PostgresMessageQueue } from "@fedify/postgres";

const federation = createFederation({
  queue: {
    inbox: new PostgresMessageQueue(postgres("postgresql://...")),
    outbox: new RedisMessageQueue(redis),
  },
  // ... other options
});
Enter fullscreen mode Exit fullscreen mode

Using a message queue only for incoming activities:

const federation = createFederation({
  queue: {
    inbox: new PostgresMessageQueue(postgres("postgresql://...")),
    // outbox is not provided; outgoing activities will not be queued
  },
  // ... other options
});
Enter fullscreen mode Exit fullscreen mode

Manual activity routing

You can now manually route activities to inbox listeners without requiring an actual HTTP request. This is particularly useful when you need to process an Activity object enclosed within another Activity. For example:

federation.setInboxListeners("/users/{identifier}/inbox", "/inbox")
  .on(Announce, async (ctx, announce) => {
    const object = await announce.getObject();
    if (object instanceof Activity) {
      // Route the enclosed activity to the appropriate inbox listener
      await ctx.routeActivity(ctx.recipient, object);
    }
  });
Enter fullscreen mode Exit fullscreen mode

For details, see also the related documentation.

SvelteKit integration

Thanks to the contribution from Jiyu Park (@robin_maki@planet.moe), Fedify now officially supports SvelteKit through the new @fedify/fedify/x/sveltekit module. This integration makes it easier to build federated applications with SvelteKit:

import { createFederation } from "@fedify/fedify";
import { fedifyHook } from "@fedify/fedify/x/sveltekit";

const federation = createFederation({
  // ... your configuration
});

export const handle = fedifyHook(federation, (req) => "context data");
Enter fullscreen mode Exit fullscreen mode

For details, see also the related documentation.

Better HTTP request identification

Fedify now includes proper User-Agent headers in all HTTP requests it makes. This makes it easier to identify and track Fedify-generated requests in server logs. The default format is:

Fedify/1.3.0 (Deno/2.1.2)
Enter fullscreen mode Exit fullscreen mode

You can customize this by providing your own user agent string or options:

createFederation({
  userAgent: {
    software: "MyApp/1.0.0",
    url: "https://myinstance.com/"
  },
  // ... other options
});
Enter fullscreen mode Exit fullscreen mode

Other improvements

  • Context.sendActivity() and InboxContext.forwardActivity() methods now properly reject when they fail to enqueue tasks
  • Various bug fixes and performance improvements
  • Enhanced documentation and examples

Upgrading to 1.3.0

Fedify 1.3.0 is available on both JSR and npm. To upgrade:

For JSR (Deno):

deno add jsr:@fedify/fedify@1.3.0
Enter fullscreen mode Exit fullscreen mode

For npm (Node.js and Bun):

npm  add @fedify/fedify@1.3.0
pnpm add @fedify/fedify@1.3.0
yarn add @fedify/fedify@1.3.0
bun  add @fedify/fedify@1.3.0 
Enter fullscreen mode Exit fullscreen mode

Looking forward

We're excited about these new features and improvements, and we believe they'll make building federated applications with Fedify even more enjoyable. Stay tuned for more updates, and don't hesitate to join our Matrix chat or Discord server if you have any questions or feedback!

For a complete list of changes, check out our changelog.

Top comments (0)