Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add traceFunction call to metrics #2898

Merged
merged 3 commits into from
Jan 7, 2025

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 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