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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@sebspark/opentelemetry-instrumentation-opensearch

v0.3.0

Published

OTEL auto instrumentation for OpenSearch

Readme

@sebspark/opentelemetry-instrumentation-opensearch

OTEL auto instrumentation for OpenSearch

Patches @opensearch-project/opensearch's Transport to create db CLIENT spans for every request. By default the db span is set as the active context so HTTP child spans are properly parented and W3C trace headers are propagated outbound.

Use

import { OpenSearchInstrumentation } from '@sebspark/opentelemetry-instrumentation-opensearch'
import { registerInstrumentations } from '@opentelemetry/instrumentation'

registerInstrumentations({
  instrumentations: [new OpenSearchInstrumentation()],
})

Disabling query capture

By default the request body is captured as db.query.text. Disable it if queries contain sensitive data:

new OpenSearchInstrumentation({ dbStatementSerializer: false })

Or provide a custom serializer to redact specific fields:

new OpenSearchInstrumentation({
  dbStatementSerializer: (params) => {
    const body = params.body as Record<string, unknown>
    return JSON.stringify({ ...body, password: '[redacted]' })
  },
})

Adding custom attributes before the request

Use requestHook to attach attributes to each span before the request is sent:

new OpenSearchInstrumentation({
  requestHook: (span, params) => {
    span.setAttribute('app.opensearch.method', params.method)
  },
})

Adding custom attributes from the response

Use responseHook to attach attributes derived from the response (only called on success):

new OpenSearchInstrumentation({
  responseHook: (span, response) => {
    span.setAttribute('app.opensearch.hits', response.body?.hits?.total?.value ?? 0)
  },
})

Recording the client library version

Set moduleVersionAttributeName to record which version of @opensearch-project/opensearch made the request:

new OpenSearchInstrumentation({
  moduleVersionAttributeName: 'db.opensearch.client.version',
})

Suppressing HTTP child spans

By default the db span is set as the active context, so an HTTP instrumentation layer (if registered) will create a child span under it. To suppress all child spans instead:

new OpenSearchInstrumentation({ suppressInternalInstrumentation: true })

Produced spans

Span name follows the pattern <operation> <index> (e.g. search asset_v0.1.3) or just <operation> for index-less operations like bulk. Falls back to the raw path when the path does not contain an underscore-prefixed operation segment.

Request attributes

Set at span creation, before the request is sent.

| Attribute | Type | Example | Notes | |---|---|---|---| | db.system.name | string | opensearch | Always set | | db.operation.name | string | search | Parsed from path (_searchsearch). Omitted when path has no operation segment | | db.opensearch.index | string | asset_v0.1.3 | Omitted for cluster-level operations like _bulk | | db.query.text | string | {"query":{"match_all":{}}} | The serialized request body. Omitted for bodyless requests or when dbStatementSerializer: false |

Response attributes

Set on the span after a successful response.

Always present on search responses

| Attribute | Type | Example | Description | |---|---|---|---| | server.address | string | opensearch.example.com | Hostname of the node that handled the request | | server.port | number | 9200 | Omitted when using the default port for the protocol | | http.response.status_code | number | 200 | HTTP status code of the response | | db.opensearch.took | number | 5 | Time in milliseconds OpenSearch spent executing the request | | db.opensearch.timed_out | boolean | false | Whether the request hit the timeout threshold | | db.opensearch.shards.total | number | 5 | Total number of shards the request was executed against | | db.opensearch.shards.successful | number | 5 | Number of shards that responded successfully | | db.opensearch.shards.failed | number | 0 | Number of shards that failed | | db.opensearch.hits.total | number | 42 | Total number of matching documents |

Conditionally present

These attributes only appear when specific conditions are met, either because OpenSearch omits them by default or because they require the query to opt in.

| Attribute | Type | Condition | When to use | |---|---|---|---| | db.opensearch.shards.skipped | number | Present when OpenSearch skips shards, e.g. when using _routing or shard-level filtering | Useful for verifying that routing is working as intended — a high skipped count means fewer shards are doing work | | db.opensearch.terminated_early | boolean | Present when the query includes terminate_after: N in the request body | Use terminate_after when you want to cap result collection for performance reasons (e.g. existence checks). The attribute tells you whether the cap was actually hit | | db.opensearch.phase_took.* | number | Present when the request uses search_type: 'dfs_query_then_fetch' | Use DFS search type when accurate relevance scoring across shards matters (e.g. small indices or cross-shard ranking). The phase breakdown lets you identify which phase dominates latency |

To enable phase_took, set search_type on the request:

client.search({
  index: 'my_index',
  search_type: 'dfs_query_then_fetch',
  body: { query: { ... } },
})

To enable terminated_early, set terminate_after in the query body:

client.search({
  index: 'my_index',
  body: {
    terminate_after: 1000,
    query: { ... },
  },
})

db.opensearch.phase_took.* fields

| Attribute | Description | |---|---| | db.opensearch.phase_took.can_match | Time spent determining which shards can match the query | | db.opensearch.phase_took.dfs_pre_query | Time spent collecting term statistics across shards before the query phase | | db.opensearch.phase_took.dfs_query | Time spent executing the query using globally collected term statistics | | db.opensearch.phase_took.expand | Time spent expanding results (e.g. for collapse/inner hits) | | db.opensearch.phase_took.fetch | Time spent fetching document source and fields | | db.opensearch.phase_took.query | Time spent in the standard query phase |