Unverified Commit 30b888df authored by Hong Minhee's avatar Hong Minhee
Browse files

Instrument actor dispatcher

parent 35cde4e3
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -120,6 +120,7 @@ spans:
| Span name                        | [Span kind] | Description                           |
|----------------------------------|-------------|---------------------------------------|
| `{method} {template}`            | Server      | Serves the incoming HTTP request.     |
| `activitypub.dispatch_actor`     | Server      | Dispatches the ActivityPub actor.     |
| `activitypub.get_actor_handle`   | Client      | Resolves the actor handle.            |
| `activitypub.lookup_object`      | Client      | Looks up the Activity Streams object. |
| `activitypub.parse_object`       | Internal    | Parses the Activity Streams object.   |
+31 −1
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import {
  traverseCollection,
  type TraverseCollectionOptions,
} from "../vocab/lookup.ts";
import { getTypeId } from "../vocab/type.ts";
import {
  Activity,
  type Collection,
@@ -840,7 +841,36 @@ export class FederationImpl<TContextData> implements Federation<TContextData> {
    }
    const callbacks: ActorCallbacks<TContextData> = {
      dispatcher: async (context, identifier) => {
        const actor = await this.#getTracer().startActiveSpan(
          "activitypub.dispatch_actor",
          { kind: SpanKind.SERVER },
          async (span) => {
            try {
              const actor = await dispatcher(context, identifier);
              span.setAttribute(
                "activitypub.actor.id",
                (actor?.id ?? context.getActorUri(identifier)).href,
              );
              if (actor == null) {
                span.setStatus({ code: SpanStatusCode.ERROR });
              } else {
                span.setAttribute(
                  "activitypub.actor.type",
                  getTypeId(actor).href,
                );
              }
              return actor;
            } catch (error) {
              span.setStatus({
                code: SpanStatusCode.ERROR,
                message: String(error),
              });
              throw error;
            } finally {
              span.end();
            }
          },
        );
        if (actor == null) return null;
        const logger = getLogger(["fedify", "federation", "actor"]);
        if (actor.id == null) {