npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@pimlico/opentelemetry-instrumentation-viem

v0.0.5-alpha.1

Published

OpenTelemetry instrumentation for viem library

Readme

OpenTelemetry Viem Instrumentation for Node.js

This module provides automatic opentelemetry instrumentation for the viem library. It patches the low-level JSON-RPC client in viem to create spans for each RPC request, providing detailed visibility into Ethereum interactions. Key features include:

  • Automatic tracing of all JSON-RPC requests made through viem
  • Detailed span attributes following OpenTelemetry RPC conventions
  • Support for batch requests
  • Configurable parent span requirement for controlled propagation
  • Custom attribute hooks for extending span information
  • Error capturing with detailed error information

Installation

npm install --save @pimlico/opentelemetry-instrumentation-viem

Supported Versions

  • viem versions >2.8.18

Usage

import { NodeSDK } from "@opentelemetry/sdk-node"
import { ConsoleSpanExporter } from '@opentelemetry/sdk-trace-node';
import { ViemInstrumentation } from "@pimlico/opentelemetry-instrumentation-viem"

const sdk = new NodeSDK({
    traceExporter: new ConsoleSpanExporter(),
    instrumentations: [
        new ViemInstrumentation({
            requireParentSpan: true,
            captureOperationResult: true
        })
    ],
})

sdk.start()

Viem Instrumentation Options

Viem instrumentation has a few options available to customize the behavior:

| Option | Type | Description | Default | | --- | --- | --- | --- | | requestHook | RequestHook | Hook for adding custom attributes to spans created by the instrumentation | undefined | | requireParentSpan | boolean | Whether to require a parent span to be present for creating spans | false | | captureOperationResult | boolean | Whether to capture operation result information. When enabled, adds basic type information about the response. | false |

Using the Request Hook

The request hook allows you to add custom attributes to spans based on the request parameters:

const { ViemInstrumentation } = require('@pimlico/opentelemetry-instrumentation-viem');

const viemInstrumentation = new ViemInstrumentation({
  requestHook: (span, request) => {
    // Add custom attributes based on the request
    span.setAttribute('custom.attribute', 'custom value');

    // You can also access request parameters
    if (request.body.method === 'eth_getBalance') {
      span.setAttribute('account.address', request.body.params[0]);
    }
  }
});

Metrics

This instrumentation does not provide any metrics.

Trace Semantic Conventions

This instrumentation follows the OpenTelemetry RPC conventions for spans and adds the following attributes:

| Attribute Name | Type | Description | | --- | --- | --- | | rpc.system | string | Always set to jsonrpc | | rpc.service | string | Always set to evm-jsonrpc | | rpc.method | string | The JSON-RPC method name (e.g., eth_getBalance, eth_call) | | rpc.jsonrpc.version | string | Always set to 2.0 | | rpc.jsonrpc.request_id | string | The JSON-RPC request ID | | server.address | string | The hostname of the JSON-RPC server | | server.port | string | The port of the JSON-RPC server | | url.full | string | The full URL of the JSON-RPC server | | url.path | string | The path component of the URL | | url.scheme | string | The scheme component of the URL (http or https) |

When captureOperationResult is enabled and an error occurs, the following additional attributes are added:

| Attribute Name | Type | Description | | --- | --- | --- | | rpc.jsonrpc.error_code | number | The JSON-RPC error code | | rpc.jsonrpc.error_message | string | The JSON-RPC error message |