@@ -30,16 +30,18 @@ import {
3030import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node' ;
3131import { AsyncLocalStorageContextManager } from '@opentelemetry/context-async-hooks' ;
3232import {
33- DBSYSTEMVALUES_CASSANDRA ,
34- SEMATTRS_DB_STATEMENT ,
35- SEMATTRS_DB_SYSTEM ,
36- SEMATTRS_DB_USER ,
37- SEMATTRS_EXCEPTION_MESSAGE ,
38- SEMATTRS_EXCEPTION_STACKTRACE ,
39- SEMATTRS_EXCEPTION_TYPE ,
40- SEMATTRS_NET_PEER_NAME ,
41- SEMATTRS_NET_PEER_PORT ,
33+ ATTR_EXCEPTION_MESSAGE ,
34+ ATTR_EXCEPTION_STACKTRACE ,
35+ ATTR_EXCEPTION_TYPE ,
4236} from '@opentelemetry/semantic-conventions' ;
37+ import {
38+ DB_SYSTEM_VALUE_CASSANDRA ,
39+ ATTR_DB_STATEMENT ,
40+ ATTR_DB_SYSTEM ,
41+ ATTR_DB_USER ,
42+ ATTR_NET_PEER_NAME ,
43+ ATTR_NET_PEER_PORT ,
44+ } from '../src/semconv' ;
4345import * as assert from 'assert' ;
4446import * as testUtils from '@opentelemetry/contrib-test-utils' ;
4547import type * as CassandraDriver from 'cassandra-driver' ;
@@ -69,13 +71,13 @@ function assertSpan(
6971 customAttributes ?: Attributes
7072) {
7173 const attributes : Attributes = {
72- [ SEMATTRS_DB_SYSTEM ] : DBSYSTEMVALUES_CASSANDRA ,
73- [ SEMATTRS_DB_USER ] : 'cassandra' ,
74+ [ ATTR_DB_SYSTEM ] : DB_SYSTEM_VALUE_CASSANDRA ,
75+ [ ATTR_DB_USER ] : 'cassandra' ,
7476 ...customAttributes ,
7577 } ;
7678
7779 if ( query !== undefined ) {
78- attributes [ SEMATTRS_DB_STATEMENT ] = query ;
80+ attributes [ ATTR_DB_STATEMENT ] = query ;
7981 }
8082
8183 const spanStatus =
@@ -113,23 +115,23 @@ function assertErrorSpan(
113115 const [ span ] = spans ;
114116
115117 const attributes : Attributes = {
116- [ SEMATTRS_DB_SYSTEM ] : DBSYSTEMVALUES_CASSANDRA ,
117- [ SEMATTRS_DB_USER ] : 'cassandra' ,
118+ [ ATTR_DB_SYSTEM ] : DB_SYSTEM_VALUE_CASSANDRA ,
119+ [ ATTR_DB_USER ] : 'cassandra' ,
118120 ...customAttributes ,
119121 } ;
120122
121123 if ( query !== undefined ) {
122- attributes [ SEMATTRS_DB_STATEMENT ] = query ;
124+ attributes [ ATTR_DB_STATEMENT ] = query ;
123125 }
124126
125127 const events = [
126128 {
127129 name : 'exception' ,
128130 droppedAttributesCount : 0 ,
129131 attributes : {
130- [ SEMATTRS_EXCEPTION_STACKTRACE ] : error . stack ,
131- [ SEMATTRS_EXCEPTION_MESSAGE ] : error . message ,
132- [ SEMATTRS_EXCEPTION_TYPE ] : String ( error . code ) ,
132+ [ ATTR_EXCEPTION_STACKTRACE ] : error . stack ,
133+ [ ATTR_EXCEPTION_MESSAGE ] : error . message ,
134+ [ ATTR_EXCEPTION_TYPE ] : String ( error . code ) ,
133135 } ,
134136 time : span . events [ 0 ] . time ,
135137 } ,
@@ -193,16 +195,16 @@ describe('CassandraDriverInstrumentation', () => {
193195 it ( 'creates a span for promise based execute' , async ( ) => {
194196 await client . execute ( 'select * from ot.test' ) ;
195197 assertSingleSpan ( 'cassandra-driver.execute' , undefined , undefined , {
196- [ SEMATTRS_NET_PEER_NAME ] : cassandraContactPoint ,
197- [ SEMATTRS_NET_PEER_PORT ] : 9042 ,
198+ [ ATTR_NET_PEER_NAME ] : cassandraContactPoint ,
199+ [ ATTR_NET_PEER_PORT ] : 9042 ,
198200 } ) ;
199201 } ) ;
200202
201203 it ( 'creates a span for callback based execute' , done => {
202204 client . execute ( 'select * from ot.test' , ( ) => {
203205 assertSingleSpan ( 'cassandra-driver.execute' , undefined , undefined , {
204- [ SEMATTRS_NET_PEER_NAME ] : cassandraContactPoint ,
205- [ SEMATTRS_NET_PEER_PORT ] : 9042 ,
206+ [ ATTR_NET_PEER_NAME ] : cassandraContactPoint ,
207+ [ ATTR_NET_PEER_PORT ] : 9042 ,
206208 } ) ;
207209 done ( ) ;
208210 } ) ;
@@ -213,8 +215,8 @@ describe('CassandraDriverInstrumentation', () => {
213215 await client . execute ( 'selec * from' ) ;
214216 } catch ( e : any ) {
215217 assertErrorSpan ( 'cassandra-driver.execute' , e , undefined , {
216- [ SEMATTRS_NET_PEER_NAME ] : cassandraContactPoint ,
217- [ SEMATTRS_NET_PEER_PORT ] : 9042 ,
218+ [ ATTR_NET_PEER_NAME ] : cassandraContactPoint ,
219+ [ ATTR_NET_PEER_PORT ] : 9042 ,
218220 } ) ;
219221 return ;
220222 }
@@ -243,17 +245,17 @@ describe('CassandraDriverInstrumentation', () => {
243245 const query = 'select * from ot.test' ;
244246 await client . execute ( query ) ;
245247 assertSingleSpan ( 'cassandra-driver.execute' , query , undefined , {
246- [ SEMATTRS_NET_PEER_NAME ] : cassandraContactPoint ,
247- [ SEMATTRS_NET_PEER_PORT ] : 9042 ,
248+ [ ATTR_NET_PEER_NAME ] : cassandraContactPoint ,
249+ [ ATTR_NET_PEER_PORT ] : 9042 ,
248250 } ) ;
249251 } ) ;
250252
251253 it ( 'truncates long queries' , async ( ) => {
252254 const query = 'select userid, count from ot.test' ;
253255 await client . execute ( query ) ;
254256 const customAttributes = {
255- [ SEMATTRS_NET_PEER_NAME ] : cassandraContactPoint ,
256- [ SEMATTRS_NET_PEER_PORT ] : 9042 ,
257+ [ ATTR_NET_PEER_NAME ] : cassandraContactPoint ,
258+ [ ATTR_NET_PEER_PORT ] : 9042 ,
257259 } ;
258260 assertSingleSpan (
259261 'cassandra-driver.execute' ,
@@ -299,8 +301,8 @@ describe('CassandraDriverInstrumentation', () => {
299301 assertAttributeInSingleSpan ( 'cassandra-driver.execute' , {
300302 [ customAttributeName ] : customAttributeValue ,
301303 [ responseAttributeName ] : 2 ,
302- [ SEMATTRS_NET_PEER_NAME ] : cassandraContactPoint ,
303- [ SEMATTRS_NET_PEER_PORT ] : 9042 ,
304+ [ ATTR_NET_PEER_NAME ] : cassandraContactPoint ,
305+ [ ATTR_NET_PEER_PORT ] : 9042 ,
304306 } ) ;
305307 } ) ;
306308
@@ -322,8 +324,8 @@ describe('CassandraDriverInstrumentation', () => {
322324
323325 assertAttributeInSingleSpan ( 'cassandra-driver.execute' , {
324326 [ hookAttributeName ] : hookAttributeValue ,
325- [ SEMATTRS_NET_PEER_NAME ] : cassandraContactPoint ,
326- [ SEMATTRS_NET_PEER_PORT ] : 9042 ,
327+ [ ATTR_NET_PEER_NAME ] : cassandraContactPoint ,
328+ [ ATTR_NET_PEER_PORT ] : 9042 ,
327329 } ) ;
328330 } ) ;
329331 } ) ;
@@ -346,8 +348,8 @@ describe('CassandraDriverInstrumentation', () => {
346348 it ( 'creates a span for callback based batch' , done => {
347349 client . batch ( [ q1 , q2 ] , ( ) => {
348350 assertSingleSpan ( 'cassandra-driver.batch' , undefined , undefined , {
349- [ SEMATTRS_NET_PEER_NAME ] : cassandraContactPoint ,
350- [ SEMATTRS_NET_PEER_PORT ] : 9042 ,
351+ [ ATTR_NET_PEER_NAME ] : cassandraContactPoint ,
352+ [ ATTR_NET_PEER_PORT ] : 9042 ,
351353 } ) ;
352354 done ( ) ;
353355 } ) ;
@@ -399,8 +401,8 @@ describe('CassandraDriverInstrumentation', () => {
399401 // stream internally uses execute
400402 assert . strictEqual ( spans . length , 2 ) ;
401403 assertSpan ( spans [ 0 ] , 'cassandra-driver.execute' , undefined , undefined , {
402- [ SEMATTRS_NET_PEER_NAME ] : cassandraContactPoint ,
403- [ SEMATTRS_NET_PEER_PORT ] : 9042 ,
404+ [ ATTR_NET_PEER_NAME ] : cassandraContactPoint ,
405+ [ ATTR_NET_PEER_PORT ] : 9042 ,
404406 } ) ;
405407 assertSpan ( spans [ 1 ] , 'cassandra-driver.stream' ) ;
406408 }
0 commit comments