io.opentracing.contrib:opentracing-cassandra-driver

OpenTracing Instrumentation for Cassandra Driver

License

License

Categories

Categories

Cassandra Data Databases
GroupId

GroupId

io.opentracing.contrib
ArtifactId

ArtifactId

opentracing-cassandra-driver
Last Version

Last Version

0.1.4
Release Date

Release Date

Type

Type

jar
Description

Description

io.opentracing.contrib:opentracing-cassandra-driver
OpenTracing Instrumentation for Cassandra Driver
Project URL

Project URL

https://github.com/opentracing-contrib/java-cassandra-driver
Source Code Management

Source Code Management

http://github.com/opentracing-contrib/java-cassandra-driver

Download opentracing-cassandra-driver

How to add to project

<!-- https://jarcasting.com/artifacts/io.opentracing.contrib/opentracing-cassandra-driver/ -->
<dependency>
    <groupId>io.opentracing.contrib</groupId>
    <artifactId>opentracing-cassandra-driver</artifactId>
    <version>0.1.4</version>
</dependency>
// https://jarcasting.com/artifacts/io.opentracing.contrib/opentracing-cassandra-driver/
implementation 'io.opentracing.contrib:opentracing-cassandra-driver:0.1.4'
// https://jarcasting.com/artifacts/io.opentracing.contrib/opentracing-cassandra-driver/
implementation ("io.opentracing.contrib:opentracing-cassandra-driver:0.1.4")
'io.opentracing.contrib:opentracing-cassandra-driver:jar:0.1.4'
<dependency org="io.opentracing.contrib" name="opentracing-cassandra-driver" rev="0.1.4">
  <artifact name="opentracing-cassandra-driver" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.opentracing.contrib', module='opentracing-cassandra-driver', version='0.1.4')
)
libraryDependencies += "io.opentracing.contrib" % "opentracing-cassandra-driver" % "0.1.4"
[io.opentracing.contrib/opentracing-cassandra-driver "0.1.4"]

Dependencies

compile (2)

Group / Artifact Type Version
io.opentracing : opentracing-util jar 0.33.0
com.datastax.cassandra : cassandra-driver-core jar 3.7.2

test (5)

Group / Artifact Type Version
io.opentracing : opentracing-mock jar 0.33.0
org.cassandraunit : cassandra-unit jar 3.11.2.0
com.datastax.cassandra : cassandra-driver-mapping jar 3.7.2
org.awaitility : awaitility jar 3.1.6
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

Build Status Coverage Status Released Version Apache-2.0 license

OpenTracing Cassandra Driver Instrumentation

OpenTracing instrumentation for Cassandra Driver.

Installation

Cassandra 3

<dependency>
    <groupId>io.opentracing.contrib</groupId>
    <artifactId>opentracing-cassandra-driver-3</artifactId>
    <version>VERSION</version>
</dependency>

Cassandra 4

<dependency>
    <groupId>io.opentracing.contrib</groupId>
    <artifactId>opentracing-cassandra-driver-4</artifactId>
    <version>VERSION</version>
</dependency>

Usage

// Instantiate tracer
Tracer tracer = ...

Cassandra 3

// Instantiate Cluster Builder:
 Cluster.Builder builder = Cluster.builder().addContactPoints("127.0.0.1").withPort(9142);

// Instantiate Tracing Cluster:
Cluster cluster = new TracingCluster(builder, tracer);

Cassandra 4

// Instantiate CqlSession:
CqlSession session = CqlSession.builder().build()

// Decorate CqlSession with TracingCqlSession:
CqlSession tracingSession = new TracingCqlSession(session, tracer);

// execute query with TracingCqlSession:
tracingSession.execute("...");

Span Names for Cassandra 3

By default, spans for executed queries will be created with the name execute. To use a different name for the query spans, you can create a custom name provider by implementing the QuerySpanNameProvider interface.

QuerySpanNameProvider interface

public interface QuerySpanNameProvider {
  public interface Builder {
    QuerySpanNameProvider build();
  }

  /**
   * Given a Cassandra query, return a name for the span
   * @param query Cassandra query
   * @return Name for query's span
   */
  String querySpanName(String query);

}

CustomStringSpanName

Returns a predefined string for every span. Defaults to execute on null or "" argument to build()

import io.opentracing.contrib.cassandra.QuerySpanNameProvider.CustomStringSpanName;
import io.opentracing.contrib.cassandra.QuerySpanNameProvider.QuerySpanNameProvider;
...

// Initialize with custom string
QuerySpanNameProvider querySpanNameProvider = CustomStringSpanName.newBuilder().build("CUSTOM_NAME");


// Instantiate Tracing Cluster with QuerySpanNameProvider as an argument
Tracer tracer = ...
Cluster.Builder builder = ...
Cluster cluster = new TracingCluster(builder, tracer, querySpanNameProvider);

