0.40.0 • Published 7 months ago

opentelemetry-instrumentation-elasticsearch v0.40.0

Weekly downloads
99
License
Apache-2.0
Repository
github
Last release
7 months ago

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: spanresult (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 ❤️

0.40.0

7 months ago

0.39.1

9 months ago

0.35.1

9 months ago

0.35.0

1 year ago

0.34.0

1 year ago

0.32.0

2 years ago

0.29.0

2 years ago

0.28.0

2 years ago

0.27.1

2 years ago

0.27.0

2 years ago

0.26.1

2 years ago

0.26.0

3 years ago

0.25.0

3 years ago

0.24.1

3 years ago

0.24.0

3 years ago

0.23.0

3 years ago

0.22.1

3 years ago

0.22.0

3 years ago

0.21.0

3 years ago

0.5.1

3 years ago

0.4.4

3 years ago

0.5.0

3 years ago

0.4.3

3 years ago

0.4.1

3 years ago

0.4.0

3 years ago

0.4.2

3 years ago

0.3.0

3 years ago

0.2.3

3 years ago

0.2.2

3 years ago

0.2.1-dev.1

3 years ago

0.2.1-dev.0

3 years ago