Skip to content
Merged
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: 3 additions & 0 deletions packages/opentelemetry-node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

- feat: Default to stable semantic conventions for HTTP instrumentation.
(https://github.com/elastic/elastic-otel-node/pull/669)

- Upgrade upstream OTel dependencies to SDK 2.0. This should be non-breaking
for users of `node --import @elastic/opentelemetry-node my-app.js` to start
EDOT Node.js for their application.
Expand Down
11 changes: 11 additions & 0 deletions packages/opentelemetry-node/lib/instrumentations.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,17 @@ function getInstrumentations(opts = {}) {
'OTEL_NODE_DISABLED_INSTRUMENTATIONS'
);

// `@opentelemetry/instrumentation-http` defaults to emit old semconv attributes.
// Set the default to stable HTTP semconv if not defined by the user (http, http/dup)
// TODO: remove this once https://github.com/open-telemetry/opentelemetry-js/pull/5552
// is merged and published.
const semconvOptIn =
getStringListFromEnv('OTEL_SEMCONV_STABILITY_OPT_IN') || [];
if (!semconvOptIn.includes('http') && !semconvOptIn.includes('http/dup')) {
semconvOptIn.push('http');
process.env.OTEL_SEMCONV_STABILITY_OPT_IN = semconvOptIn.join(',');
}

Object.keys(instrumentationsMap).forEach((name) => {
// Skip if env has an `enabled` list and does not include this one
if (enabledFromEnv && !enabledFromEnv.includes(name)) {
Expand Down
10 changes: 5 additions & 5 deletions packages/opentelemetry-node/test/instr-aws-sdk.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const http = require('http');
const path = require('path');

const test = require('tape');
const {runTestFixtures} = require('./testutils');
const {runTestFixtures, filterOutGcpDetectorSpans} = require('./testutils');

const TEST_REGION = 'us-east-2';

Expand Down Expand Up @@ -41,7 +41,7 @@ const testFixtures = [
// span b592a3 "manual-parent-span" (26.1ms, SPAN_KIND_INTERNAL)
// +4ms `- span bbe07e "S3.ListBuckets" (21.5ms, SPAN_KIND_CLIENT)
// +10ms `- span b3b885 "GET" (7.0ms, SPAN_KIND_CLIENT, GET http://localhost:4566/?x-id=ListBuckets -> 200)
const spans = col.sortedSpans;
const spans = filterOutGcpDetectorSpans(col.sortedSpans);
t.equal(spans.length, 2);

t.equal(
Expand Down Expand Up @@ -77,7 +77,7 @@ const testFixtures = [
// span b592a3 "manual-parent-span" (26.1ms, SPAN_KIND_INTERNAL)
// +4ms `- span bbe07e "SNS ListBuckets" (21.5ms, SPAN_KIND_CLIENT)
// +10ms `- span b3b885 "POST" (7.0ms, SPAN_KIND_CLIENT, POST http://localhost:4566/ -> 200)
const spans = col.sortedSpans;
const spans = filterOutGcpDetectorSpans(col.sortedSpans);
t.equal(spans.length, 2);

t.equal(
Expand Down Expand Up @@ -114,7 +114,7 @@ const testFixtures = [
// span b592a3 "manual-parent-span" (26.1ms, SPAN_KIND_INTERNAL)
// +4ms `- span bbe07e "SQS.ListQueues" (21.5ms, SPAN_KIND_CLIENT)
// +10ms `- span b3b885 "POST" (7.0ms, SPAN_KIND_CLIENT, POST http://localhost:4566/ -> 200)
const spans = col.sortedSpans;
const spans = filterOutGcpDetectorSpans(col.sortedSpans);
t.equal(spans.length, 2);

t.equal(
Expand Down Expand Up @@ -152,7 +152,7 @@ const testFixtures = [
// span b592a3 "manual-parent-span" (26.1ms, SPAN_KIND_INTERNAL)
// +4ms `- span bbe07e "DynamoDB.ListTables" (21.5ms, SPAN_KIND_CLIENT)
// +10ms `- span b3b885 "POST" (7.0ms, SPAN_KIND_CLIENT, POST http://localhost:4566/ -> 200)
const spans = col.sortedSpans;
const spans = filterOutGcpDetectorSpans(col.sortedSpans);
t.equal(spans.length, 2);

t.equal(
Expand Down
10 changes: 7 additions & 3 deletions packages/opentelemetry-node/test/instr-elastic-openai.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ const http = require('http');
const {basename} = require('path');
const test = require('tape');
const semver = require('semver');
const {runTestFixtures, assertDeepMatch} = require('./testutils');
const {
runTestFixtures,
filterOutGcpDetectorSpans,
assertDeepMatch,
} = require('./testutils');

let skip = process.env.TEST_GENAI_MODEL === undefined;
if (skip) {
Expand Down Expand Up @@ -35,7 +39,7 @@ const testFixtures = [
// Expected a trace like this:
// span 7e8ca8 "embeddings all-minilm:22m" (26.4ms, SPAN_KIND_CLIENT, GenAI openai)
// +9ms `- span 39fc32 "POST" (16.7ms, SPAN_KIND_CLIENT, POST http://127.0.0.1:11434/v1/embeddings -> 200)
const spans = col.sortedSpans;
const spans = filterOutGcpDetectorSpans(col.sortedSpans);
assertDeepMatch(
t,
spans,
Expand All @@ -58,7 +62,7 @@ const testFixtures = [
name: 'POST',
parentSpanId: spans[0].spanId,
attributes: {
'http.target': '/v1/embeddings',
'url.full': 'http://127.0.0.1:11434/v1/embeddings',
},
scope: {
name: '@opentelemetry/instrumentation-http',
Expand Down
10 changes: 8 additions & 2 deletions packages/opentelemetry-node/test/instr-elasticsearch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
// and later.

const test = require('tape');
const {filterOutDnsNetSpans, runTestFixtures} = require('./testutils');
const {
filterOutDnsNetSpans,
filterOutGcpDetectorSpans,
runTestFixtures,
} = require('./testutils');

const skip = process.env.ES_URL === undefined;
if (skip) {
Expand All @@ -20,7 +24,9 @@ function checkTelemetry(t, col) {
// Expected a trace like this:
// span 91a6b1 "search" (13.4ms, SPAN_KIND_CLIENT, GET http://localhost:9200/)
// +2ms `- span 14278c "GET" (10.8ms, SPAN_KIND_CLIENT, GET http://localhost:9200/_search?q=pants -> 200)
const spans = filterOutDnsNetSpans(col.sortedSpans);
const spans = filterOutGcpDetectorSpans(
filterOutDnsNetSpans(col.sortedSpans)
);
t.equal(spans.length, 2);
t.equal(spans[0].name, 'search');
t.equal(spans[0].kind, 'SPAN_KIND_CLIENT', 'kind');
Expand Down
5 changes: 4 additions & 1 deletion packages/opentelemetry-node/test/instr-express.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const {
filterOutDnsNetSpans,
runTestFixtures,
findObjInArray,
filterOutGcpDetectorSpans,
} = require('./testutils');

/** @type {import('./testutils').TestFixture[]} */
Expand All @@ -36,7 +37,9 @@ const testFixtures = [
// +0ms `- span 2092ee "middleware - query" (0.1ms, SPAN_KIND_INTERNAL)
// +0ms `- span 033a59 "middleware - expressInit" (0.1ms, SPAN_KIND_INTERNAL)
// +1ms `- span 5573dc "request handler - /hi/:name" (0.0ms, SPAN_KIND_INTERNAL)
const spans = filterOutDnsNetSpans(col.sortedSpans);
const spans = filterOutGcpDetectorSpans(
filterOutDnsNetSpans(col.sortedSpans)
);
t.equal(spans.length, 10);

t.equal(spans[0].scope.name, '@opentelemetry/instrumentation-http');
Expand Down
9 changes: 7 additions & 2 deletions packages/opentelemetry-node/test/instr-fastify.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const {
filterOutDnsNetSpans,
runTestFixtures,
findObjInArray,
filterOutGcpDetectorSpans,
} = require('./testutils');

/** @type {import('./testutils').TestFixture[]} */
Expand All @@ -27,7 +28,9 @@ const testFixtures = [
},
// verbose: true,
checkTelemetry: (t, col) => {
const spans = filterOutDnsNetSpans(col.sortedSpans);
const spans = filterOutGcpDetectorSpans(
filterOutDnsNetSpans(col.sortedSpans)
);

t.equal(spans.length, 4);
t.ok(
Expand Down Expand Up @@ -70,7 +73,9 @@ const testFixtures = [
// span 6e0fc9 "GET" (1.6ms, SPAN_KIND_CLIENT, GET http://localhost:3000/hi/Bob -> 200)
// +1ms `- span 40c4a8 "GET /hi/:name" (0.3ms, SPAN_KIND_SERVER, GET http://localhost:3000/hi/Bob -> 200)
// +0ms `- span 74a68a "request handler - fastify" (0.1ms, SPAN_KIND_INTERNAL)
const spans = filterOutDnsNetSpans(col.sortedSpans);
const spans = filterOutGcpDetectorSpans(
filterOutDnsNetSpans(col.sortedSpans)
);
t.equal(spans.length, 6);

t.equal(spans[0].scope.name, '@opentelemetry/instrumentation-http');
Expand Down
10 changes: 8 additions & 2 deletions packages/opentelemetry-node/test/instr-grpc.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
// Test that instrumentation-grpc generates the telemetry we expect.

const test = require('tape');
const {filterOutDnsNetSpans, runTestFixtures} = require('./testutils');
const {
filterOutDnsNetSpans,
runTestFixtures,
filterOutGcpDetectorSpans,
} = require('./testutils');

/** @type {import('./testutils').TestFixture[]} */
const testFixtures = [
Expand All @@ -19,7 +23,9 @@ const testFixtures = [
},
// verbose: true,
checkTelemetry: (t, col) => {
const spans = filterOutDnsNetSpans(col.sortedSpans);
const spans = filterOutGcpDetectorSpans(
filterOutDnsNetSpans(col.sortedSpans)
);
t.equal(spans.length, 2);
t.equal(spans[0].kind, 'SPAN_KIND_CLIENT');
t.equal(spans[1].kind, 'SPAN_KIND_SERVER');
Expand Down
8 changes: 6 additions & 2 deletions packages/opentelemetry-node/test/instr-hapi.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
// Test that 'hapi' instrumentation generates the telemetry we expect.

const test = require('tape');
const {runTestFixtures, findObjInArray} = require('./testutils');
const {
runTestFixtures,
findObjInArray,
filterOutGcpDetectorSpans,
} = require('./testutils');

/** @type {import('./testutils').TestFixture[]} */
const testFixtures = [
Expand All @@ -31,7 +35,7 @@ const testFixtures = [
// span 9a96c1 "GET" (2.0ms, SPAN_KIND_CLIENT, GET http://localhost:3000/hi/Bob -> 200)
// +1ms `- span dfacba "GET /hi/{name}" (0.5ms, SPAN_KIND_SERVER, GET http://localhost:3000/hi/Bob -> 200)
// +0ms `- span 71a126 "route - /hi/{name}" (0.0ms, SPAN_KIND_INTERNAL, GET)
const spans = col.sortedSpans;
const spans = filterOutGcpDetectorSpans(col.sortedSpans);
t.equal(spans.length, 6);

t.equal(spans[0].scope.name, '@opentelemetry/instrumentation-http');
Expand Down
75 changes: 69 additions & 6 deletions packages/opentelemetry-node/test/instr-http.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,106 @@
// Test that 'http' instrumentation generates the telemetry we expect.

const test = require('tape');
const {runTestFixtures} = require('./testutils');
const {runTestFixtures, filterOutGcpDetectorSpans} = require('./testutils');

/** @type {import('./testutils').TestFixture[]} */
const testFixtures = [
{
name: 'http.get',
name: 'http.get (stable HTTP semconv if env not set)',
args: ['./fixtures/use-http-get.js'],
cwd: __dirname,
env: {
NODE_OPTIONS: '--require=@elastic/opentelemetry-node',
},
// verbose: true,
checkTelemetry: (t, col) => {
const spans = col.sortedSpans;
const spans = filterOutGcpDetectorSpans(col.sortedSpans);
t.equal(spans.length, 1);
const span = spans[0];
t.equal(span.scope.name, '@opentelemetry/instrumentation-http');
t.equal(span.name, 'GET');
t.equal(span.kind, 'SPAN_KIND_CLIENT');
t.equal(span.attributes['http.url'], undefined);
t.equal(span.attributes['url.full'], 'http://www.google.com/');
},
},
{
name: 'http.get (stable HTTP semconv if env set with other values)',
args: ['./fixtures/use-http-get.js'],
cwd: __dirname,
env: {
NODE_OPTIONS: '--require=@elastic/opentelemetry-node',
OTEL_SEMCONV_STABILITY_OPT_IN: 'db/dup,foo',
},
// verbose: true,
checkTelemetry: (t, col) => {
const spans = filterOutGcpDetectorSpans(col.sortedSpans);
t.equal(spans.length, 1);
const span = spans[0];
t.equal(span.scope.name, '@opentelemetry/instrumentation-http');
t.equal(span.name, 'GET');
t.equal(span.kind, 'SPAN_KIND_CLIENT');
t.equal(span.attributes['http.url'], undefined);
t.equal(span.attributes['url.full'], 'http://www.google.com/');
},
},
{
name: 'https.get (stable HTTP semconv if env not set)',
args: ['./fixtures/use-https-get.js'],
cwd: __dirname,
env: {
NODE_OPTIONS: '--require=@elastic/opentelemetry-node',
},
// verbose: true,
checkTelemetry: (t, col) => {
const spans = filterOutGcpDetectorSpans(col.sortedSpans);
t.equal(spans.length, 1);
const span = spans[0];
t.equal(span.scope.name, '@opentelemetry/instrumentation-http');
t.equal(span.name, 'GET');
t.equal(span.kind, 'SPAN_KIND_CLIENT');
t.equal(span.attributes['http.url'], undefined);
t.equal(span.attributes['url.full'], 'https://www.google.com/');
},
},
{
name: 'http.get (dual HTTP semconv if user set in env)',
args: ['./fixtures/use-http-get.js'],
cwd: __dirname,
env: {
NODE_OPTIONS: '--require=@elastic/opentelemetry-node',
OTEL_SEMCONV_STABILITY_OPT_IN: 'http/dup',
},
// verbose: true,
checkTelemetry: (t, col) => {
const spans = filterOutGcpDetectorSpans(col.sortedSpans);
t.equal(spans.length, 1);
const span = spans[0];
t.equal(span.scope.name, '@opentelemetry/instrumentation-http');
t.equal(span.name, 'GET');
t.equal(span.kind, 'SPAN_KIND_CLIENT');
t.equal(span.attributes['http.url'], 'http://www.google.com/');
t.equal(span.attributes['url.full'], 'http://www.google.com/');
},
},
{
name: 'https.get',
name: 'https.get (dual HTTP semconv if user set in env)',
args: ['./fixtures/use-https-get.js'],
cwd: __dirname,
env: {
NODE_OPTIONS: '--require=@elastic/opentelemetry-node',
OTEL_SEMCONV_STABILITY_OPT_IN: 'http/dup',
},
// verbose: true,
checkTelemetry: (t, col) => {
const spans = col.sortedSpans;
const spans = filterOutGcpDetectorSpans(col.sortedSpans);
t.equal(spans.length, 1);
const span = spans[0];
t.equal(span.scope.name, '@opentelemetry/instrumentation-http');
t.equal(span.name, 'GET');
t.equal(span.kind, 'SPAN_KIND_CLIENT');
t.equal(span.attributes['http.url'], 'https://www.google.com/');
t.equal(span.attributes['url.full'], 'https://www.google.com/');
},
},
{
Expand All @@ -52,6 +114,7 @@ const testFixtures = [
cwd: __dirname,
env: {
NODE_OPTIONS: '--require=@elastic/opentelemetry-node',
OTEL_SEMCONV_STABILITY_OPT_IN: 'http/dup',
},
// verbose: true,
checkTelemetry: (t, col) => {
Expand All @@ -62,7 +125,7 @@ const testFixtures = [
// ------ trace b8467d (2 spans) ------
// span bc8a2c "POST" (3.8ms, SPAN_KIND_CLIENT, POST http://127.0.0.1:64972/echo -> 200)
// +2ms `- span 4e7adf "POST" (1.1ms, SPAN_KIND_SERVER, POST http://127.0.0.1:64972/echo -> 200)
const spans = col.sortedSpans;
const spans = filterOutGcpDetectorSpans(col.sortedSpans);
t.equal(spans.length, 4);
t.equal(spans[0].scope.name, '@opentelemetry/instrumentation-http');
t.equal(spans[0].name, 'GET');
Expand Down
10 changes: 8 additions & 2 deletions packages/opentelemetry-node/test/instr-mongodb.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
// Test that 'mongodb' instrumentation generates the telemetry we expect.

const test = require('tape');
const {filterOutDnsNetSpans, runTestFixtures} = require('./testutils');
const {
filterOutDnsNetSpans,
filterOutGcpDetectorSpans,
runTestFixtures,
} = require('./testutils');

let skip = process.env.MONGODB_HOST === undefined;
if (skip) {
Expand Down Expand Up @@ -36,7 +40,9 @@ const testFixtures = [
// +13ms `- span 1e5ee2 "mongodb.insert" (1.4ms, SPAN_KIND_CLIENT)
// +3ms `- span 3d4723 "mongodb.delete" (0.6ms, SPAN_KIND_CLIENT)
// +1ms `- span 1c1373 "mongodb.endSessions" (0.3ms, SPAN_KIND_CLIENT)
const spans = filterOutDnsNetSpans(col.sortedSpans);
const spans = filterOutGcpDetectorSpans(
filterOutDnsNetSpans(col.sortedSpans)
);
t.equal(spans.length, 4);

t.equal(spans[0].name, 'manual-parent-span');
Expand Down
10 changes: 8 additions & 2 deletions packages/opentelemetry-node/test/instr-mongoose.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
// Test that 'mongoose' instrumentation generates the telemetry we expect.

const test = require('tape');
const {filterOutDnsNetSpans, runTestFixtures} = require('./testutils');
const {
filterOutDnsNetSpans,
filterOutGcpDetectorSpans,
runTestFixtures,
} = require('./testutils');

let skip = process.env.MONGODB_HOST === undefined;
if (skip) {
Expand Down Expand Up @@ -40,7 +44,9 @@ const testFixtures = [
// +13ms `- span 5be842 "mongodb.drop" (0.8ms, SPAN_KIND_CLIENT)
// +1ms `- span 13d56b "mongodb.endSessions" (0.3ms, SPAN_KIND_CLIENT)
// -20ms `- span c4e688 "mongoose.User.save" (18.9ms, SPAN_KIND_CLIENT)
const spans = filterOutDnsNetSpans(col.sortedSpans);
const spans = filterOutGcpDetectorSpans(
filterOutDnsNetSpans(col.sortedSpans)
);
t.equal(spans.length, 7);

t.equal(spans[0].name, 'manual-parent-span');
Expand Down
Loading
Loading