Skip to content

Commit

Permalink
Instrument actor key pairs dispatcher
Browse files Browse the repository at this point in the history
  • Loading branch information
dahlia committed Nov 26, 2024
1 parent 30b888d commit d97ee74
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 17 deletions.
31 changes: 16 additions & 15 deletions docs/manual/opentelemetry.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,21 +117,22 @@ Instrumented spans
Fedify automatically instruments the following operations with OpenTelemetry
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. |
| `http_signatures.sign` | Internal | Signs the HTTP request. |
| `http_signatures.verify` | Internal | Verifies the HTTP request signature. |
| `ld_signatures.sign` | Internal | Makes the Linked Data signature. |
| `ld_signatures.verify` | Internal | Verifies the Linked Data signature. |
| `object_integrity_proofs.sign` | Internal | Makes the object integrity proof. |
| `object_integrity_proofs.verify` | Internal | Verifies the object integrity proof. |
| `webfinger.handle` | Server | Handles the WebFinger request. |
| `webfinger.lookup` | Client | Looks up the WebFinger resource. |
| Span name | [Span kind] | Description |
|----------------------------------------|-------------|---------------------------------------------|
| `{method} {template}` | Server | Serves the incoming HTTP request. |
| `activitypub.dispatch_actor` | Server | Dispatches the ActivityPub actor. |
| `activitypub.dispatch_actor_key_pairs` | Server | Dispatches the ActivityPub actor key pairs. |
| `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. |
| `http_signatures.sign` | Internal | Signs the HTTP request. |
| `http_signatures.verify` | Internal | Verifies the HTTP request signature. |
| `ld_signatures.sign` | Internal | Makes the Linked Data signature. |
| `ld_signatures.verify` | Internal | Verifies the Linked Data signature. |
| `object_integrity_proofs.sign` | Internal | Makes the object integrity proof. |
| `object_integrity_proofs.verify` | Internal | Verifies the object integrity proof. |
| `webfinger.handle` | Server | Handles the WebFinger request. |
| `webfinger.lookup` | Client | Looks up the WebFinger resource. |

More operations will be instrumented in the future releases.

Expand Down
23 changes: 21 additions & 2 deletions src/federation/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1062,8 +1062,27 @@ export class FederationImpl<TContextData> implements Federation<TContextData> {
};
this.actorCallbacks = callbacks;
const setters: ActorCallbackSetters<TContextData> = {
setKeyPairsDispatcher(dispatcher: ActorKeyPairsDispatcher<TContextData>) {
callbacks.keyPairsDispatcher = dispatcher;
setKeyPairsDispatcher: (
dispatcher: ActorKeyPairsDispatcher<TContextData>,
) => {
callbacks.keyPairsDispatcher = (ctx, identifier) =>
this.#getTracer().startActiveSpan(
"activitypub.dispatch_actor_key_pairs",
{ kind: SpanKind.SERVER },
async (span) => {
try {
return await dispatcher(ctx, identifier);
} catch (e) {
span.setStatus({
code: SpanStatusCode.ERROR,
message: String(e),
});
throw e;
} finally {
span.end();
}
},
);
return setters;
},
mapHandle(mapper: ActorHandleMapper<TContextData>) {
Expand Down

0 comments on commit d97ee74

Please sign in to comment.