Session session = cluster.newSession();

// Execute query
session.execute("SELECT * FROM example.table WHERE field = ?", "test");
// Span is created with span name 
// "CUSTOM_NAME"

FullQuerySpanName

Returns the full query as the span name.

import io.opentracing.contrib.cassandra.QuerySpanNameProvider.FullQuerySpanName;
import io.opentracing.contrib.cassandra.QuerySpanNameProvider.QuerySpanNameProvider;
...

// Initialize
QuerySpanNameProvider querySpanNameProvider = FullQuerySpanName.newBuilder().build();


// Instantiate Tracing Cluster with QuerySpanNameProvider as an argument
Tracer tracer = ...
Cluster.Builder builder = ...
Cluster cluster = new TracingCluster(builder, tracer, querySpanNameProvider);

Session session = cluster.newSession();

// Execute query
session.execute("SELECT * FROM example.table WHERE field = ?", "test");

// Span is created with the full query as the span name,
// "SELECT * FROM example.table WHERE field = ?;"

// Span name will be parameterized if the original given query is parameterized.

PrefixedFullQuerySpanName

Returns the full query as the span name, with a custom string prefix. Defaults to Cassandra on null or "" argument to build().

import io.opentracing.contrib.cassandra.QuerySpanNameProvider.PrefixedFullQuerySpanName;
import io.opentracing.contrib.cassandra.QuerySpanNameProvider.QuerySpanNameProvider;
...

// Initialize with custom prefix string
QuerySpanNameProvider querySpanNameProvider = PrefixedFullQuerySpanName.newBuilder().build("CUSTOM_PREFIX");


// Instantiate Tracing Cluster with QuerySpanNameProvider as an argument
Tracer tracer = ...
Cluster.Builder builder = ...
Cluster cluster = new TracingCluster(builder, tracer, querySpanNameProvider);


Session session = cluster.newSession();

// Execute query
session.execute("SELECT * FROM example.table WHERE field = ?", "test");

// Span is created with the full query as the span name, prefixed with the custom prefix, 
// "CUSTOM_PREFIX: SELECT * FROM example.table WHERE field = ?;"

// Span name will be parameterized if the original given query is parameterized.

QueryMethodTableSpanName

Returns formatted string Cassandra.[METHOD] - [TARGET_ENTITY] where [METHOD] is the Cassandra Method and [TARGET_ENTITY] is the entity that the method is acting on (view, keyspace, table, index).

For methods that require no target entity, returns Cassandra.[METHOD].

If a method does require a target entity, but none is found, returns Cassandra.[METHOD] - N/A.

The supported Cassandra methods are:

  • SELECT
  • INSERT
  • UPDATE
  • DELETE
  • BATCH
  • USE
  • CREATE MATERIALIZED VIEW
  • ALTER MATERIALIZED VIEW
  • DROP MATERIALIZED VIEW
  • CREATE KEYSPACE
  • ALTER KEYSPACE
  • DROP KEYSPACE
  • CREATE TABLE
  • ALTER TABLE
  • DROP TABLE
  • TRUNCATE
  • CREATE INDEX
  • DROP INDEX
import io.opentracing.contrib.cassandra.QuerySpanNameProvider.QueryMethodTableSpanName;
import io.opentracing.contrib.cassandra.QuerySpanNameProvider.QuerySpanNameProvider;
...

// Initialize
QuerySpanNameProvider querySpanNameProvider = QueryMethodTableSpanName.newBuilder().build();


// Instantiate Tracing Cluster with QuerySpanNameProvider as an argument
Tracer tracer = ...
Cluster.Builder builder = ...
Cluster cluster = new TracingCluster(builder, tracer, querySpanNameProvider);

Session session = cluster.newSession();

// Execute query
session.execute("SELECT * FROM example.table WHERE field = ?", "test");

// Span is created with the method and target entity in the name,
// "Cassandra.SELECT - example.table"

// Provider has support for additional qualifiers IF EXISTS and IF NOT EXISTS
session.execute("CREATE TABLE example.table;");
session.execute("CREATE TABLE IF NOT EXISTS example.table;")

// Two spans are created with the same name,
// "Cassandra.CREATE_TABLE - example.table"

License

Apache 2.0 License.

io.opentracing.contrib

3rd-Party OpenTracing API Contributions

3rd-party contributions that use OpenTracing. **The repositories in this org are *not* affiliated with the CNCF.**

Versions

Version
0.1.4
0.1.3
0.1.2
0.1.1
0.1.0
0.0.11
0.0.10
0.0.9
0.0.8
0.0.7
0.0.6
0.0.5
0.0.4
0.0.3
0.0.3-RC1
0.0.2
0.0.1