@@ -29,6 +29,7 @@ import {
2929import * as kurrentdb from "@kurrent/kurrentdb-client" ;
3030import { KurrentAttributes } from "@kurrent/opentelemetry/src/attributes" ;
3131import { v4 } from "uuid" ;
32+ import { SpanStatusCode } from "@opentelemetry/api" ;
3233
3334const memoryExporter = new InMemorySpanExporter ( ) ;
3435const otlpExporter = new OTLPTraceExporter ( { url : "http://localhost:4317" } ) ; // change this to your OTLP receiver address
@@ -214,5 +215,76 @@ describe("[sample] opentelemetry", () => {
214215 [ KurrentAttributes . DATABASE_OPERATION ] : "multiStreamAppend" ,
215216 } ) ;
216217 } ) ;
218+
219+ test ( "does not trace if result contains failures" , async ( ) => {
220+ // Arrange
221+ const defer = new Defer ( ) ;
222+
223+ const { KurrentDBClient, jsonEvent } = await import (
224+ "@kurrent/kurrentdb-client"
225+ ) ;
226+
227+ const client = KurrentDBClient . connectionString ( node . connectionString ( ) ) ;
228+
229+ const firstOrderReq : kurrentdb . AppendStreamRequest = {
230+ streamName : `order-${ v4 ( ) } ` ,
231+ events : [
232+ jsonEvent ( {
233+ type : "OrderPlaced" ,
234+ data : { id : v4 ( ) } ,
235+ } ) ,
236+ jsonEvent ( {
237+ type : "PaymentProcessed" ,
238+ data : { id : v4 ( ) } ,
239+ } ) ,
240+ ] ,
241+ expectedState : kurrentdb . ANY ,
242+ } ;
243+
244+ const secondOrderReq : kurrentdb . AppendStreamRequest = {
245+ streamName : `order-${ v4 ( ) } ` ,
246+ events : [
247+ jsonEvent ( {
248+ type : "OrderPlaced" ,
249+ data : { customerId : "cust-456" } ,
250+ } ) ,
251+ ] ,
252+ expectedState : kurrentdb . STREAM_EXISTS ,
253+ } ;
254+
255+ // Act
256+ const appendResponse = await client . multiStreamAppend ( [
257+ firstOrderReq ,
258+ secondOrderReq ,
259+ ] ) ;
260+
261+ expect ( appendResponse . success ) . toBeFalsy ( ) ;
262+
263+ // Assert
264+ const firstOrderAppendSpans = getSpans (
265+ KurrentAttributes . STREAM_APPEND ,
266+ firstOrderReq . streamName
267+ ) ;
268+ const secondOrderAppendSpans = getSpans (
269+ KurrentAttributes . STREAM_APPEND ,
270+ secondOrderReq . streamName
271+ ) ;
272+
273+ expect ( firstOrderAppendSpans ) . toHaveLength ( 1 ) ;
274+ expect ( secondOrderAppendSpans ) . toHaveLength ( 1 ) ;
275+
276+ expect ( firstOrderAppendSpans [ 0 ] . attributes ) . toMatchObject ( {
277+ [ KurrentAttributes . KURRENT_DB_STREAM ] : firstOrderReq . streamName ,
278+ [ KurrentAttributes . SERVER_ADDRESS ] : node . endpoints [ 0 ] . address ,
279+ [ KurrentAttributes . SERVER_PORT ] : node . endpoints [ 0 ] . port . toString ( ) ,
280+ [ KurrentAttributes . DATABASE_SYSTEM ] : moduleName ,
281+ [ KurrentAttributes . DATABASE_OPERATION ] : "multiStreamAppend" ,
282+ } ) ;
283+
284+ expect ( secondOrderAppendSpans [ 0 ] . status . code ) . toBe ( SpanStatusCode . ERROR ) ;
285+ expect ( secondOrderAppendSpans [ 0 ] . status . message ) . toBe (
286+ "wrong_expected_revision"
287+ ) ;
288+ } ) ;
217289 } ) ;
218290} ) ;
0 commit comments