Socket
Socket
Sign inDemoInstall

opentelemetry-instrumentation-elasticsearch

Package Overview
Dependencies
27
Maintainers
2
Versions
62
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    opentelemetry-instrumentation-elasticsearch

open telemetry instrumentation for the `elasticsearch` module


Version published
Weekly downloads
40K
decreased by-1.25%
Maintainers
2
Install size
4.00 MB
Created
Weekly downloads
 

Readme

Source

OpenTelemetry Elasticsearch Instrumentation for Node.js

NPM version

This module provides automatic instrumentation for @elastic/elasticsearch and follows otel DB Semantic Conventions.

Installation

npm install opentelemetry-instrumentation-elasticsearch

Usage

For further automatic instrumentation instruction see the @opentelemetry/instrumentation package.

const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node');
const { registerInstrumentations } = require('@opentelemetry/instrumentation');
const { ElasticsearchInstrumentation } = require('opentelemetry-instrumentation-elasticsearch');

registerInstrumentations({
  tracerProvider,
  instrumentations: [
    new ElasticsearchInstrumentation({
      // Config example (all optional)
      suppressInternalInstrumentation: false,
      moduleVersionAttributeName: 'elasticsearchClient.version',
      responseHook: (span, result) => {
        span.setAttribute('db.response', JSON.stringify(result));
      },
      dbStatementSerializer: (operation, params, options) => {
        return JSON.stringify(params);
      }
    })
  ]
});

Elasticsearch Instrumentation Options

Elasticsearch instrumentation has few options available to choose from. You can set the following (all optional):

OptionsTypeDefaultDescription
suppressInternalInstrumentationbooleanfalseElasticsearch operation use http/https under the hood. Setting this to true will hide the underlying request spans (if instrumented).
responseHookResponseHook (function)undefinedHook called before response is returned, which allows to add custom attributes to span.
Function receive params: span
result (object)
dbStatementSerializerDbStatementSerializer (function)JSON.stringify({params, options})Elasticsearch instrumentation will serialize db.statement using this function response.
Function receive params: operation (string)
params (object)
options (object)
Function response must be a string
moduleVersionAttributeNamestringundefinedIf passed, a span attribute will be added to all spans with key of the provided moduleVersionAttributeName and value of the @elastic/elasticsearch version

Please make sure dbStatementSerializer is error proof, as errors are not handled while executing this function.

db.operation attribute

db.operation contain the API function called. For the full list see API reference.

Few examples:

  • client.bulk
  • client.search
  • client.index
  • cat.shards
  • cluster.health

This extension (and many others) was developed by Aspecto with ❤️

Keywords

FAQs

Last updated on 17 Oct 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc