Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(otel-node): add @opentelemetry/instrumentation-cassandra-driver #553

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions .github/workflows/test-edot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ jobs:
MSSQL_SA_PASSWORD: 'Very(!)Secure'
ports:
- "1433:1433"

cassandra:
image: cassandra:3
env:
MAX_HEAP_SIZE: "1G"
HEAP_NEWSIZE: 400m
ports:
- "9042:9042"

steps:
- uses: actions/checkout@v4
Expand Down
3 changes: 3 additions & 0 deletions packages/opentelemetry-node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
of instrumentations. See <https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/plugins/node/opentelemetry-instrumentation-mysql#readme>
- feat: Add `@opentelemetry/instrumentation-mysql2` to the default set
of instrumentations. See <https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/plugins/node/opentelemetry-instrumentation-mysql2#readme>
- feat: Add `@opentelemetry/instrumentation-cassandra-driver` to the default set
of instrumentations. See <https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/plugins/node/opentelemetry-instrumentation-cassandra#readme>


## v0.6.0

Expand Down
1 change: 1 addition & 0 deletions packages/opentelemetry-node/docs/supported-technologies.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ requires:
| `@elastic/opentelemetry-instrumentation-openai` | `openai` version range `>=4.19.0 <5` | [README](https://github.com/elastic/elastic-otel-node/tree/main/packages/instrumentation-openai#readme) |
| `@opentelemetry/instrumentation-aws-sdk` | `aws-sdk` v2 and `@aws-sdk/client-*` v3 | [README](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-aws-sdk#readme) |
| `@opentelemetry/instrumentation-bunyan` | `bunyan` version range `^1.0.0` | [README](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-bunyan#readme) |
| `@opentelemetry/instrumentation-cassandra-driver` | `cassandra-driver` version range `>=4.4.0 <5` | [README](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-cassandra#readme) |
| `@opentelemetry/instrumentation-express` | `express` version range `^4.0.0` | [README](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-express#readme) |
| `@opentelemetry/instrumentation-fastify` | `fastify` version range `>=3 <5` | [README](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-fastify#readme) |
| `@opentelemetry/instrumentation-generic-pool` | `generic-pool` version range `2 - 2.3, ^2.4, >=3` | [README](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-generic-pool#readme) |
Expand Down
3 changes: 3 additions & 0 deletions packages/opentelemetry-node/lib/instrumentations.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
* "@opentelemetry/instrumentation-aws-sdk": import('@opentelemetry/instrumentation-aws-sdk').AwsSdkInstrumentationConfig | InstrumentationFactory,
* "@opentelemetry/instrumentation-bunyan": import('@opentelemetry/instrumentation-bunyan').BunyanInstrumentationConfig | InstrumentationFactory,
* "@opentelemetry/instrumentation-connect": import('@opentelemetry/instrumentation').InstrumentationConfig | InstrumentationFactory,
* "@opentelemetry/instrumentation-cassandra-driver": import('@opentelemetry/instrumentation-cassandra-driver').CassandraDriverInstrumentation | InstrumentationFactory,
* "@opentelemetry/instrumentation-cucumber": import('@opentelemetry/instrumentation-cucumber').CucumberInstrumentationConfig | InstrumentationFactory,
* "@opentelemetry/instrumentation-dataloader": import('@opentelemetry/instrumentation-dataloader').DataloaderInstrumentationConfig | InstrumentationFactory,
* "@opentelemetry/instrumentation-dns": import('@opentelemetry/instrumentation-dns').DnsInstrumentationConfig | InstrumentationFactory,
Expand Down Expand Up @@ -67,6 +68,7 @@ const {OpenAIInstrumentation} = require('@elastic/opentelemetry-instrumentation-
const {AwsInstrumentation} = require('@opentelemetry/instrumentation-aws-sdk');
const {BunyanInstrumentation} = require('@opentelemetry/instrumentation-bunyan');
const {ConnectInstrumentation} = require('@opentelemetry/instrumentation-connect');
const {CassandraDriverInstrumentation} = require('@opentelemetry/instrumentation-cassandra-driver');
const {CucumberInstrumentation} = require('@opentelemetry/instrumentation-cucumber');
const {DataloaderInstrumentation} = require('@opentelemetry/instrumentation-dataloader');
const {DnsInstrumentation} = require('@opentelemetry/instrumentation-dns');
Expand Down Expand Up @@ -115,6 +117,7 @@ const INSTRUMENTATIONS = {
'@opentelemetry/instrumentation-aws-sdk': (cfg) => new AwsInstrumentation(cfg),
'@opentelemetry/instrumentation-bunyan': (cfg) => new BunyanInstrumentation(cfg),
'@opentelemetry/instrumentation-connect': (cfg) => new ConnectInstrumentation(cfg),
'@opentelemetry/instrumentation-cassandra-driver': (cfg) => new CassandraDriverInstrumentation(cfg),
'@opentelemetry/instrumentation-cucumber': (cfg) => new CucumberInstrumentation(cfg),
'@opentelemetry/instrumentation-dataloader': (cfg) => new DataloaderInstrumentation(cfg),
'@opentelemetry/instrumentation-dns': (cfg) => new DnsInstrumentation(cfg),
Expand Down
87 changes: 87 additions & 0 deletions packages/opentelemetry-node/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions packages/opentelemetry-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
"@opentelemetry/instrumentation": "^0.57.1",
"@opentelemetry/instrumentation-aws-sdk": "^0.49.0",
"@opentelemetry/instrumentation-bunyan": "^0.45.0",
"@opentelemetry/instrumentation-cassandra-driver": "^0.45.0",
"@opentelemetry/instrumentation-connect": "^0.43.0",
"@opentelemetry/instrumentation-cucumber": "^0.13.0",
"@opentelemetry/instrumentation-dataloader": "^0.16.0",
Expand Down Expand Up @@ -134,6 +135,7 @@
"@hapi/hapi": "^21.3.10",
"@types/tape": "^5.6.4",
"bunyan": "^1.8.15",
"cassandra-driver": "^4.7.2",
"dotenv": "^16.4.5",
"express": "^4.21.0",
"fastify": "^5.1.0",
Expand Down
13 changes: 13 additions & 0 deletions packages/opentelemetry-node/test/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,16 @@ services:
interval: 1s
timeout: 10s
retries: 30

cassandra:
image: cassandra:3
environment:
MAX_HEAP_SIZE: "1G"
HEAP_NEWSIZE: 400m
ports:
- "9042:9042"
healthcheck:
test: ["CMD-SHELL", "[ $$(nodetool statusgossip) = running ]"]
interval: 1s
timeout: 10s
retries: 30
61 changes: 61 additions & 0 deletions packages/opentelemetry-node/test/fixtures/use-cassandra-driver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

// Usage: node -r @elastic/opentelemetry-node use-cassandra-driver.js

const cassandra = require('cassandra-driver');
const otel = require('@opentelemetry/api');

const host = process.env.CASSANDRA_HOST;
const port = process.env.CASSANDRA_PORT || '9042';
const keyspace = 'keyspace1';
const table = 'table1';

async function main() {
const client = new cassandra.Client({
contactPoints: [`${host}:${port}`],
localDataCenter: 'datacenter1',
});

await client.connect();
await client.execute(
`CREATE KEYSPACE IF NOT EXISTS ${keyspace} WITH replication = { 'class': 'SimpleStrategy', 'replication_factor': 1 };`
);
await client.execute(`USE ${keyspace}`);
await client.execute(
`CREATE TABLE IF NOT EXISTS ${keyspace}.${table}(id uuid,text varchar,PRIMARY KEY(id));`
);
await client.batch([
{
query: `INSERT INTO ${keyspace}.${table} (id, text) VALUES (uuid(), ?)`,
params: ['value1'],
},
{
query: `INSERT INTO ${keyspace}.${table} (id, text) VALUES (uuid(), ?)`,
params: ['value2'],
},
]);
await client.execute(`DROP TABLE IF EXISTS ${keyspace}.${table}`);
await client.shutdown();
}
const tracer = otel.trace.getTracer('test');
tracer.startActiveSpan('manual-span', async (span) => {
await main();
span.end();
});
76 changes: 76 additions & 0 deletions packages/opentelemetry-node/test/instr-cassandra-driver.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

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

// TODO: check https://github.com/elastic/apm-agent-nodejs/blob/main/test/_is_cassandra_incompat.js
const skip = process.env.CASSANDRA_HOST === undefined;
if (skip) {
console.log(
'# SKIP cassandra-driver tests: CASSANDRA_HOST is not set (try with `CASSANDRA_HOST=localhost`)'
);
}

/** @type {import('./testutils').TestFixture[]} */
const testFixtures = [
{
name: 'use-cassandra-driver.js',
args: ['./fixtures/use-cassandra-driver.js'],
cwd: __dirname,
env: {
NODE_OPTIONS: '--require=@elastic/opentelemetry-node',
},
// verbose: true,
checkTelemetry: (t, col) => {
// Expected a trace like this:
// ------ trace 15ca3e (8 spans) ------
// span 3d3aa5 "manual-span" (402.5ms, SPAN_KIND_INTERNAL)
// +27ms `- span b8ab8f "tcp.connect" (0.5ms, SPAN_KIND_INTERNAL)
// +17ms `- span 6c9179 "tcp.connect" (0.4ms, SPAN_KIND_INTERNAL)
// +25ms `- span 97c330 "cassandra-driver.execute" (2.7ms, SPAN_KIND_CLIENT)
// +2ms `- span 91e594 "cassandra-driver.execute" (1.6ms, SPAN_KIND_CLIENT)
// +2ms `- span 9fbb84 "cassandra-driver.execute" (88.3ms, SPAN_KIND_CLIENT)
// +88ms `- span ef48b9 "cassandra-driver.batch" (5.7ms, SPAN_KIND_CLIENT)
// +6ms `- span fa5471 "cassandra-driver.execute" (232.5ms, SPAN_KIND_CLIENT)
const spans = filterOutDnsNetSpans(col.sortedSpans);
t.equal(spans.length, 6);
spans.slice(1).forEach((s) => {
t.equal(s.traceId, spans[0].traceId, 'traceId');
t.equal(s.parentSpanId, spans[0].spanId, 'parentSpanId');
t.equal(s.kind, 'SPAN_KIND_CLIENT', 'kind');
t.equal(
s.scope.name,
'@opentelemetry/instrumentation-cassandra-driver'
);
t.equal(s.attributes['db.system'], 'cassandra');
});
t.equal(spans[1].name, 'cassandra-driver.execute');
t.equal(spans[2].name, 'cassandra-driver.execute');
t.equal(spans[3].name, 'cassandra-driver.execute');
t.equal(spans[4].name, 'cassandra-driver.batch');
t.equal(spans[5].name, 'cassandra-driver.execute');
},
},
];

test('cassandra-driver instrumentation', {skip}, (suite) => {
runTestFixtures(suite, testFixtures);
suite.end();
});
1 change: 1 addition & 0 deletions packages/opentelemetry-node/test/test-services.env
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ PGHOST=localhost
MONGODB_HOST=localhost
MSSQL_HOST=localhost
MYSQL_HOST=localhost
CASSANDRA_HOST=localhost

OPENAI_BASE_URL=http://127.0.0.1:11434/v1
OPENAI_API_KEY=notused
Expand Down
Loading
Loading