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 libp2p tracing metrics #166 #194

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
},
"devDependencies": {
"aegir": "^45.0.8",
"npm-run-all": "^4.1.5"
"npm-run-all": "^4.1.5",
"@libp2p/opentelemetry-metrics": "^1.0.0"
},
"type": "module",
"workspaces": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { webRTCDirect } from '@libp2p/webrtc'
import { webSockets } from '@libp2p/websockets'
import { libp2pDefaults, type DefaultLibp2pServices } from 'helia'
import { trace } from '@libp2p/opentelemetry-metrics' // Add this import
import type { ServiceFactoryMap } from './libp2p-types'
import type { Libp2pOptions } from 'libp2p'

Expand All @@ -14,6 +15,9 @@ export function getLibp2pConfig (): Libp2pOptions & Required<Pick<Libp2pOptions,
libp2pDefaultOptions.transports = [webRTCDirect(), webSockets()]
libp2pDefaultOptions.peerDiscovery = [] // Avoid connecting to bootstrap nodes

// Initialize tracing
trace(libp2pDefaultOptions)

const services: ServiceFactoryMap<ServiceMap> = {
dcutr: libp2pDefaultOptions.services.dcutr,
identify: libp2pDefaultOptions.services.identify,
Expand Down
6 changes: 5 additions & 1 deletion packages/verified-fetch/src/utils/libp2p-defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@ import { kadDHT } from '@libp2p/kad-dht'
import { libp2pDefaults, type DefaultLibp2pServices } from 'helia'
import { ipnsSelector } from 'ipns/selector'
import { ipnsValidator } from 'ipns/validator'
import { trace } from '@libp2p/opentelemetry-metrics' // Add this import
import type { ServiceFactoryMap } from './libp2p-types'
import type { Libp2pOptions } from 'libp2p'

type ServiceMap = Pick<DefaultLibp2pServices, 'autoNAT' | 'dcutr' | 'dht' | 'identify' | 'keychain' | 'ping' | 'upnp'>

export function getLibp2pConfig (): Libp2pOptions & Required<Pick<Libp2pOptions, 'services'>> {
export function getLibp2pConfig(): Libp2pOptions & Required<Pick<Libp2pOptions, 'services'>> {
const libp2pDefaultOptions = libp2pDefaults()

libp2pDefaultOptions.start = false

// Initialize tracing
trace(libp2pDefaultOptions)

const services: ServiceFactoryMap<ServiceMap> = {
autoNAT: libp2pDefaultOptions.services.autoNAT,
dcutr: libp2pDefaultOptions.services.dcutr,
Expand Down