Skip to content

feat: add traceFunction call to metrics#2898

Merged
achingbrain merged 3 commits intomainfrom
feat/add-trace-function-to-metrics
Jan 7, 2025
Merged

feat: add traceFunction call to metrics#2898
achingbrain merged 3 commits intomainfrom
feat/add-trace-function-to-metrics

Conversation

@achingbrain
Copy link
Member

@achingbrain achingbrain commented Dec 19, 2024

Allow tracing method calls using a metrics implementation.

const libp2p = await createLibp2p()

for await (const foo of libp2p.contentRouting.findProviders(cid, {
  trace: libp2p.metrics?.createTrace(),
  signal: AbortSignal.timeout(20_000)
}) {
  //...
}

Adds tracing support to libp2p.contentRouting.* and libp2p.peerRouting.* to start with, other methods can have it added when necessary.

Traces can have attributes set on them to give context to a call (input args, output values, yielded results, etc).

Change checklist

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation if necessary (this includes comments as well)
  • I have added tests that prove my fix is effective or that my feature works

@achingbrain achingbrain requested a review from a team as a code owner December 19, 2024 18:03
@achingbrain achingbrain force-pushed the feat/add-trace-function-to-metrics branch from 73887f2 to fc5f1a5 Compare December 19, 2024 18:11
Allow tracing method calls using a metrics implementation.

```js
const libp2p = await createLibp2p()

for await (const foo of libp2p.contentRouting.findProviders(cid, {
  context: libp2p.metrics?.createTraceContext()
  signal: AbortSignal.timeout(20_000)
}) {
  //...
}
```

Adds tracing support to `libp2p.contentRouting.*` and
`libp2p.peerRouting.*` to start with, other methods can have it added
when necessary.
@achingbrain achingbrain force-pushed the feat/add-trace-function-to-metrics branch from fc5f1a5 to 086c5c5 Compare December 19, 2024 18:13
@achingbrain achingbrain merged commit 20d9ba7 into main Jan 7, 2025
35 checks passed
@achingbrain achingbrain deleted the feat/add-trace-function-to-metrics branch January 7, 2025 09:53
@achingbrain achingbrain mentioned this pull request Jan 7, 2025
achingbrain added a commit that referenced this pull request Jan 7, 2025
Adds a `Metrics` interface implementation that is powered by an OpenTelemetry backend.

It tracks the same metrics as `@libp2p/prometheus-metrics` but also supports the new function tracing added in #2898.

See the readme for a usage example.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant