@fedify/fedify 1.3.0-dev.565 → 1.3.0-dev.569

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGES.md CHANGED
@@ -61,6 +61,7 @@ To be released.
61
61
 
62
62
  - Fedify now supports OpenTelemetry for tracing. [[#170]]
63
63
 
64
+ - Added `Context.tracerProvider` property.
64
65
  - Added `CreateFederationOptions.tracerProvider` option.
65
66
  - Added `LookupWebFingerOptions.tracerProvider` option.
66
67
  - Added `LookupObjectOptions.tracerProvider` option.
@@ -71,8 +72,17 @@ To be released.
71
72
  - Added `VerifyProofOptions.tracerProvider` option.
72
73
  - Added `VerifyObjectOptions.tracerProvider` option.
73
74
  - Added `SignObjectOptions.tracerProvider` option.
75
+ - Added `VerifySignatureOptions.tracerProvider` option.
74
76
  - Added `VerifyJsonLdOptions.tracerProvider` option.
75
77
  - Added `SignJsonLdOptions.tracerProvider` option.
78
+ - Added `DoesActorOwnKeyOptions.tracerProvider` option.
79
+ - Added `GetKeyOwnerOptions.tracerProvider` option.
80
+
81
+ - Added `tracerProvider` option to the following Activity Vocabulary APIs:
82
+
83
+ - The second parameters of constructors.
84
+ - The second parameters of `fromJsonLd()` static methods.
85
+ - The second parameters of `get*()` methods.
76
86
 
77
87
  - Added `@fedify/fedify/x/sveltekit` module for integrating with [SvelteKit]
78
88
  hook. [[#171], [#183] by Jiyu Park]
package/esm/deno.js CHANGED
@@ -1,6 +1,6 @@
1
1
  export default {
2
2
  "name": "@fedify/fedify",
3
- "version": "1.3.0-dev.565+37191e25",
3
+ "version": "1.3.0-dev.569+d97ee744",
4
4
  "license": "MIT",
5
5
  "exports": {
6
6
  ".": "./mod.ts",
@@ -11,6 +11,7 @@ import { hasSignature, signJsonLd } from "../sig/ld.js";
11
11
  import { getKeyOwner } from "../sig/owner.js";
12
12
  import { signObject } from "../sig/proof.js";
13
13
  import { lookupObject, traverseCollection, } from "../vocab/lookup.js";
14
+ import { getTypeId } from "../vocab/type.js";
14
15
  import { Activity, CryptographicKey, Multikey, } from "../vocab/vocab.js";
15
16
  import { handleWebFinger } from "../webfinger/handler.js";
16
17
  import { buildCollectionSynchronizationHeader } from "./collection.js";
@@ -204,6 +205,7 @@ export class FederationImpl {
204
205
  documentLoader: rsaKeyPair == null
205
206
  ? this.documentLoader
206
207
  : this.authenticatedDocumentLoaderFactory(rsaKeyPair),
208
+ tracerProvider: this.tracerProvider,
207
209
  });
208
210
  try {
209
211
  this.onOutboxError?.(error, activity);
@@ -401,7 +403,29 @@ export class FederationImpl {
401
403
  }
402
404
  const callbacks = {
403
405
  dispatcher: async (context, identifier) => {
404
- const actor = await dispatcher(context, identifier);
406
+ const actor = await this.#getTracer().startActiveSpan("activitypub.dispatch_actor", { kind: SpanKind.SERVER }, async (span) => {
407
+ try {
408
+ const actor = await dispatcher(context, identifier);
409
+ span.setAttribute("activitypub.actor.id", (actor?.id ?? context.getActorUri(identifier)).href);
410
+ if (actor == null) {
411
+ span.setStatus({ code: SpanStatusCode.ERROR });
412
+ }
413
+ else {
414
+ span.setAttribute("activitypub.actor.type", getTypeId(actor).href);
415
+ }
416
+ return actor;
417
+ }
418
+ catch (error) {
419
+ span.setStatus({
420
+ code: SpanStatusCode.ERROR,
421
+ message: String(error),
422
+ });
423
+ throw error;
424
+ }
425
+ finally {
426
+ span.end();
427
+ }
428
+ });
405
429
  if (actor == null)
406
430
  return null;
407
431
  const logger = getLogger(["fedify", "federation", "actor"]);
@@ -535,8 +559,22 @@ export class FederationImpl {
535
559
  };
536
560
  this.actorCallbacks = callbacks;
537
561
  const setters = {
538
- setKeyPairsDispatcher(dispatcher) {
539
- callbacks.keyPairsDispatcher = dispatcher;
562
+ setKeyPairsDispatcher: (dispatcher) => {
563
+ callbacks.keyPairsDispatcher = (ctx, identifier) => this.#getTracer().startActiveSpan("activitypub.dispatch_actor_key_pairs", { kind: SpanKind.SERVER }, async (span) => {
564
+ try {
565
+ return await dispatcher(ctx, identifier);
566
+ }
567
+ catch (e) {
568
+ span.setStatus({
569
+ code: SpanStatusCode.ERROR,
570
+ message: String(e),
571
+ });
572
+ throw e;
573
+ }
574
+ finally {
575
+ span.end();
576
+ }
577
+ });
540
578
  return setters;
541
579
  },
542
580
  mapHandle(mapper) {
@@ -1301,6 +1339,9 @@ export class ContextImpl {
1301
1339
  get contextLoader() {
1302
1340
  return this.federation.contextLoader;
1303
1341
  }
1342
+ get tracerProvider() {
1343
+ return this.federation.tracerProvider;
1344
+ }
1304
1345
  getNodeInfoUri() {
1305
1346
  const path = this.federation.router.build("nodeInfo", {});
1306
1347
  if (path == null) {
@@ -1638,7 +1679,7 @@ export class ContextImpl {
1638
1679
  documentLoader: options.documentLoader ?? this.documentLoader,
1639
1680
  contextLoader: options.contextLoader ?? this.contextLoader,
1640
1681
  userAgent: options.userAgent ?? this.federation.userAgent,
1641
- tracerProvider: options.tracerProvider ?? this.federation.tracerProvider,
1682
+ tracerProvider: options.tracerProvider ?? this.tracerProvider,
1642
1683
  });
1643
1684
  }
1644
1685
  traverseCollection(collection, options = {}) {
@@ -1805,7 +1846,7 @@ class RequestContextImpl extends ContextImpl {
1805
1846
  return this.#signedKey = await verifyRequest(this.request, {
1806
1847
  ...this,
1807
1848
  timeWindow: this.federation.signatureTimeWindow,
1808
- tracerProvider: this.federation.tracerProvider,
1849
+ tracerProvider: this.tracerProvider,
1809
1850
  });
1810
1851
  }
1811
1852
  #signedKeyOwner = undefined;
@@ -1935,7 +1976,7 @@ export class InboxContextImpl extends ContextImpl {
1935
1976
  activity: this.activity,
1936
1977
  activityId: activityId,
1937
1978
  inbox: new URL(inbox),
1938
- tracerProvider: this.federation.tracerProvider,
1979
+ tracerProvider: this.tracerProvider,
1939
1980
  }));
1940
1981
  }
1941
1982
  await Promise.all(promises);
package/esm/sig/http.js CHANGED
@@ -135,7 +135,7 @@ export async function verifyRequest(request, options = {}) {
135
135
  }
136
136
  });
137
137
  }
138
- async function verifyRequestInternal(request, span, { documentLoader, contextLoader, timeWindow, currentTime, keyCache, } = {}) {
138
+ async function verifyRequestInternal(request, span, { documentLoader, contextLoader, timeWindow, currentTime, keyCache, tracerProvider, } = {}) {
139
139
  const logger = getLogger(["fedify", "sig", "http"]);
140
140
  if (request.bodyUsed) {
141
141
  logger.error("Failed to verify; the request body is already consumed.", { url: request.url });
@@ -244,6 +244,7 @@ async function verifyRequestInternal(request, span, { documentLoader, contextLoa
244
244
  documentLoader,
245
245
  contextLoader,
246
246
  keyCache,
247
+ tracerProvider,
247
248
  });
248
249
  if (key == null)
249
250
  return null;
package/esm/sig/key.js CHANGED
@@ -106,7 +106,7 @@ export async function importJwk(jwk, type) {
106
106
  */
107
107
  export async function fetchKey(keyId,
108
108
  // deno-lint-ignore no-explicit-any
109
- cls, { documentLoader, contextLoader, keyCache } = {}) {
109
+ cls, { documentLoader, contextLoader, keyCache, tracerProvider } = {}) {
110
110
  const logger = getLogger(["fedify", "sig", "key"]);
111
111
  const cacheKey = typeof keyId === "string" ? new URL(keyId) : keyId;
112
112
  keyId = typeof keyId === "string" ? keyId : keyId.href;
@@ -140,6 +140,7 @@ cls, { documentLoader, contextLoader, keyCache } = {}) {
140
140
  object = await Object.fromJsonLd(document, {
141
141
  documentLoader,
142
142
  contextLoader,
143
+ tracerProvider,
143
144
  });
144
145
  }
145
146
  catch (e) {
@@ -149,6 +150,7 @@ cls, { documentLoader, contextLoader, keyCache } = {}) {
149
150
  object = await cls.fromJsonLd(document, {
150
151
  documentLoader,
151
152
  contextLoader,
153
+ tracerProvider,
152
154
  });
153
155
  }
154
156
  catch (e) {
@@ -166,8 +168,12 @@ cls, { documentLoader, contextLoader, keyCache } = {}) {
166
168
  else if (isActor(object)) {
167
169
  // @ts-ignore: cls is either CryptographicKey or Multikey
168
170
  const keys = cls === CryptographicKey
169
- ? object.getPublicKeys({ documentLoader, contextLoader })
170
- : object.getAssertionMethods({ documentLoader, contextLoader });
171
+ ? object.getPublicKeys({ documentLoader, contextLoader, tracerProvider })
172
+ : object.getAssertionMethods({
173
+ documentLoader,
174
+ contextLoader,
175
+ tracerProvider,
176
+ });
171
177
  for await (const k of keys) {
172
178
  if (k.id?.href === keyId) {
173
179
  key = k;
package/esm/sig/owner.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { trace } from "@opentelemetry/api";
1
2
  import { getDocumentLoader, } from "../runtime/docloader.js";
2
3
  import { isActor } from "../vocab/actor.js";
3
4
  import { CryptographicKey, Object as ASObject, } from "../vocab/vocab.js";
@@ -30,8 +31,10 @@ export async function doesActorOwnKey(activity, key, options) {
30
31
  * @param options Options for getting the key owner.
31
32
  * @returns The actor that owns the key, or `null` if the key has no known
32
33
  * owner.
34
+ * @since 0.7.0
33
35
  */
34
36
  export async function getKeyOwner(keyId, options) {
37
+ const tracerProvider = options.tracerProvider ?? trace.getTracerProvider();
35
38
  const documentLoader = options.documentLoader ?? getDocumentLoader();
36
39
  const contextLoader = options.contextLoader ?? getDocumentLoader();
37
40
  let object;
@@ -54,6 +57,7 @@ export async function getKeyOwner(keyId, options) {
54
57
  object = await ASObject.fromJsonLd(keyDoc, {
55
58
  documentLoader,
56
59
  contextLoader,
60
+ tracerProvider,
57
61
  });
58
62
  }
59
63
  catch (e) {
@@ -63,6 +67,7 @@ export async function getKeyOwner(keyId, options) {
63
67
  object = await CryptographicKey.fromJsonLd(keyDoc, {
64
68
  documentLoader,
65
69
  contextLoader,
70
+ tracerProvider,
66
71
  });
67
72
  }
68
73
  catch (e) {
@@ -76,7 +81,11 @@ export async function getKeyOwner(keyId, options) {
76
81
  if (object instanceof CryptographicKey) {
77
82
  if (object.ownerId == null)
78
83
  return null;
79
- owner = await object.getOwner({ documentLoader, contextLoader });
84
+ owner = await object.getOwner({
85
+ documentLoader,
86
+ contextLoader,
87
+ tracerProvider,
88
+ });
80
89
  }
81
90
  else if (isActor(object)) {
82
91
  owner = object;
@@ -119,6 +119,7 @@ async function lookupObjectInternal(identifier, options = {}) {
119
119
  return await Object.fromJsonLd(document, {
120
120
  documentLoader,
121
121
  contextLoader: options.contextLoader,
122
+ tracerProvider: options.tracerProvider,
122
123
  });
123
124
  }
124
125
  catch (error) {