Skip to content

Commit 10ad71f

Browse files
committed
fixing bug in trace for errors
1 parent bed7cf9 commit 10ad71f

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ assetInstallTime.properties
1414
/quick-start/input
1515
/quick-start/plugins
1616
flow.properties
17+
node_modules/

marklogic-data-hub/src/main/resources/ml-modules/root/com.marklogic.hub/lib/flow-lib.xqy

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ declare function flow:run-collector(
410410
}
411411
catch($ex) {
412412
xdmp:log($ex),
413-
trace:create-trace(
413+
trace:log-error-trace(
414414
trace:error-trace(
415415
(),
416416
$module-uri,
@@ -425,7 +425,7 @@ declare function flow:run-collector(
425425
xdmp:rethrow()
426426
}
427427
let $_ :=
428-
trace:create-trace(
428+
trace:log-trace(
429429
trace:plugin-trace(
430430
null-node {},
431431
$module-uri,
@@ -647,7 +647,7 @@ declare function flow:run-plugin(
647647
}
648648
catch($ex) {
649649
xdmp:log($ex),
650-
trace:create-trace(
650+
trace:log-error-trace(
651651
trace:error-trace(
652652
$identifier,
653653
$module-uri,
@@ -689,7 +689,7 @@ declare function flow:run-plugin(
689689
$resp
690690
let $_ :=
691691
if (trace:enabled()) then
692-
trace:create-trace(
692+
trace:log-trace(
693693
trace:plugin-trace(
694694
$identifier,
695695
$module-uri,
@@ -738,7 +738,7 @@ declare function flow:run-writer(
738738
}
739739
catch($ex) {
740740
xdmp:log($ex),
741-
trace:create-trace(
741+
trace:log-error-trace(
742742
trace:error-trace(
743743
$identifier,
744744
$module-uri,
@@ -755,7 +755,7 @@ declare function flow:run-writer(
755755
}
756756
let $duration := xdmp:elapsed-time() - $before
757757
let $_ :=
758-
trace:create-trace(
758+
trace:log-trace(
759759
trace:plugin-trace(
760760
$identifier,
761761
$module-uri,

marklogic-data-hub/src/main/resources/ml-modules/root/com.marklogic.hub/lib/trace-lib.xqy

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,24 @@ declare function trace:enabled() as xs:boolean
3838
xdmp:get-server-field("HUB-TRACING-ENABLED", fn:false())
3939
};
4040

41-
declare function trace:create-trace($trace)
41+
declare function trace:log-trace($trace)
4242
{
43-
if (trace:enabled()) then
43+
trace:create-trace($trace, fn:false())
44+
};
45+
46+
declare function trace:log-error-trace($trace)
47+
{
48+
trace:create-trace($trace, fn:true())
49+
};
50+
51+
declare %private function trace:create-trace($trace, $force as xs:boolean)
52+
{
53+
if ($force or trace:enabled()) then
4454
xdmp:eval('
55+
xquery version "1.0-ml";
56+
57+
declare option xdmp:mapping "false";
58+
4559
declare variable $trace external;
4660
4761
xdmp:document-insert(
@@ -115,7 +129,7 @@ declare function trace:error-trace(
115129
let $_ := map:put($config, "ignore-attribute-names", xs:QName("xsi:schemaLocation"))
116130
let $_ := map:put($config, "whitespace", "ignore")
117131
return
118-
json:transform-to-json($error, $config)
132+
json:transform-to-json($error, $config)/object-node()
119133
return
120134
object-node {
121135
"trace": object-node {
@@ -125,7 +139,7 @@ declare function trace:error-trace(
125139
"plugin-type": $plugin-type,
126140
"flow-type": $flow-type,
127141
"error": $error,
128-
"input": $input,
142+
"input": ($input, null-node{})[1],
129143
"duration": $duration
130144
}
131145
}

0 commit comments

Comments
 (0)