Skip to content

Add Prepare Request support to RequestTracker and OpenTelemetry extension #614

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

Merged
merged 9 commits into from
Sep 27, 2024
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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# ChangeLog - DataStax C# Driver

## 3.22.0

2024-09-30

### New Features

* [[CSHARP-969](https://datastax-oss.atlassian.net/browse/CSHARP-969)] Support OpenTelemetry Tracing

## 3.21.0

2024-09-09
Expand Down
3 changes: 2 additions & 1 deletion build/pack.bat
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
dotnet pack src\Cassandra -c Release
dotnet pack src\Extensions\Cassandra.AppMetrics -c Release
dotnet pack src\Extensions\Cassandra.AppMetrics -c Release
dotnet pack src\Extensions\Cassandra.OpenTelemetry -c Release
3 changes: 2 additions & 1 deletion build/pack.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
dotnet pack ./src/Cassandra -c Release
dotnet pack ./src/Extensions/Cassandra.AppMetrics -c Release
dotnet pack ./src/Extensions/Cassandra.AppMetrics -c Release
dotnet pack ./src/Extensions/Cassandra.OpenTelemetry -c Release
3 changes: 2 additions & 1 deletion doc/api-docs/docfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
{
"files": [
"src/Cassandra/**.csproj",
"src/Extensions/Cassandra.AppMetrics/**.csproj"
"src/Extensions/Cassandra.AppMetrics/**.csproj",
"src/Extensions/Cassandra.OpenTelemetry/**.csproj"
],
"src": "../../"
}
Expand Down
31 changes: 21 additions & 10 deletions doc/features/opentelemetry/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ Add the package `Cassandra.OpenTelemetry` to the project and add the extension m
```csharp
var cluster = Cluster.Builder()
.AddContactPoint(Program.ContactPoint)
.WithSessionName(Program.SessionName)
.WithOpenTelemetryInstrumentation()
.Build();
```
Expand All @@ -29,11 +28,13 @@ The table below displays the list of included attributes in this feature:
| Attribute | Description | Output Values|
|---|---|---|
| db.namespace | The keyspace name. | *keyspace in use* |
| db.operation.name | The type name of the operation being executed. | *Session Request* for session level calls and *Node Request* for node level calls |
| db.query.text | The database statement being executed. Included as [optional configuration](#include-statement-as-an-attribute). | *database statement in use* |
| db.system | An identifier for the database management system (DBMS) product being used. | cassandra |
| server.address | The host node. | e.g.: 127.0.0.1 |
| server.port | Port number. | e.g.: 9042 |
| db.operation.name | The type name of the operation being executed. | `Session_Request({RequestType})` for session level calls and `Node_Request({RequestType})` for node level calls |
| db.query.text | The database statement being executed. Included as [optional configuration](#include-statement-as-an-attribute). | e.g.: `SELECT * FROM system.local` |
| db.system | An identifier for the database management system (DBMS) product being used. | `cassandra` |
| server.address | The host node. | e.g.: `127.0.0.1` |
| server.port | Port number. | e.g.: `9042` |

Note that in some cases the driver does not know which keyspace a request is targeting because the driver doesn't parse CQL query strings.

The console log below displays an example of a full Cassandra activity:

Expand All @@ -43,15 +44,15 @@ Activity.SpanId: bd42cfc78b552cd1
Activity.TraceFlags: Recorded
Activity.ActivitySourceName: Cassandra.OpenTelemetry
Activity.ActivitySourceVersion: 1.0.0.0
Activity.DisplayName: Session Request
Activity.DisplayName: Session_Request(SimpleStatement) system
Activity.Kind: Client
Activity.StartTime: 2024-09-13T14:08:36.9762191Z
Activity.Duration: 00:00:00.0416284
Activity.Tags:
db.system: cassandra
db.operation.name: Session Request
db.operation.name: Session_Request(SimpleStatement)
db.namespace: system
db.query.text: SELECT * FROM system.local
db.query.text: SELECT * FROM local
Resource associated with Activity:
service.name: CassandraDemo
service.version: 1.0.0
Expand All @@ -72,7 +73,17 @@ As mentioned above, the attribute `db.query.text` is not included by default in
```csharp
var cluster = Cluster.Builder()
.AddContactPoint(Program.ContactPoint)
.WithSessionName(Program.SessionName)
.AddOpenTelemetryInstrumentation(options => options.IncludeDatabaseStatement = true)
.Build();
```

### Batch Statement size

By default, the `OpenTelemetry` extension only uses up to `5` child statements of a `BatchStatement` to generate the `db.query.text` tag. If you want to change this number, set the `CassandraInstrumentationOptions` property `BatchChildStatementLimit`:

```csharp
var cluster = Cluster.Builder()
.AddContactPoint(Program.ContactPoint)
.AddOpenTelemetryInstrumentation(options => options.BatchChildStatementLimit = 10)
.Build();
```
3 changes: 3 additions & 0 deletions docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ api_docs:
'3.19': http://docs.datastax.com/en/drivers/csharp/3.19
'3.20': http://docs.datastax.com/en/drivers/csharp/3.20
'3.21': http://docs.datastax.com/en/drivers/csharp/3.21
'3.22': http://docs.datastax.com/en/drivers/csharp/3.22
checks:
external_links:
exclude:
Expand All @@ -71,6 +72,8 @@ checks:
- 'https://twitter.com/datastax'
- 'https://academy.datastax.com/slack'
versions:
- name: '3.22'
ref: '3.22'
- name: '3.21'
ref: '3.21'
- name: '3.20'
Expand Down
8 changes: 4 additions & 4 deletions src/Cassandra.IntegrationTests/Core/ConnectionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void Prepare_Query()
using (var connection = CreateConnection())
{
connection.Open().Wait();
var request = new PrepareRequest(GetSerializer(), BasicQuery, null, null);
var request = new InternalPrepareRequest(GetSerializer(), BasicQuery, null, null);
var task = connection.Send(request);
task.Wait();
Assert.AreEqual(TaskStatus.RanToCompletion, task.Status);
Expand All @@ -102,7 +102,7 @@ public void Prepare_ResponseError_Faults_Task()
using (var connection = CreateConnection())
{
connection.Open().Wait();
var request = new PrepareRequest(GetSerializer(), "SELECT WILL FAIL", null, null);
var request = new InternalPrepareRequest(GetSerializer(), "SELECT WILL FAIL", null, null);
var task = connection.Send(request);
task.ContinueWith(t =>
{
Expand All @@ -121,7 +121,7 @@ public void Execute_Prepared_Test()
connection.Open().Wait();

//Prepare a query
var prepareRequest = new PrepareRequest(GetSerializer(), BasicQuery, null, null);
var prepareRequest = new InternalPrepareRequest(GetSerializer(), BasicQuery, null, null);
var task = connection.Send(prepareRequest);
var prepareOutput = ValidateResult<OutputPrepared>(task.Result);

Expand Down Expand Up @@ -150,7 +150,7 @@ public void Execute_Prepared_With_Param_Test()
{
connection.Open().Wait();

var prepareRequest = new PrepareRequest(GetSerializer(), "SELECT * FROM system.local WHERE key = ?", null, null);
var prepareRequest = new InternalPrepareRequest(GetSerializer(), "SELECT * FROM system.local WHERE key = ?", null, null);
var task = connection.Send(prepareRequest);
var prepareOutput = ValidateResult<OutputPrepared>(task.Result);

Expand Down
Loading