@voxgig/sdkgen 4.49.1 → 4.50.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/voxgig-sdkgen +1 -1
- package/package.json +1 -1
- package/project/.sdk/tm/c/feature/debug.c +1 -0
- package/project/.sdk/tm/c/feature/telemetry.c +1 -0
- package/project/.sdk/tm/c/tests/feature_test.c +38 -0
- package/project/.sdk/tm/clojure/src/sdk/features.clj +2 -0
- package/project/.sdk/tm/clojure/test/sdk/test/feature.clj +14 -0
- package/project/.sdk/tm/cpp/feature/debug.hpp +1 -0
- package/project/.sdk/tm/cpp/feature/telemetry.hpp +1 -0
- package/project/.sdk/tm/cpp/test/feature_test.cpp +29 -0
- package/project/.sdk/tm/csharp/feature/DebugFeature.cs +1 -0
- package/project/.sdk/tm/csharp/feature/TelemetryFeature.cs +1 -0
- package/project/.sdk/tm/csharp/test/FeatureTest.cs +25 -0
- package/project/.sdk/tm/elixir/lib/projectname/feature/debug.ex +1 -0
- package/project/.sdk/tm/elixir/lib/projectname/feature/telemetry.ex +1 -0
- package/project/.sdk/tm/elixir/test/feature_test.exs +23 -0
- package/project/.sdk/tm/go/feature/debug_feature.go +3 -2
- package/project/.sdk/tm/go/feature/telemetry_feature.go +5 -4
- package/project/.sdk/tm/go/test/feature_test.go +40 -0
- package/project/.sdk/tm/java/feature/DebugFeature.java +1 -0
- package/project/.sdk/tm/java/feature/TelemetryFeature.java +1 -0
- package/project/.sdk/tm/java/test/FeatureTest.java +28 -0
- package/project/.sdk/tm/js/src/feature/debug/DebugFeature.js +1 -0
- package/project/.sdk/tm/js/src/feature/telemetry/TelemetryFeature.js +1 -0
- package/project/.sdk/tm/js/test/feature.test.js +17 -0
- package/project/.sdk/tm/kotlin/feature/DebugFeature.kt +1 -0
- package/project/.sdk/tm/kotlin/feature/TelemetryFeature.kt +1 -0
- package/project/.sdk/tm/kotlin/test/FeatureTest.kt +20 -0
- package/project/.sdk/tm/lua/feature/debug_feature.lua +1 -0
- package/project/.sdk/tm/lua/feature/telemetry_feature.lua +1 -0
- package/project/.sdk/tm/lua/test/feature_test.lua +27 -0
- package/project/.sdk/tm/ocaml/sdk_features.ml +2 -0
- package/project/.sdk/tm/ocaml/test/t_feature.ml +16 -0
- package/project/.sdk/tm/perl/feature/debug_feature.pm +1 -0
- package/project/.sdk/tm/perl/feature/telemetry_feature.pm +1 -0
- package/project/.sdk/tm/perl/t/feature.t +20 -0
- package/project/.sdk/tm/php/feature/DebugFeature.php +1 -0
- package/project/.sdk/tm/php/feature/TelemetryFeature.php +1 -0
- package/project/.sdk/tm/php/test/FeatureTest.php +22 -0
- package/project/.sdk/tm/py/pkg/feature/debug_feature.py +1 -0
- package/project/.sdk/tm/py/pkg/feature/telemetry_feature.py +1 -0
- package/project/.sdk/tm/py/test/test_feature.py +23 -0
- package/project/.sdk/tm/rb/feature/debug_feature.rb +1 -0
- package/project/.sdk/tm/rb/feature/telemetry_feature.rb +1 -0
- package/project/.sdk/tm/rb/test/feature_test.rb +19 -0
- package/project/.sdk/tm/rust/feature/debug.rs +1 -0
- package/project/.sdk/tm/rust/feature/telemetry.rs +1 -0
- package/project/.sdk/tm/rust/tests/feature_test.rs +41 -0
- package/project/.sdk/tm/scala/feature/DebugFeature.scala +1 -0
- package/project/.sdk/tm/scala/feature/TelemetryFeature.scala +1 -0
- package/project/.sdk/tm/scala/sdktest/SdkTestMain.scala +24 -1
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/DebugFeature.swift +1 -0
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/TelemetryFeature.swift +1 -0
- package/project/.sdk/tm/swift/Tests/ProjectNameSDKTests/FeatureTest.swift +24 -0
- package/project/.sdk/tm/ts/src/feature/debug/DebugFeature.ts +1 -0
- package/project/.sdk/tm/ts/src/feature/telemetry/TelemetryFeature.ts +1 -0
- package/project/.sdk/tm/ts/test/feature.test.ts +17 -0
- package/project/.sdk/tm/zig/feature/debug.zig +1 -0
- package/project/.sdk/tm/zig/feature/telemetry.zig +1 -0
- package/project/.sdk/tm/zig/test/feature_test.zig +35 -0
- package/project/sdkgen-package.json +1 -1
package/bin/voxgig-sdkgen
CHANGED
package/package.json
CHANGED
|
@@ -125,6 +125,7 @@ static void debug_pre_request(DebugFeature* df, Context* ctx) {
|
|
|
125
125
|
voxgig_value* entry = v_map();
|
|
126
126
|
char* op = dot_join(entity, opname);
|
|
127
127
|
setp(entry, "op", v_str(op));
|
|
128
|
+
setp(entry, "correlationId", v_str(ctx->id));
|
|
128
129
|
setp(entry, "start", v_num((double)fopt_now_call(df->options)));
|
|
129
130
|
if (ctx->spec) {
|
|
130
131
|
Spec* s = ctx->spec;
|
|
@@ -116,6 +116,7 @@ static void telemetry_pre_point(TelemetryFeature* tf, Context* ctx) {
|
|
|
116
116
|
char* spanid = telemetry_id(tf, "span");
|
|
117
117
|
setp(span, "spanId", v_str(spanid));
|
|
118
118
|
free(spanid);
|
|
119
|
+
setp(span, "correlationId", v_str(ctx->id));
|
|
119
120
|
|
|
120
121
|
size_t nl = strlen(entity) + strlen(opname) + 2; // '.' + '\0'
|
|
121
122
|
char* namebuf = (char*)malloc(nl);
|
|
@@ -882,6 +882,42 @@ static void test_audit_inactive_records_nothing(void) {
|
|
|
882
882
|
CHECK_INT_EQ(fh_track_int(f, "records"), 0, "audit inactive: no records");
|
|
883
883
|
}
|
|
884
884
|
|
|
885
|
+
// =============================================================================
|
|
886
|
+
// one call, one id
|
|
887
|
+
// =============================================================================
|
|
888
|
+
|
|
889
|
+
static void test_telemetry_debug_audit_carry_one_calls_context_id(void) {
|
|
890
|
+
if (!fh_present("telemetry,debug,audit")) return;
|
|
891
|
+
voxgig_value* spans = v_list();
|
|
892
|
+
voxgig_value* entries = v_list();
|
|
893
|
+
voxgig_value* records = v_list();
|
|
894
|
+
Feature* tf = feature_telemetry_new();
|
|
895
|
+
Feature* df = feature_debug_new();
|
|
896
|
+
Feature* af = feature_audit_new();
|
|
897
|
+
FhFeat feats[] = {
|
|
898
|
+
{tf, cmap(1, "exporter", vfn(collect_fn, spans))},
|
|
899
|
+
{df, cmap(1, "onEntry", vfn(collect_fn, entries))},
|
|
900
|
+
{af, cmap(1, "sink", vfn(collect_fn, records))},
|
|
901
|
+
};
|
|
902
|
+
FhHarness h = fh_make(NULL, feats, 3);
|
|
903
|
+
fh_op(&h, op_load());
|
|
904
|
+
FhOpSpec ol; memset(&ol, 0, sizeof(ol)); ol.op = "list";
|
|
905
|
+
fh_op(&h, ol);
|
|
906
|
+
CHECK_INT_EQ((int)voxgig_list_len(voxgig_as_list(records)), 2, "one id: 2 audit records");
|
|
907
|
+
CHECK_INT_EQ((int)voxgig_list_len(voxgig_as_list(spans)), 2, "one id: 2 spans");
|
|
908
|
+
CHECK_INT_EQ((int)voxgig_list_len(voxgig_as_list(entries)), 2, "one id: 2 debug entries");
|
|
909
|
+
const char* calls[2];
|
|
910
|
+
for (int i = 0; i < 2; i++) {
|
|
911
|
+
calls[i] = get_str(voxgig_getelem(records, v_int(i), v_undef()), "correlationId");
|
|
912
|
+
CHECK(calls[i] && calls[i][0] != '\0', "one id: audit id is a non-empty string");
|
|
913
|
+
CHECK_STR_EQ(get_str(voxgig_getelem(spans, v_int(i), v_undef()), "correlationId"),
|
|
914
|
+
calls[i], "one id: span id is the audit id");
|
|
915
|
+
CHECK_STR_EQ(get_str(voxgig_getelem(entries, v_int(i), v_undef()), "correlationId"),
|
|
916
|
+
calls[i], "one id: debug entry id is the audit id");
|
|
917
|
+
}
|
|
918
|
+
CHECK(calls[0] && calls[1] && strcmp(calls[0], calls[1]) != 0, "one id: one id per call");
|
|
919
|
+
}
|
|
920
|
+
|
|
885
921
|
// =============================================================================
|
|
886
922
|
// clienttrack
|
|
887
923
|
// =============================================================================
|
|
@@ -1212,6 +1248,8 @@ int main(void) {
|
|
|
1212
1248
|
RUN(test_audit_default_actor_anonymous);
|
|
1213
1249
|
RUN(test_audit_injected_clock);
|
|
1214
1250
|
RUN(test_audit_inactive_records_nothing);
|
|
1251
|
+
// one call, one id
|
|
1252
|
+
RUN(test_telemetry_debug_audit_carry_one_calls_context_id);
|
|
1215
1253
|
// clienttrack
|
|
1216
1254
|
RUN(test_clienttrack_stable_client_id_unique_request_ids_ua);
|
|
1217
1255
|
RUN(test_clienttrack_does_not_clobber_caller_ua);
|
|
@@ -1054,6 +1054,7 @@
|
|
|
1054
1054
|
(when (active? fa)
|
|
1055
1055
|
(let [op (core/oget ctx :op)
|
|
1056
1056
|
span (vs/jm "traceId" (gen-id2 "trace") "spanId" (gen-id2 "span")
|
|
1057
|
+
"correlationId" (core/oget ctx :id)
|
|
1057
1058
|
"name" (str (if op (core/op-entity op) "_") "." (if op (core/op-name op) "_"))
|
|
1058
1059
|
"start" (now-ms fa) "end" nil "durationMs" nil "ok" nil)]
|
|
1059
1060
|
(swap! fa update :spans assoc ctx span)
|
|
@@ -1175,6 +1176,7 @@
|
|
|
1175
1176
|
method (when spec (core/oget spec :method))
|
|
1176
1177
|
headers (when spec (core/oget spec :headers))
|
|
1177
1178
|
entry (vs/jm "op" (str (if op (core/op-entity op) "_") "." (if op (core/op-name op) "_"))
|
|
1179
|
+
"correlationId" (core/oget ctx :id)
|
|
1178
1180
|
"method" method "url" url "headers" (redact ctx headers) "start" (now-ms fa)
|
|
1179
1181
|
"status" nil "ok" nil "durationMs" nil "error" nil)]
|
|
1180
1182
|
(swap! fa update :entries assoc ctx entry))))
|
|
@@ -517,6 +517,20 @@
|
|
|
517
517
|
(t/is-eq (mget (vs/getelem recs 0) "seq") 2 "seq 2")
|
|
518
518
|
(t/is-eq (mget (vs/getelem recs 1) "seq") 3 "seq 3")))))
|
|
519
519
|
|
|
520
|
+
;; ---- one call, one id ----
|
|
521
|
+
(check "telemetry-debug-audit-one-call-context-id" "telemetry"
|
|
522
|
+
(fn [] (when (and (feature-present? "debug") (feature-present? "audit"))
|
|
523
|
+
(let [h (make-harness [(fspec "telemetry") (fspec "debug") (fspec "audit")])
|
|
524
|
+
ids (fn [recs] (mapv (fn [rec] (mget rec "correlationId")) recs))]
|
|
525
|
+
(h-op h)
|
|
526
|
+
(h-op h :opname "list")
|
|
527
|
+
(let [calls (ids (mget (h-track h "_audit") "records"))]
|
|
528
|
+
(t/is-eq (count calls) 2 "one audit record per call")
|
|
529
|
+
(t/is-true (every? (fn [id] (and (string? id) (not= "" id))) calls) (pr-str calls))
|
|
530
|
+
(t/is-true (not= (nth calls 0) (nth calls 1)) "a different id per call")
|
|
531
|
+
(t/is-eq (ids (mget (h-track h "_telemetry") "spans")) calls "span ids")
|
|
532
|
+
(t/is-eq (ids (mget (h-track h "_debug") "entries")) calls "debug entry ids"))))))
|
|
533
|
+
|
|
520
534
|
;; ---- clienttrack ----
|
|
521
535
|
(check "clienttrack-stable-id-unique-req" "clienttrack"
|
|
522
536
|
(fn [] (let [[server calls] (recording-server nil)
|
|
@@ -49,6 +49,7 @@ public:
|
|
|
49
49
|
|
|
50
50
|
Value entry = vmap();
|
|
51
51
|
map_put(entry, "op", Value(entity + "." + opname));
|
|
52
|
+
map_put(entry, "correlationId", Value(ctx->id));
|
|
52
53
|
map_put(entry, "start", Value((long long) fopt::foptNow(options)()));
|
|
53
54
|
if (ctx->spec) {
|
|
54
55
|
map_put(entry, "method", Value(ctx->spec->method));
|
|
@@ -52,6 +52,7 @@ public:
|
|
|
52
52
|
Value span = vmap();
|
|
53
53
|
map_put(span, "traceId", Value(id("trace")));
|
|
54
54
|
map_put(span, "spanId", Value(id("span")));
|
|
55
|
+
map_put(span, "correlationId", Value(ctx->id));
|
|
55
56
|
map_put(span, "name", Value(entity + "." + opname));
|
|
56
57
|
map_put(span, "start", Value((long long) fopt::foptNow(options)()));
|
|
57
58
|
pending[ctx->id] = span;
|
|
@@ -700,6 +700,33 @@ static void audit_inactiveRecordsNothing() {
|
|
|
700
700
|
ASSERT_EQ((int)f->records.as_list()->size(), 0, "expected no records");
|
|
701
701
|
}
|
|
702
702
|
|
|
703
|
+
// ============================ one call, one id =========================
|
|
704
|
+
|
|
705
|
+
static void telemetryDebugAudit_carryOneCallsContextId() {
|
|
706
|
+
if (!have({"telemetry", "debug", "audit"})) return;
|
|
707
|
+
auto tf = std::make_shared<TelemetryFeature>();
|
|
708
|
+
auto df = std::make_shared<DebugFeature>();
|
|
709
|
+
auto af = std::make_shared<AuditFeature>();
|
|
710
|
+
auto h = fhMake(nullptr, {FF(tf, Value::undef()), FF(df, Value::undef()), FF(af, Value::undef())});
|
|
711
|
+
h->op(fhOp("load"));
|
|
712
|
+
h->op(fhOp("list"));
|
|
713
|
+
auto ids = [](const Value& recs) {
|
|
714
|
+
Value out = vlist();
|
|
715
|
+
for (const auto& rec : *recs.as_list()) out.as_list()->push_back(getp(rec, "correlationId"));
|
|
716
|
+
return out;
|
|
717
|
+
};
|
|
718
|
+
Value calls = ids(af->records);
|
|
719
|
+
ASSERT_EQ((int)calls.as_list()->size(), 2, "expected 2 audit records");
|
|
720
|
+
for (const auto& id : *calls.as_list()) {
|
|
721
|
+
ASSERT_TRUE(id.is_string() && !id.as_string().empty(),
|
|
722
|
+
"expected a non-empty string id, got " + sdktest::vstr(calls));
|
|
723
|
+
}
|
|
724
|
+
ASSERT_TRUE(vs::getelem(calls, Value(int64_t(0))) != vs::getelem(calls, Value(int64_t(1))),
|
|
725
|
+
"expected one id per call");
|
|
726
|
+
ASSERT_EQ_VAL(ids(tf->spans), calls, "expected the spans' ids");
|
|
727
|
+
ASSERT_EQ_VAL(ids(df->entries), calls, "expected the debug entries' ids");
|
|
728
|
+
}
|
|
729
|
+
|
|
703
730
|
// ============================ clienttrack ==============================
|
|
704
731
|
|
|
705
732
|
static void clienttrack_stableClientIdUniqueRequestIdsUa() {
|
|
@@ -968,6 +995,8 @@ int main() {
|
|
|
968
995
|
T_RUN(audit_injectedClock);
|
|
969
996
|
T_RUN(audit_inactiveRecordsNothing);
|
|
970
997
|
|
|
998
|
+
T_RUN(telemetryDebugAudit_carryOneCallsContextId);
|
|
999
|
+
|
|
971
1000
|
T_RUN(clienttrack_stableClientIdUniqueRequestIdsUa);
|
|
972
1001
|
T_RUN(clienttrack_doesNotClobberCallerUa);
|
|
973
1002
|
T_RUN(clienttrack_injectedIdgenFixedSession);
|
|
@@ -1020,6 +1020,31 @@ public class FeatureAuditTest
|
|
|
1020
1020
|
}
|
|
1021
1021
|
}
|
|
1022
1022
|
|
|
1023
|
+
// --- one call, one id -----------------------------------------------------------
|
|
1024
|
+
|
|
1025
|
+
public class FeatureCorrelationTest
|
|
1026
|
+
{
|
|
1027
|
+
[Fact]
|
|
1028
|
+
public void TelemetryDebugAndAuditCarryOneCallsContextId()
|
|
1029
|
+
{
|
|
1030
|
+
if (Fh.SkipWithout("telemetry", "debug", "audit")) return;
|
|
1031
|
+
var telemetry = new TelemetryFeature();
|
|
1032
|
+
var debug = new DebugFeature();
|
|
1033
|
+
var audit = new AuditFeature();
|
|
1034
|
+
var h = Fh.Make(null, (telemetry, null), (debug, null), (audit, null));
|
|
1035
|
+
h.Op(new FhOpSpec { Op = "load" });
|
|
1036
|
+
h.Op(new FhOpSpec { Op = "list" });
|
|
1037
|
+
static List<object?> Ids(List<Dictionary<string, object?>> recs) =>
|
|
1038
|
+
recs.Select(rec => rec.GetValueOrDefault("correlationId")).ToList();
|
|
1039
|
+
var calls = Ids(audit.Records);
|
|
1040
|
+
Assert.Equal(2, calls.Count);
|
|
1041
|
+
Assert.All(calls, id => Assert.True(id is string s && s != "", $"context id: {id}"));
|
|
1042
|
+
Assert.NotEqual(calls[0], calls[1]);
|
|
1043
|
+
Assert.Equal(calls, Ids(telemetry.Spans));
|
|
1044
|
+
Assert.Equal(calls, Ids(debug.Entries));
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1023
1048
|
// --- clienttrack ----------------------------------------------------------------
|
|
1024
1049
|
|
|
1025
1050
|
public class FeatureClienttrackTest
|
|
@@ -51,6 +51,7 @@ defmodule ProjectName.Feature.Debug do
|
|
|
51
51
|
entry =
|
|
52
52
|
S.jm([
|
|
53
53
|
"op", opname,
|
|
54
|
+
"correlationId", S.getprop(ctx, "id"),
|
|
54
55
|
"method", if(spec != nil, do: S.getprop(spec, "method"), else: nil),
|
|
55
56
|
"url",
|
|
56
57
|
if(spec != nil, do: H.or_(S.getprop(spec, "url"), S.getprop(spec, "path")), else: nil),
|
|
@@ -714,6 +714,29 @@ defmodule ProjectName.FeatureTest do
|
|
|
714
714
|
end
|
|
715
715
|
end
|
|
716
716
|
|
|
717
|
+
# === one call, one id ===
|
|
718
|
+
|
|
719
|
+
test "telemetry, debug and audit carry one call's context id" do
|
|
720
|
+
if has?("telemetry") and has?("debug") and has?("audit") do
|
|
721
|
+
h = harness([fspec("telemetry"), fspec("debug"), fspec("audit")])
|
|
722
|
+
FH.op(h, %{op: "load"})
|
|
723
|
+
FH.op(h, %{op: "list"})
|
|
724
|
+
|
|
725
|
+
ids = fn recs ->
|
|
726
|
+
Enum.map(0..(S.size(recs) - 1)//1, fn i ->
|
|
727
|
+
S.getprop(S.getelem(recs, i), "correlationId")
|
|
728
|
+
end)
|
|
729
|
+
end
|
|
730
|
+
|
|
731
|
+
calls = ids.(S.getprop(track(h, "_audit"), "records"))
|
|
732
|
+
assert length(calls) == 2
|
|
733
|
+
assert Enum.all?(calls, fn id -> is_binary(id) and id != "" end), inspect(calls)
|
|
734
|
+
assert Enum.at(calls, 0) != Enum.at(calls, 1)
|
|
735
|
+
assert ids.(S.getprop(track(h, "_telemetry"), "spans")) == calls
|
|
736
|
+
assert ids.(S.getprop(track(h, "_debug"), "entries")) == calls
|
|
737
|
+
end
|
|
738
|
+
end
|
|
739
|
+
|
|
717
740
|
# === clienttrack ===
|
|
718
741
|
|
|
719
742
|
test "clienttrack stable client id unique request ids and ua" do
|
|
@@ -46,8 +46,9 @@ func (f *DebugFeature) PreRequest(ctx *core.Context) {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
entry := map[string]any{
|
|
49
|
-
"op":
|
|
50
|
-
"
|
|
49
|
+
"op": entity + "." + opname,
|
|
50
|
+
"correlationId": ctx.Id,
|
|
51
|
+
"start": foptNow(f.options)(),
|
|
51
52
|
}
|
|
52
53
|
if ctx.Spec != nil {
|
|
53
54
|
entry["method"] = ctx.Spec.Method
|
|
@@ -49,10 +49,11 @@ func (f *TelemetryFeature) PrePoint(ctx *core.Context) {
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
span := map[string]any{
|
|
52
|
-
"traceId":
|
|
53
|
-
"spanId":
|
|
54
|
-
"
|
|
55
|
-
"
|
|
52
|
+
"traceId": f.id("trace"),
|
|
53
|
+
"spanId": f.id("span"),
|
|
54
|
+
"correlationId": ctx.Id,
|
|
55
|
+
"name": entity + "." + opname,
|
|
56
|
+
"start": foptNow(f.options)(),
|
|
56
57
|
}
|
|
57
58
|
ctx.Out[telemetrySpanKey] = span
|
|
58
59
|
f.ActiveSpans++
|
|
@@ -1047,6 +1047,46 @@ func TestFeatureAudit(t *testing.T) {
|
|
|
1047
1047
|
})
|
|
1048
1048
|
}
|
|
1049
1049
|
|
|
1050
|
+
// --- one call, one id -----------------------------------------------------------
|
|
1051
|
+
|
|
1052
|
+
func TestFeatureOneCallOneId(t *testing.T) {
|
|
1053
|
+
fhSkipWithout(t, "telemetry", "debug", "audit")
|
|
1054
|
+
|
|
1055
|
+
t.Run("telemetry-debug-and-audit-carry-one-calls-context-id", func(t *testing.T) {
|
|
1056
|
+
ft := feat.NewTelemetryFeature()
|
|
1057
|
+
fd := feat.NewDebugFeature()
|
|
1058
|
+
fa := feat.NewAuditFeature()
|
|
1059
|
+
h := fhMake(nil, fhF(ft, nil), fhF(fd, nil), fhF(fa, nil))
|
|
1060
|
+
h.op(fhOpSpec{op: "load"})
|
|
1061
|
+
h.op(fhOpSpec{op: "list"})
|
|
1062
|
+
ids := func(recs []map[string]any) []any {
|
|
1063
|
+
out := []any{}
|
|
1064
|
+
for _, rec := range recs {
|
|
1065
|
+
out = append(out, rec["correlationId"])
|
|
1066
|
+
}
|
|
1067
|
+
return out
|
|
1068
|
+
}
|
|
1069
|
+
calls := ids(fa.Records)
|
|
1070
|
+
if len(calls) != 2 {
|
|
1071
|
+
t.Fatalf("expected 2 audit records, got %d", len(calls))
|
|
1072
|
+
}
|
|
1073
|
+
for _, id := range calls {
|
|
1074
|
+
if s, ok := id.(string); !ok || s == "" {
|
|
1075
|
+
t.Fatalf("expected non-empty string ids, got %v", calls)
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
if calls[0] == calls[1] {
|
|
1079
|
+
t.Errorf("expected one id per call, got %v", calls)
|
|
1080
|
+
}
|
|
1081
|
+
if spans := ids(ft.Spans); !reflect.DeepEqual(spans, calls) {
|
|
1082
|
+
t.Errorf("expected span ids %v, got %v", calls, spans)
|
|
1083
|
+
}
|
|
1084
|
+
if entries := ids(fd.Entries); !reflect.DeepEqual(entries, calls) {
|
|
1085
|
+
t.Errorf("expected debug entry ids %v, got %v", calls, entries)
|
|
1086
|
+
}
|
|
1087
|
+
})
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1050
1090
|
// --- clienttrack ----------------------------------------------------------------
|
|
1051
1091
|
|
|
1052
1092
|
func TestFeatureClienttrack(t *testing.T) {
|
|
@@ -53,6 +53,7 @@ public class DebugFeature extends BaseFeature {
|
|
|
53
53
|
|
|
54
54
|
Map<String, Object> entry = new LinkedHashMap<>();
|
|
55
55
|
entry.put("op", entity + "." + opname);
|
|
56
|
+
entry.put("correlationId", ctx.id);
|
|
56
57
|
entry.put("start", FeatureOptions.foptNow(this.options).getAsLong());
|
|
57
58
|
if (ctx.spec != null) {
|
|
58
59
|
entry.put("method", ctx.spec.method);
|
|
@@ -61,6 +61,7 @@ public class TelemetryFeature extends BaseFeature {
|
|
|
61
61
|
Map<String, Object> span = new LinkedHashMap<>();
|
|
62
62
|
span.put("traceId", id("trace"));
|
|
63
63
|
span.put("spanId", id("span"));
|
|
64
|
+
span.put("correlationId", ctx.id);
|
|
64
65
|
span.put("name", entity + "." + opname);
|
|
65
66
|
span.put("start", FeatureOptions.foptNow(this.options).getAsLong());
|
|
66
67
|
ctx.out.put(TELEMETRY_SPAN_KEY, span);
|
|
@@ -830,6 +830,34 @@ public class FeatureTest {
|
|
|
830
830
|
assertEquals(0, f.records.size(), "expected no records");
|
|
831
831
|
}
|
|
832
832
|
|
|
833
|
+
// --- one call, one id -----------------------------------------------------------
|
|
834
|
+
|
|
835
|
+
@Test
|
|
836
|
+
public void correlation_telemetryDebugAndAuditCarryOneCallsContextId() {
|
|
837
|
+
assumeFeatures("telemetry", "debug", "audit");
|
|
838
|
+
TelemetryFeature telemetry = new TelemetryFeature();
|
|
839
|
+
DebugFeature debug = new DebugFeature();
|
|
840
|
+
AuditFeature audit = new AuditFeature();
|
|
841
|
+
FhHarness h = fhMake(null, fhF(telemetry, null), fhF(debug, null), fhF(audit, null));
|
|
842
|
+
h.op(fhOp("load"));
|
|
843
|
+
h.op(fhOp("list"));
|
|
844
|
+
Function<List<Map<String, Object>>, List<Object>> ids = (recs) -> {
|
|
845
|
+
List<Object> out = new ArrayList<>();
|
|
846
|
+
for (Map<String, Object> rec : recs) {
|
|
847
|
+
out.add(rec.get("correlationId"));
|
|
848
|
+
}
|
|
849
|
+
return out;
|
|
850
|
+
};
|
|
851
|
+
List<Object> calls = ids.apply(audit.records);
|
|
852
|
+
assertEquals(2, calls.size(), "expected one audit record per call");
|
|
853
|
+
for (Object id : calls) {
|
|
854
|
+
assertTrue(id instanceof String && !"".equals(id), "expected a context id, got " + calls);
|
|
855
|
+
}
|
|
856
|
+
assertNotEquals(calls.get(0), calls.get(1), "expected a different id per call");
|
|
857
|
+
assertEquals(calls, ids.apply(telemetry.spans), "expected the spans to carry the audit ids");
|
|
858
|
+
assertEquals(calls, ids.apply(debug.entries), "expected the debug entries to carry the audit ids");
|
|
859
|
+
}
|
|
860
|
+
|
|
833
861
|
// --- clienttrack ----------------------------------------------------------------
|
|
834
862
|
|
|
835
863
|
@Test
|
|
@@ -36,6 +36,7 @@ class DebugFeature extends BaseFeature {
|
|
|
36
36
|
const spec = ctx.spec || {}
|
|
37
37
|
const entry = {
|
|
38
38
|
op: ((ctx.op && ctx.op.entity) || '_') + '.' + ((ctx.op && ctx.op.name) || '_'),
|
|
39
|
+
correlationId: ctx.id,
|
|
39
40
|
method: spec.method,
|
|
40
41
|
url: spec.url || spec.path,
|
|
41
42
|
headers: this._redact(ctx, spec.headers),
|
|
@@ -39,6 +39,7 @@ class TelemetryFeature extends BaseFeature {
|
|
|
39
39
|
const span = {
|
|
40
40
|
traceId: this._id('trace'),
|
|
41
41
|
spanId: this._id('span'),
|
|
42
|
+
correlationId: ctx.id,
|
|
42
43
|
name: ((ctx.op && ctx.op.entity) || '_') + '.' + ((ctx.op && ctx.op.name) || '_'),
|
|
43
44
|
start: this._now(),
|
|
44
45
|
end: undefined,
|
|
@@ -455,6 +455,23 @@ describe('feature', () => {
|
|
|
455
455
|
})
|
|
456
456
|
|
|
457
457
|
|
|
458
|
+
// --- one call, one id -----------------------------------------------------
|
|
459
|
+
if (hasFeature('telemetry') && hasFeature('debug') && hasFeature('audit')) {
|
|
460
|
+
test('telemetry, debug and audit carry one call\'s context id', async () => {
|
|
461
|
+
const h = makeClient({ features: [{ name: 'telemetry' }, { name: 'debug' }, { name: 'audit' }] })
|
|
462
|
+
await h.op({ op: 'load' })
|
|
463
|
+
await h.op({ op: 'list' })
|
|
464
|
+
const ids = (recs) => recs.map((rec) => rec.correlationId)
|
|
465
|
+
const calls = ids(h.client._audit.records)
|
|
466
|
+
strictEqual(calls.length, 2)
|
|
467
|
+
ok(calls.every((id) => 'string' === typeof id && '' !== id), JSON.stringify(calls))
|
|
468
|
+
ok(calls[0] !== calls[1])
|
|
469
|
+
deepStrictEqual(ids(h.client._telemetry.spans), calls)
|
|
470
|
+
deepStrictEqual(ids(h.client._debug.entries), calls)
|
|
471
|
+
})
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
|
|
458
475
|
// --- clienttrack ----------------------------------------------------------
|
|
459
476
|
if (hasFeature('clienttrack')) describe('clienttrack', () => {
|
|
460
477
|
|
|
@@ -34,6 +34,7 @@ class DebugFeature : BaseFeature("debug", "0.0.1", true) {
|
|
|
34
34
|
|
|
35
35
|
val entry = linkedMapOf<String, Any?>()
|
|
36
36
|
entry["op"] = "$entity.$opname"
|
|
37
|
+
entry["correlationId"] = ctx.id
|
|
37
38
|
entry["start"] = FeatureOptions.foptNow(this.options).getAsLong()
|
|
38
39
|
val spec = ctx.spec
|
|
39
40
|
if (spec != null) {
|
|
@@ -40,6 +40,7 @@ class TelemetryFeature : BaseFeature("telemetry", "0.0.1", true) {
|
|
|
40
40
|
val span = linkedMapOf<String, Any?>()
|
|
41
41
|
span["traceId"] = id("trace")
|
|
42
42
|
span["spanId"] = id("span")
|
|
43
|
+
span["correlationId"] = ctx.id
|
|
43
44
|
span["name"] = "$entity.$opname"
|
|
44
45
|
span["start"] = FeatureOptions.foptNow(this.options).getAsLong()
|
|
45
46
|
ctx.out[TELEMETRY_SPAN_KEY] = span
|
|
@@ -768,6 +768,26 @@ class FeatureTest {
|
|
|
768
768
|
assertEquals(0, f.records.size, "expected no records")
|
|
769
769
|
}
|
|
770
770
|
|
|
771
|
+
// --- one call, one id -----------------------------------------------------------
|
|
772
|
+
|
|
773
|
+
@Test
|
|
774
|
+
fun correlation_telemetryDebugAndAuditCarryOneCallsContextId() {
|
|
775
|
+
assumeFeatures("telemetry", "debug", "audit")
|
|
776
|
+
val telemetry = TelemetryFeature()
|
|
777
|
+
val debug = DebugFeature()
|
|
778
|
+
val audit = AuditFeature()
|
|
779
|
+
val h = fhMake(null, fhF(telemetry, null), fhF(debug, null), fhF(audit, null))
|
|
780
|
+
h.op(fhOp("load"))
|
|
781
|
+
h.op(fhOp("list"))
|
|
782
|
+
val ids = { recs: List<Map<String, Any?>> -> recs.map { it["correlationId"] } }
|
|
783
|
+
val calls = ids(audit.records)
|
|
784
|
+
assertEquals(2, calls.size, "expected one audit record per call")
|
|
785
|
+
assertTrue(calls.all { it is String && "" != it }, "expected a context id per call, got $calls")
|
|
786
|
+
assertNotEquals(calls[0], calls[1], "expected a different id per call")
|
|
787
|
+
assertEquals(calls, ids(telemetry.spans), "expected the spans to carry the audit ids")
|
|
788
|
+
assertEquals(calls, ids(debug.entries), "expected the debug entries to carry the audit ids")
|
|
789
|
+
}
|
|
790
|
+
|
|
771
791
|
// --- clienttrack ----------------------------------------------------------------
|
|
772
792
|
|
|
773
793
|
@Test
|
|
@@ -68,6 +68,7 @@ function DebugFeature:PreRequest(ctx)
|
|
|
68
68
|
local entry = {
|
|
69
69
|
op = ((ctx.op ~= nil and ctx.op.entity) or "_") .. "." ..
|
|
70
70
|
((ctx.op ~= nil and ctx.op.name) or "_"),
|
|
71
|
+
correlationId = ctx.id,
|
|
71
72
|
method = method,
|
|
72
73
|
url = url,
|
|
73
74
|
headers = self:_redact(ctx, headers),
|
|
@@ -64,6 +64,7 @@ function TelemetryFeature:PrePoint(ctx)
|
|
|
64
64
|
local span = {
|
|
65
65
|
traceId = self:_id("trace"),
|
|
66
66
|
spanId = self:_id("span"),
|
|
67
|
+
correlationId = ctx.id,
|
|
67
68
|
name = ((ctx.op ~= nil and ctx.op.entity) or "_") .. "." ..
|
|
68
69
|
((ctx.op ~= nil and ctx.op.name) or "_"),
|
|
69
70
|
start = self:_now(),
|
|
@@ -1023,6 +1023,33 @@ describe("feature", function()
|
|
|
1023
1023
|
end) end
|
|
1024
1024
|
|
|
1025
1025
|
|
|
1026
|
+
-- one call, one id ------------------------------------------------------
|
|
1027
|
+
if has_feature("telemetry") and has_feature("debug") and has_feature("audit") then
|
|
1028
|
+
it("telemetry, debug and audit carry one call's context id", function()
|
|
1029
|
+
local h = make_client({ features = {
|
|
1030
|
+
{ name = "telemetry" }, { name = "debug" }, { name = "audit" },
|
|
1031
|
+
} })
|
|
1032
|
+
h.op({ op = "load" })
|
|
1033
|
+
h.op({ op = "list" })
|
|
1034
|
+
local function ids(recs)
|
|
1035
|
+
local out = {}
|
|
1036
|
+
for i, rec in ipairs(recs) do
|
|
1037
|
+
out[i] = rec.correlationId
|
|
1038
|
+
end
|
|
1039
|
+
return out
|
|
1040
|
+
end
|
|
1041
|
+
local calls = ids(h.client._audit.records)
|
|
1042
|
+
assert.are.equal(2, #calls)
|
|
1043
|
+
for _, id in ipairs(calls) do
|
|
1044
|
+
assert.is_true(type(id) == "string" and id ~= "")
|
|
1045
|
+
end
|
|
1046
|
+
assert.is_true(calls[1] ~= calls[2])
|
|
1047
|
+
assert.are.same(calls, ids(h.client._telemetry.spans))
|
|
1048
|
+
assert.are.same(calls, ids(h.client._debug.entries))
|
|
1049
|
+
end)
|
|
1050
|
+
end
|
|
1051
|
+
|
|
1052
|
+
|
|
1026
1053
|
-- clienttrack -------------------------------------------------------------
|
|
1027
1054
|
if has_feature("clienttrack") then describe("clienttrack", function()
|
|
1028
1055
|
|
|
@@ -665,6 +665,7 @@ let telemetry_feature () : feature =
|
|
|
665
665
|
let entity = if ctx.c_op.op_entity <> "" then ctx.c_op.op_entity else "_" in
|
|
666
666
|
let opname = if ctx.c_op.op_name <> "" then ctx.c_op.op_name else "_" in
|
|
667
667
|
let span = jo [("traceId", Str (gen_id "trace")); ("spanId", Str (gen_id "span"));
|
|
668
|
+
("correlationId", Str ctx.c_id);
|
|
668
669
|
("name", Str (entity ^ "." ^ opname)); ("start", Num (now_of !options));
|
|
669
670
|
("end", Noval); ("durationMs", Noval); ("ok", Noval)] in
|
|
670
671
|
scratch_set ctx "telemetry_span" span;
|
|
@@ -733,6 +734,7 @@ let debug_feature () : feature =
|
|
|
733
734
|
let opname = (if ctx.c_op.op_entity <> "" then ctx.c_op.op_entity else "_") ^ "." ^ (if ctx.c_op.op_name <> "" then ctx.c_op.op_name else "_") in
|
|
734
735
|
let entry = jo [
|
|
735
736
|
("op", Str opname);
|
|
737
|
+
("correlationId", Str ctx.c_id);
|
|
736
738
|
("method", (match ctx.c_spec with Some s -> Str s.sp_method | None -> Noval));
|
|
737
739
|
("url", (match ctx.c_spec with Some s -> Str (if s.sp_url <> "" then s.sp_url else s.sp_path) | None -> Noval));
|
|
738
740
|
("headers", redact ctx (match ctx.c_spec with Some s -> s.sp_headers | None -> Noval));
|
|
@@ -408,6 +408,22 @@ let () =
|
|
|
408
408
|
check_int "records" (size (getp (track h "audit") "records")) 0)
|
|
409
409
|
end;
|
|
410
410
|
|
|
411
|
+
(* ---------------- one call, one id ---------------- *)
|
|
412
|
+
if has_feature "telemetry" && has_feature "debug" && has_feature "audit" then begin
|
|
413
|
+
test "telemetry_debug_audit.one_context_id" (fun () ->
|
|
414
|
+
let h = make_client [("telemetry", empty_map ()); ("debug", empty_map ()); ("audit", empty_map ())] in
|
|
415
|
+
ignore (op h ~op:"load" ());
|
|
416
|
+
ignore (op h ~op:"list" ());
|
|
417
|
+
let ids recs = ja (List.init (size recs) (fun i -> getp (getelem recs (Num (float_of_int i))) "correlationId")) in
|
|
418
|
+
let calls = ids (getp (track h "audit") "records") in
|
|
419
|
+
check_int "records" (size calls) 2;
|
|
420
|
+
check ("string ids " ^ stringify calls)
|
|
421
|
+
(List.for_all (function Str s -> s <> "" | _ -> false) (match calls with List r -> !r | _ -> []));
|
|
422
|
+
check "one id per call" (not (veq (getelem calls (Num 0.)) (getelem calls (Num 1.))));
|
|
423
|
+
check "span ids" (veq (ids (getp (track h "telemetry") "spans")) calls);
|
|
424
|
+
check "debug entry ids" (veq (ids (getp (track h "debug") "entries")) calls))
|
|
425
|
+
end;
|
|
426
|
+
|
|
411
427
|
(* ---------------- clienttrack ---------------- *)
|
|
412
428
|
if has_feature "clienttrack" then begin
|
|
413
429
|
test "clienttrack.stable_id_ua" (fun () ->
|
|
@@ -61,6 +61,7 @@ sub PrePoint {
|
|
|
61
61
|
my $span = {
|
|
62
62
|
'traceId' => $self->_id('trace'),
|
|
63
63
|
'spanId' => $self->_id('span'),
|
|
64
|
+
'correlationId' => $ctx->{id},
|
|
64
65
|
'name' => ($ctx->{op} ? $ctx->{op}{entity} : '_') . '.'
|
|
65
66
|
. ($ctx->{op} ? $ctx->{op}{name} : '_'),
|
|
66
67
|
'start' => $self->_now,
|
|
@@ -883,6 +883,26 @@ if (has_feature('audit')) {
|
|
|
883
883
|
else { note('feature "audit" not present in this SDK') }
|
|
884
884
|
|
|
885
885
|
|
|
886
|
+
# === one call, one id ===
|
|
887
|
+
|
|
888
|
+
if (has_feature('telemetry') && has_feature('debug') && has_feature('audit')) {
|
|
889
|
+
my $h = harness([fspec('telemetry'), fspec('debug'), fspec('audit')]);
|
|
890
|
+
$h->op;
|
|
891
|
+
$h->op('opname' => 'list');
|
|
892
|
+
my $ids = sub { [map { $_->{correlationId} } @{ $_[0] }] };
|
|
893
|
+
my $calls = $ids->($h->track('_audit')->{records});
|
|
894
|
+
is(scalar @$calls, 2, 'telemetry, debug and audit: two calls audited');
|
|
895
|
+
is(scalar(grep { defined $_ && !ref $_ && '' ne $_ } @$calls), 2,
|
|
896
|
+
'telemetry, debug and audit: each call id is a non-empty string');
|
|
897
|
+
isnt($calls->[0], $calls->[1], 'telemetry, debug and audit: each call has its own id');
|
|
898
|
+
is_deeply($ids->($h->track('_telemetry')->{spans}), $calls,
|
|
899
|
+
'telemetry, debug and audit: spans carry the call ids');
|
|
900
|
+
is_deeply($ids->($h->track('_debug')->{entries}), $calls,
|
|
901
|
+
'telemetry, debug and audit: debug entries carry the call ids');
|
|
902
|
+
}
|
|
903
|
+
else { note('feature "telemetry", "debug" or "audit" not present in this SDK') }
|
|
904
|
+
|
|
905
|
+
|
|
886
906
|
# === clienttrack ===
|
|
887
907
|
|
|
888
908
|
if (has_feature('clienttrack')) {
|
|
@@ -55,6 +55,7 @@ class ProjectNameDebugFeature extends ProjectNameBaseFeature
|
|
|
55
55
|
$entry = [
|
|
56
56
|
'op' => ($ctx->op->entity !== '' ? $ctx->op->entity : '_')
|
|
57
57
|
. '.' . ($ctx->op->name !== '' ? $ctx->op->name : '_'),
|
|
58
|
+
'correlationId' => $ctx->id,
|
|
58
59
|
'method' => $spec !== null ? $spec->method : null,
|
|
59
60
|
'url' => $spec !== null ? ($spec->url !== '' ? $spec->url : $spec->path) : null,
|
|
60
61
|
'headers' => $this->_redact($ctx, $spec !== null ? $spec->headers : null),
|
|
@@ -58,6 +58,7 @@ class ProjectNameTelemetryFeature extends ProjectNameBaseFeature
|
|
|
58
58
|
$span = [
|
|
59
59
|
'traceId' => $this->_id('trace'),
|
|
60
60
|
'spanId' => $this->_id('span'),
|
|
61
|
+
'correlationId' => $ctx->id,
|
|
61
62
|
'name' => ($ctx->op->entity !== '' ? $ctx->op->entity : '_')
|
|
62
63
|
. '.' . ($ctx->op->name !== '' ? $ctx->op->name : '_'),
|
|
63
64
|
'start' => $this->_now(),
|
|
@@ -1039,6 +1039,28 @@ class FeatureTest extends TestCase
|
|
|
1039
1039
|
}
|
|
1040
1040
|
|
|
1041
1041
|
|
|
1042
|
+
// --- one call, one id -----------------------------------------------------
|
|
1043
|
+
|
|
1044
|
+
public function test_telemetry_debug_and_audit_carry_one_calls_context_id(): void
|
|
1045
|
+
{
|
|
1046
|
+
$this->needs('telemetry', 'debug', 'audit');
|
|
1047
|
+
$h = new FtHarness([
|
|
1048
|
+
['name' => 'telemetry'], ['name' => 'debug'], ['name' => 'audit'],
|
|
1049
|
+
]);
|
|
1050
|
+
$h->op(['op' => 'load']);
|
|
1051
|
+
$h->op(['op' => 'list']);
|
|
1052
|
+
$calls = array_column($h->client->_audit['records'], 'correlationId');
|
|
1053
|
+
$this->assertCount(2, $calls);
|
|
1054
|
+
foreach ($calls as $id) {
|
|
1055
|
+
$this->assertIsString($id);
|
|
1056
|
+
$this->assertNotSame('', $id);
|
|
1057
|
+
}
|
|
1058
|
+
$this->assertNotSame($calls[0], $calls[1]);
|
|
1059
|
+
$this->assertSame($calls, array_column($h->client->_telemetry['spans'], 'correlationId'));
|
|
1060
|
+
$this->assertSame($calls, array_column($h->client->_debug['entries'], 'correlationId'));
|
|
1061
|
+
}
|
|
1062
|
+
|
|
1063
|
+
|
|
1042
1064
|
// --- clienttrack ----------------------------------------------------------
|
|
1043
1065
|
|
|
1044
1066
|
public function test_clienttrack_stable_client_id_unique_request_ids_ua(): void
|
|
@@ -46,6 +46,7 @@ class ProjectNameDebugFeature(ProjectNameBaseFeature):
|
|
|
46
46
|
|
|
47
47
|
entry = {
|
|
48
48
|
"op": opname,
|
|
49
|
+
"correlationId": ctx.id,
|
|
49
50
|
"method": spec.method if spec is not None else None,
|
|
50
51
|
"url": (spec.url or spec.path) if spec is not None else None,
|
|
51
52
|
"headers": self._redact(ctx, spec.headers if spec is not None else None),
|
|
@@ -670,6 +670,29 @@ class TestAuditFeature:
|
|
|
670
670
|
assert len(h.client._audit["records"]) == 0
|
|
671
671
|
|
|
672
672
|
|
|
673
|
+
# --- one call, one id -------------------------------------------------------
|
|
674
|
+
@pytest.mark.skipif(not (has_feature("telemetry") and has_feature("debug")
|
|
675
|
+
and has_feature("audit")),
|
|
676
|
+
reason="telemetry, debug or audit not in this SDK")
|
|
677
|
+
class TestOneCallOneId:
|
|
678
|
+
|
|
679
|
+
def test_telemetry_debug_and_audit_carry_one_calls_context_id(self):
|
|
680
|
+
h = make_client([{"name": "telemetry"}, {"name": "debug"},
|
|
681
|
+
{"name": "audit"}])
|
|
682
|
+
h.op(op="load")
|
|
683
|
+
h.op(op="list")
|
|
684
|
+
|
|
685
|
+
def ids(recs):
|
|
686
|
+
return [rec.get("correlationId") for rec in recs]
|
|
687
|
+
|
|
688
|
+
calls = ids(h.client._audit["records"])
|
|
689
|
+
assert len(calls) == 2
|
|
690
|
+
assert all(isinstance(cid, str) and cid != "" for cid in calls), calls
|
|
691
|
+
assert calls[0] != calls[1]
|
|
692
|
+
assert ids(h.client._telemetry["spans"]) == calls
|
|
693
|
+
assert ids(h.client._debug["entries"]) == calls
|
|
694
|
+
|
|
695
|
+
|
|
673
696
|
# --- clienttrack ------------------------------------------------------------------
|
|
674
697
|
@pytest.mark.skipif(not has_feature("clienttrack"),
|
|
675
698
|
reason="clienttrack not in this SDK")
|
|
@@ -42,6 +42,7 @@ class ProjectNameTelemetryFeature < ProjectNameBaseFeature
|
|
|
42
42
|
span = {
|
|
43
43
|
"traceId" => _id("trace"),
|
|
44
44
|
"spanId" => _id("span"),
|
|
45
|
+
"correlationId" => ctx.id,
|
|
45
46
|
"name" => "#{ctx.op ? ctx.op.entity : '_'}.#{ctx.op ? ctx.op.name : '_'}",
|
|
46
47
|
"start" => _now,
|
|
47
48
|
"end" => nil,
|
|
@@ -853,6 +853,25 @@ class FeatureTest < Minitest::Test
|
|
|
853
853
|
end
|
|
854
854
|
|
|
855
855
|
|
|
856
|
+
# === one call, one id ===
|
|
857
|
+
|
|
858
|
+
def test_telemetry_debug_and_audit_carry_one_calls_context_id
|
|
859
|
+
skip_unless_feature("telemetry")
|
|
860
|
+
skip_unless_feature("debug")
|
|
861
|
+
skip_unless_feature("audit")
|
|
862
|
+
h = harness([fspec("telemetry"), fspec("debug"), fspec("audit")])
|
|
863
|
+
h.op
|
|
864
|
+
h.op(opname: "list")
|
|
865
|
+
ids = ->(recs) { recs.map { |r| r["correlationId"] } }
|
|
866
|
+
calls = ids.call(h.track(:@_audit)["records"])
|
|
867
|
+
assert_equal 2, calls.length
|
|
868
|
+
assert calls.all? { |id| id.is_a?(String) && !id.empty? }, calls.inspect
|
|
869
|
+
refute_equal calls[0], calls[1]
|
|
870
|
+
assert_equal calls, ids.call(h.track(:@_telemetry)["spans"])
|
|
871
|
+
assert_equal calls, ids.call(h.track(:@_debug)["entries"])
|
|
872
|
+
end
|
|
873
|
+
|
|
874
|
+
|
|
856
875
|
# === clienttrack ===
|
|
857
876
|
|
|
858
877
|
def test_clienttrack_stable_client_id_unique_request_ids_and_ua
|
|
@@ -108,6 +108,7 @@ impl Feature for TelemetryFeature {
|
|
|
108
108
|
let span = Value::empty_map();
|
|
109
109
|
setp(&span, "traceId", Value::str(self.id("trace")));
|
|
110
110
|
setp(&span, "spanId", Value::str(self.id("span")));
|
|
111
|
+
setp(&span, "correlationId", Value::str(ctx.id.clone()));
|
|
111
112
|
setp(&span, "name", Value::str(format!("{}.{}", entity, opname)));
|
|
112
113
|
setp(
|
|
113
114
|
&span,
|
|
@@ -1397,6 +1397,47 @@ fn feature_audit_inactive_records_nothing() {
|
|
|
1397
1397
|
assert_eq!(f.borrow().records.len(), 0, "expected no records");
|
|
1398
1398
|
}
|
|
1399
1399
|
|
|
1400
|
+
// --- one call, one id -----------------------------------------------------------
|
|
1401
|
+
|
|
1402
|
+
#[test]
|
|
1403
|
+
fn feature_telemetry_debug_audit_carry_one_calls_context_id() {
|
|
1404
|
+
if !fh_present(&["telemetry", "debug", "audit"]) {
|
|
1405
|
+
return;
|
|
1406
|
+
}
|
|
1407
|
+
let tf = Rc::new(RefCell::new(TelemetryFeature::new()));
|
|
1408
|
+
let df = Rc::new(RefCell::new(DebugFeature::new()));
|
|
1409
|
+
let af = Rc::new(RefCell::new(AuditFeature::new()));
|
|
1410
|
+
let h = fh_make(
|
|
1411
|
+
None,
|
|
1412
|
+
vec![
|
|
1413
|
+
(fr(&tf), Value::Noval),
|
|
1414
|
+
(fr(&df), Value::Noval),
|
|
1415
|
+
(fr(&af), Value::Noval),
|
|
1416
|
+
],
|
|
1417
|
+
);
|
|
1418
|
+
h.op(opspec("load"));
|
|
1419
|
+
h.op(opspec("list"));
|
|
1420
|
+
let ids = |recs: &[Value]| -> Vec<Value> {
|
|
1421
|
+
recs.iter().map(|rec| getp(rec, "correlationId")).collect()
|
|
1422
|
+
};
|
|
1423
|
+
let calls = ids(&af.borrow().records);
|
|
1424
|
+
assert_eq!(calls.len(), 2, "expected 2 audit records");
|
|
1425
|
+
assert!(
|
|
1426
|
+
calls
|
|
1427
|
+
.iter()
|
|
1428
|
+
.all(|id| matches!(id, Value::Str(s) if !s.is_empty())),
|
|
1429
|
+
"expected non-empty string ids, got {:?}",
|
|
1430
|
+
calls
|
|
1431
|
+
);
|
|
1432
|
+
assert_ne!(calls[0], calls[1], "expected one id per call");
|
|
1433
|
+
assert_eq!(ids(&tf.borrow().spans), calls, "expected the spans' ids");
|
|
1434
|
+
assert_eq!(
|
|
1435
|
+
ids(&df.borrow().entries),
|
|
1436
|
+
calls,
|
|
1437
|
+
"expected the debug entries' ids"
|
|
1438
|
+
);
|
|
1439
|
+
}
|
|
1440
|
+
|
|
1400
1441
|
// --- clienttrack ----------------------------------------------------------------
|
|
1401
1442
|
|
|
1402
1443
|
#[test]
|
|
@@ -39,6 +39,7 @@ class DebugFeature extends BaseFeature("debug", "0.0.1", true) {
|
|
|
39
39
|
|
|
40
40
|
val entry = new LinkedHashMap[String, Object]()
|
|
41
41
|
entry.put("op", entity + "." + opname)
|
|
42
|
+
entry.put("correlationId", ctx.id)
|
|
42
43
|
entry.put("start", java.lang.Long.valueOf(FeatureOptions.foptNow(this.options).getAsLong()))
|
|
43
44
|
if (ctx.spec != null) {
|
|
44
45
|
entry.put("method", ctx.spec.method)
|
|
@@ -45,6 +45,7 @@ class TelemetryFeature extends BaseFeature("telemetry", "0.0.1", true) {
|
|
|
45
45
|
val span = new LinkedHashMap[String, Object]()
|
|
46
46
|
span.put("traceId", id("trace"))
|
|
47
47
|
span.put("spanId", id("span"))
|
|
48
|
+
span.put("correlationId", ctx.id)
|
|
48
49
|
span.put("name", entity + "." + opname)
|
|
49
50
|
span.put("start", java.lang.Long.valueOf(FeatureOptions.foptNow(this.options).getAsLong()))
|
|
50
51
|
ctx.out.put(TELEMETRY_SPAN_KEY, span)
|
|
@@ -541,6 +541,28 @@ object SdkTestMain {
|
|
|
541
541
|
h.op(fhOp("load")); eqI("audit.inactive", 0, f.records.size()) }
|
|
542
542
|
}
|
|
543
543
|
|
|
544
|
+
private def testCorrelation(): Unit = {
|
|
545
|
+
{ val telemetry = new TelemetryFeature(); val debug = new DebugFeature(); val audit = new AuditFeature()
|
|
546
|
+
val h = fhMake(null, fhF(telemetry, null), fhF(debug, null), fhF(audit, null))
|
|
547
|
+
h.op(fhOp("load")); h.op(fhOp("list"))
|
|
548
|
+
def ids(recs: JList[JMap[String, Object]]): JList[Object] = {
|
|
549
|
+
val out = new ArrayList[Object]()
|
|
550
|
+
val it = recs.iterator()
|
|
551
|
+
while (it.hasNext) out.add(it.next().get("correlationId"))
|
|
552
|
+
out
|
|
553
|
+
}
|
|
554
|
+
val calls = ids(audit.records)
|
|
555
|
+
eqI("correlation.calls", 2, calls.size())
|
|
556
|
+
val it = calls.iterator()
|
|
557
|
+
while (it.hasNext) {
|
|
558
|
+
val id = it.next()
|
|
559
|
+
check("correlation.id", id.isInstanceOf[String] && "" != id, "expected a context id, got " + calls)
|
|
560
|
+
}
|
|
561
|
+
check("correlation.distinct", 2 == calls.size() && !jeq(calls.get(0), calls.get(1)), "expected a different id per call, got " + calls)
|
|
562
|
+
eq("correlation.spans", calls, ids(telemetry.spans))
|
|
563
|
+
eq("correlation.debug", calls, ids(debug.entries)) }
|
|
564
|
+
}
|
|
565
|
+
|
|
544
566
|
private def testClienttrack(): Unit = {
|
|
545
567
|
{ val rec = new FhRecorder(); val f = new ClienttrackFeature()
|
|
546
568
|
val h = fhMake((c, u, fd) => rec.fetch(c, u, fd), fhF(f, om("clientName" -> "Acme", "clientVersion" -> "2.0.0")))
|
|
@@ -1048,7 +1070,8 @@ object SdkTestMain {
|
|
|
1048
1070
|
"netsim" -> testNetsim, "retry" -> testRetry, "timeout" -> testTimeout,
|
|
1049
1071
|
"ratelimit" -> testRatelimit, "cache" -> testCache, "idempotency" -> testIdempotency,
|
|
1050
1072
|
"rbac" -> testRbac, "metrics" -> testMetrics, "telemetry" -> testTelemetry,
|
|
1051
|
-
"debug" -> testDebug, "audit" -> testAudit, "
|
|
1073
|
+
"debug" -> testDebug, "audit" -> testAudit, "correlation" -> testCorrelation,
|
|
1074
|
+
"clienttrack" -> testClienttrack,
|
|
1052
1075
|
"paging" -> testPaging, "streaming" -> testStreaming, "proxy" -> testProxy,
|
|
1053
1076
|
"composition" -> testComposition, "featureAdd" -> testFeatureAdd,
|
|
1054
1077
|
"featureOrder" -> testFeatureOrder, "entityCrud" -> testEntityCrud,
|
|
@@ -40,6 +40,7 @@ public final class DebugFeature: BaseFeature {
|
|
|
40
40
|
|
|
41
41
|
let entry = VMap()
|
|
42
42
|
entry.entries["op"] = .string(entity + "." + opname)
|
|
43
|
+
entry.entries["correlationId"] = .string(ctx.id)
|
|
43
44
|
entry.entries["start"] = .int(foptNow(options)())
|
|
44
45
|
if let spec = ctx.spec {
|
|
45
46
|
entry.entries["method"] = .string(spec.method)
|
|
@@ -45,6 +45,7 @@ public final class TelemetryFeature: BaseFeature {
|
|
|
45
45
|
let span = VMap()
|
|
46
46
|
span.entries["traceId"] = .string(id("trace"))
|
|
47
47
|
span.entries["spanId"] = .string(id("span"))
|
|
48
|
+
span.entries["correlationId"] = .string(ctx.id)
|
|
48
49
|
span.entries["name"] = .string(entity + "." + opname)
|
|
49
50
|
span.entries["start"] = .int(foptNow(options)())
|
|
50
51
|
ctx.out[TelemetryFeature.spanKey] = span
|
|
@@ -887,6 +887,30 @@ final class FeatureAuditTest: XCTestCase {
|
|
|
887
887
|
}
|
|
888
888
|
}
|
|
889
889
|
|
|
890
|
+
// --- one call, one id --------------------------------------------------------
|
|
891
|
+
|
|
892
|
+
final class FeatureCorrelationTest: XCTestCase {
|
|
893
|
+
func testTelemetryDebugAndAuditCarryOneCallsContextId() {
|
|
894
|
+
if Fh.skipWithout("telemetry", "debug", "audit") { return }
|
|
895
|
+
let telemetry = TelemetryFeature()
|
|
896
|
+
let debug = DebugFeature()
|
|
897
|
+
let audit = AuditFeature()
|
|
898
|
+
let h = Fh.make(nil, (telemetry, nil), (debug, nil), (audit, nil))
|
|
899
|
+
_ = h.op(FhOpSpec(op: "load"))
|
|
900
|
+
_ = h.op(FhOpSpec(op: "list"))
|
|
901
|
+
func ids(_ recs: [VMap]) -> [Value?] { recs.map { $0.entries["correlationId"] } }
|
|
902
|
+
let calls = ids(audit.records)
|
|
903
|
+
guard calls.count == 2 else {
|
|
904
|
+
XCTFail("expected one audit record per call, got \(calls.count)")
|
|
905
|
+
return
|
|
906
|
+
}
|
|
907
|
+
XCTAssertTrue(calls.allSatisfy { ($0?.asString ?? "") != "" }, "context ids: \(calls)")
|
|
908
|
+
XCTAssertNotEqual(calls[0], calls[1])
|
|
909
|
+
XCTAssertEqual(ids(telemetry.spans), calls)
|
|
910
|
+
XCTAssertEqual(ids(debug.entries), calls)
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
|
|
890
914
|
// --- clienttrack -------------------------------------------------------------
|
|
891
915
|
|
|
892
916
|
final class FeatureClienttrackTest: XCTestCase {
|
|
@@ -32,6 +32,7 @@ class DebugFeature extends BaseFeature {
|
|
|
32
32
|
const spec = ctx.spec || {}
|
|
33
33
|
const entry = {
|
|
34
34
|
op: ((ctx.op && ctx.op.entity) || '_') + '.' + ((ctx.op && ctx.op.name) || '_'),
|
|
35
|
+
correlationId: ctx.id,
|
|
35
36
|
method: spec.method,
|
|
36
37
|
url: spec.url || spec.path,
|
|
37
38
|
headers: this._redact(ctx, spec.headers),
|
|
@@ -34,6 +34,7 @@ class TelemetryFeature extends BaseFeature {
|
|
|
34
34
|
const span = {
|
|
35
35
|
traceId: this._id('trace'),
|
|
36
36
|
spanId: this._id('span'),
|
|
37
|
+
correlationId: ctx.id,
|
|
37
38
|
name: ((ctx.op && ctx.op.entity) || '_') + '.' + ((ctx.op && ctx.op.name) || '_'),
|
|
38
39
|
start: this._now(),
|
|
39
40
|
end: undefined as any,
|
|
@@ -455,6 +455,23 @@ describe('feature', () => {
|
|
|
455
455
|
})
|
|
456
456
|
|
|
457
457
|
|
|
458
|
+
// --- one call, one id -----------------------------------------------------
|
|
459
|
+
if (hasFeature('telemetry') && hasFeature('debug') && hasFeature('audit')) {
|
|
460
|
+
test('telemetry, debug and audit carry one call\'s context id', async () => {
|
|
461
|
+
const h = makeClient({ features: [{ name: 'telemetry' }, { name: 'debug' }, { name: 'audit' }] })
|
|
462
|
+
await h.op({ op: 'load' })
|
|
463
|
+
await h.op({ op: 'list' })
|
|
464
|
+
const ids = (recs: any[]) => recs.map((rec: any) => rec.correlationId)
|
|
465
|
+
const calls = ids(h.client._audit.records)
|
|
466
|
+
strictEqual(calls.length, 2)
|
|
467
|
+
ok(calls.every((id: any) => 'string' === typeof id && '' !== id), JSON.stringify(calls))
|
|
468
|
+
ok(calls[0] !== calls[1])
|
|
469
|
+
deepStrictEqual(ids(h.client._telemetry.spans), calls)
|
|
470
|
+
deepStrictEqual(ids(h.client._debug.entries), calls)
|
|
471
|
+
})
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
|
|
458
475
|
// --- clienttrack ----------------------------------------------------------
|
|
459
476
|
if (hasFeature('clienttrack')) describe('clienttrack', () => {
|
|
460
477
|
|
|
@@ -107,6 +107,7 @@ pub const DebugFeature = struct {
|
|
|
107
107
|
|
|
108
108
|
const entry = h.omap();
|
|
109
109
|
h.setp(entry, "op", h.vstr(std.fmt.allocPrint(h.A(), "{s}.{s}", .{ entity, opname }) catch ""));
|
|
110
|
+
h.setp(entry, "correlationId", h.vstr(ctx.id));
|
|
110
111
|
h.setp(entry, "start", h.vnum(sup.fopt_now(self.options)));
|
|
111
112
|
if (ctx.spec) |sp| {
|
|
112
113
|
h.setp(entry, "method", h.vstr(sp.method));
|
|
@@ -92,6 +92,7 @@ pub const TelemetryFeature = struct {
|
|
|
92
92
|
const span = h.omap();
|
|
93
93
|
h.setp(span, "traceId", h.vstr(self.id("trace")));
|
|
94
94
|
h.setp(span, "spanId", h.vstr(self.id("span")));
|
|
95
|
+
h.setp(span, "correlationId", h.vstr(ctx.id));
|
|
95
96
|
h.setp(span, "name", h.vstr(std.fmt.allocPrint(h.A(), "{s}.{s}", .{ entity, opname }) catch ""));
|
|
96
97
|
h.setp(span, "start", h.vnum(sup.fopt_now(self.options)));
|
|
97
98
|
ctx.out_set(TELEMETRY_SPAN_KEY, OutVal{ .val = span });
|
|
@@ -828,6 +828,41 @@ test "feature audit: inactive records nothing" {
|
|
|
828
828
|
try testing.expect(af.records.items.len == 0);
|
|
829
829
|
}
|
|
830
830
|
|
|
831
|
+
// =====================================================================
|
|
832
|
+
// one call, one id
|
|
833
|
+
// =====================================================================
|
|
834
|
+
|
|
835
|
+
test "feature telemetry, debug and audit: carry one call's context id" {
|
|
836
|
+
if (!fh.fh_present(&.{ "telemetry", "debug", "audit" })) return;
|
|
837
|
+
const tfeat = sdk.TelemetryFeature.make();
|
|
838
|
+
const tf: *sdk.TelemetryFeature = @ptrCast(@alignCast(tfeat.ptr));
|
|
839
|
+
const dfeat = sdk.DebugFeature.make();
|
|
840
|
+
const df: *sdk.DebugFeature = @ptrCast(@alignCast(dfeat.ptr));
|
|
841
|
+
const afeat = sdk.AuditFeature.make();
|
|
842
|
+
const af: *sdk.AuditFeature = @ptrCast(@alignCast(afeat.ptr));
|
|
843
|
+
const hh = fh.fh_make(null, &.{
|
|
844
|
+
.{ .feat = tfeat, .options = vnull() },
|
|
845
|
+
.{ .feat = dfeat, .options = vnull() },
|
|
846
|
+
.{ .feat = afeat, .options = vnull() },
|
|
847
|
+
});
|
|
848
|
+
_ = hh.op(.{ .op = "load" });
|
|
849
|
+
_ = hh.op(.{ .op = "list" });
|
|
850
|
+
const calls = af.records.items;
|
|
851
|
+
try testing.expect(calls.len == 2);
|
|
852
|
+
for (calls) |rec| {
|
|
853
|
+
const id = h.get_str(rec, "correlationId") orelse "";
|
|
854
|
+
try testing.expect(id.len != 0);
|
|
855
|
+
}
|
|
856
|
+
try testing.expect(!h.veq(h.getp(calls[0], "correlationId"), h.getp(calls[1], "correlationId")));
|
|
857
|
+
try testing.expect(tf.spans.items.len == calls.len);
|
|
858
|
+
try testing.expect(df.entries.items.len == calls.len);
|
|
859
|
+
for (calls, tf.spans.items, df.entries.items) |rec, span, entry| {
|
|
860
|
+
const id = h.getp(rec, "correlationId");
|
|
861
|
+
try testing.expect(h.veq(h.getp(span, "correlationId"), id));
|
|
862
|
+
try testing.expect(h.veq(h.getp(entry, "correlationId"), id));
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
|
|
831
866
|
// =====================================================================
|
|
832
867
|
// clienttrack
|
|
833
868
|
// =====================================================================
|