@downtrace/protocol 0.6.0 → 0.7.1

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.
Files changed (37) hide show
  1. package/README.md +18 -2
  2. package/dist/index.d.ts +867 -14
  3. package/dist/index.js +570 -17
  4. package/package.json +1 -1
  5. package/schema/v0/aggregates.schema.json +233 -6
  6. package/schema/v0/capture-evidence.schema.json +200 -0
  7. package/schema/v0/fixtures/evidence/invalid/half-a-coverage.json +8 -0
  8. package/schema/v0/fixtures/evidence/invalid/no-coverage.json +7 -0
  9. package/schema/v0/fixtures/evidence/invalid/no-instance.json +7 -0
  10. package/schema/v0/fixtures/evidence/invalid/operation-with-text.json +17 -0
  11. package/schema/v0/fixtures/evidence/invalid/operation-without-hash.json +17 -0
  12. package/schema/v0/fixtures/evidence/invalid/reference-without-selection.json +49 -0
  13. package/schema/v0/fixtures/evidence/invalid/unknown-protocol.json +8 -0
  14. package/schema/v0/fixtures/evidence/valid/complete.json +28 -0
  15. package/schema/v0/fixtures/evidence/valid/no-requests.json +8 -0
  16. package/schema/v0/fixtures/evidence/valid/partial.json +27 -0
  17. package/schema/v0/fixtures/evidence/valid/with-reference.json +75 -0
  18. package/schema/v0/fixtures/invalid/capture-without-a-start.json +50 -0
  19. package/schema/v0/fixtures/invalid/exception-that-did-not-happen.json +52 -0
  20. package/schema/v0/fixtures/invalid/operation-with-class-and-text.json +87 -0
  21. package/schema/v0/fixtures/invalid/runtime-with-nothing-in-it.json +51 -0
  22. package/schema/v0/fixtures/invalid/withholding-with-nothing-in-it.json +46 -0
  23. package/schema/v0/fixtures/response/invalid/capture-without-deadline.json +5 -0
  24. package/schema/v0/fixtures/response/invalid/capture-without-id.json +5 -0
  25. package/schema/v0/fixtures/response/invalid/missing-accepted.json +1 -0
  26. package/schema/v0/fixtures/response/invalid/unknown-field.json +1 -0
  27. package/schema/v0/fixtures/response/invalid/window-of-no-time.json +5 -0
  28. package/schema/v0/fixtures/response/valid/nothing-pending.json +1 -0
  29. package/schema/v0/fixtures/response/valid/one-capture.json +16 -0
  30. package/schema/v0/fixtures/response/valid/re-sent-batch.json +1 -0
  31. package/schema/v0/fixtures/valid/capture-started.json +51 -0
  32. package/schema/v0/fixtures/valid/operation-omitted-with-class.json +86 -0
  33. package/schema/v0/fixtures/valid/process-exceptions.json +58 -0
  34. package/schema/v0/fixtures/valid/profile-without-intervals.json +60 -0
  35. package/schema/v0/fixtures/{invalid/runtime-missing-rss.json → valid/runtime-without-an-event-loop.json} +2 -7
  36. package/schema/v0/fixtures/valid/withholding.json +49 -0
  37. package/schema/v0/ingest-response.schema.json +71 -0
package/dist/index.js CHANGED
@@ -23,7 +23,8 @@ var aggregates_schema_default = {
23
23
  "0.3.0",
24
24
  "0.4.0",
25
25
  "0.5.0",
26
- "0.6.0"
26
+ "0.6.0",
27
+ "0.7.0"
27
28
  ],
28
29
  "description": "Protocol version this batch conforms to. Every published minor of v0 stays acceptable."
29
30
  },
@@ -32,11 +33,30 @@ var aggregates_schema_default = {
32
33
  "deploy": { "$ref": "#/$defs/DeployInfo" },
33
34
  "intervals": {
34
35
  "type": "array",
35
- "minItems": 1,
36
+ "minItems": 0,
36
37
  "maxItems": 6,
37
- "items": { "$ref": "#/$defs/Interval" }
38
+ "items": { "$ref": "#/$defs/Interval" },
39
+ "description": "The intervals this batch carries. May be empty when the batch carries a profile: the profile has a cadence of its own and hangs off the batch, not off an interval (ADR 0017), so tying its delivery to one meant it was lost whenever a window closed with no traffic — at shutdown, always (gh-375). A batch with neither is refused by the cloud with a reason, which the schema cannot say without making the generated types unusable."
38
40
  },
39
- "profile": { "$ref": "#/$defs/Profile" }
41
+ "profile": { "$ref": "#/$defs/Profile" },
42
+ "captures": {
43
+ "type": "array",
44
+ "maxItems": 16,
45
+ "items": { "$ref": "#/$defs/CaptureProgress" },
46
+ "description": "Progress on the captures this sender was asked for. Absent from every sender that predates it, and from every batch with nothing to report. Bounded like the answer that carries the orders."
47
+ },
48
+ "exceptions": {
49
+ "type": "array",
50
+ "maxItems": 32,
51
+ "items": { "$ref": "#/$defs/ProcessException" },
52
+ "description": "Distinct exception signatures this process saw outside any request. Absent from every sender that predates it and from every batch with none. Bounded: a process crashing in a loop must not become an unbounded batch."
53
+ },
54
+ "triggers": {
55
+ "type": "array",
56
+ "maxItems": 4,
57
+ "items": { "$ref": "#/$defs/LocalTrigger" },
58
+ "description": "Local signals that ask for a capture. `product.md:124` gives the instrumentation «disparar por señales locales»: it sees a process in trouble before any aggregate crosses the cloud, and asking in the batch costs no channel of its own — the answer already carries the orders (ADR 0071). Absent from every sender that predates it and from every batch with nothing to ask. The cloud decides: the same budget, cooldown and concurrency as any other capture (`product.md:122`), and a refusal is silence, because there is nothing the instrumentation would do differently."
59
+ }
40
60
  },
41
61
  $defs: {
42
62
  "AgentInfo": {
@@ -65,6 +85,18 @@ var aggregates_schema_default = {
65
85
  "type": "string",
66
86
  "minLength": 1,
67
87
  "maxLength": 64
88
+ },
89
+ "observers": {
90
+ "$ref": "#/$defs/Observers",
91
+ "description": "Absent from an instrumentation older than protocol 0.7.0. Absent is not 'nothing is observed': it is 'this one did not say', and the two must not be shown alike."
92
+ },
93
+ "withholding": {
94
+ "$ref": "#/$defs/Withholding",
95
+ "description": "Absent means **this sender did not say**, not that it withholds nothing — the same reading as `observers`, and for the same reason."
96
+ },
97
+ "resources": {
98
+ "$ref": "#/$defs/AgentResources",
99
+ "description": "What the instrumentation costs and what it has lost, measured by itself. Absent means **this sender did not say**, the same reading as `observers` and `withholding`. `product.md:239` asks for it by name: «recursos internos medidos»."
68
100
  }
69
101
  }
70
102
  },
@@ -327,17 +359,9 @@ var aggregates_schema_default = {
327
359
  },
328
360
  "RuntimeHealth": {
329
361
  "title": "RuntimeHealth",
330
- "description": "Health of the agent's own process during the interval. Optional: an agent that does not measure it omits it. Per interval, not per route, because it belongs to the process.",
362
+ "description": "What the runtime itself was doing. Every field is optional and at least one has to be there: `product.md:251` says the protocol is independent of the language, and a Go runtime has garbage collection, a heap and a resident set but no event loop. Requiring the six of them meant it could either invent an event loop or send none of the three it does have. An empty object is not a reading, hence the minimum of one (gh-285).",
331
363
  "type": "object",
332
364
  "additionalProperties": false,
333
- "required": [
334
- "eventLoopDelayMs",
335
- "gcPauseMs",
336
- "gcCount",
337
- "heapUsedMb",
338
- "rssMb",
339
- "inFlightMax"
340
- ],
341
365
  "properties": {
342
366
  "eventLoopDelayMs": {
343
367
  "type": "object",
@@ -391,7 +415,8 @@ var aggregates_schema_default = {
391
415
  "minimum": 0,
392
416
  "description": "Peak concurrent in-flight requests during the interval."
393
417
  }
394
- }
418
+ },
419
+ "minProperties": 1
395
420
  },
396
421
  "Dependency": {
397
422
  "title": "Dependency",
@@ -565,12 +590,522 @@ var aggregates_schema_default = {
565
590
  "type": "integer",
566
591
  "minimum": 0,
567
592
  "description": "Only on the `(other)` bucket: how many distinct operations it merges, so a cap does not become a lie by omission."
593
+ },
594
+ "class": {
595
+ "enum": [
596
+ "select",
597
+ "insert",
598
+ "update",
599
+ "delete",
600
+ "other"
601
+ ],
602
+ "description": "What kind of statement this is, when the sender could not normalise it safely. Its presence is the reason the text is absent: `product.md:104` says a query the normaliser does not understand travels «solo como hash y clase», and this is the class. Never sent together with `text` — they are two answers to the same question. Our word and not the service's: it is decided from the first keyword, which is all that can be told without understanding the rest (gh-344)."
603
+ }
604
+ },
605
+ "not": {
606
+ "required": ["class", "text"],
607
+ "properties": {
608
+ "class": {},
609
+ "text": {}
610
+ }
611
+ }
612
+ },
613
+ "ObserverState": {
614
+ "title": "ObserverState",
615
+ "enum": [
616
+ "on",
617
+ "off",
618
+ "unavailable"
619
+ ],
620
+ "description": "Whether an observer is attached (`on`), was not asked for (`off`), or was asked for and could not attach (`unavailable`) — a driver that is not resolvable from the application's root, for instance. The third one is the point: without it, a service that is not being watched looks exactly like a service that has nothing to watch (COB-01, invariant 14)."
621
+ },
622
+ "Observers": {
623
+ "title": "Observers",
624
+ "type": "object",
625
+ "additionalProperties": false,
626
+ "description": "What the instrumentation is watching, by switch. The keys are the switches of `DOWNTRACE_INSTRUMENT`, so this says `pg` where a dependency says `postgres`: one is the switch and the other is the thing observed.",
627
+ "properties": {
628
+ "pg": { "$ref": "#/$defs/ObserverState" },
629
+ "http": { "$ref": "#/$defs/ObserverState" },
630
+ "redis": { "$ref": "#/$defs/ObserverState" },
631
+ "runtime": { "$ref": "#/$defs/ObserverState" }
632
+ }
633
+ },
634
+ "Withholding": {
635
+ "title": "Withholding",
636
+ "type": "object",
637
+ "additionalProperties": false,
638
+ "minProperties": 1,
639
+ "description": "What this sender is deliberately not sending, so that less arriving can be read as a choice rather than as a fault (invariant 14, COB-01). Counts and never names: the name of an excluded endpoint is exactly what the user asked not to send. The cloud cannot verify any of this and does not try — it is what the sender says, and it is shown as such.",
640
+ "properties": {
641
+ "freeText": {
642
+ "type": "boolean",
643
+ "description": "True when the sender is in minimal mode: no query text, no route templates, no dependency hosts, no error messages. Only ever true — a sender that is not in minimal mode leaves it out.",
644
+ "const": true
645
+ },
646
+ "endpoints": {
647
+ "type": "integer",
648
+ "minimum": 1,
649
+ "description": "How many endpoints are excluded. Absent means none are."
650
+ },
651
+ "dependencies": {
652
+ "type": "integer",
653
+ "minimum": 1,
654
+ "description": "How many dependencies are excluded. Absent means none are."
655
+ }
656
+ }
657
+ },
658
+ "CaptureProgress": {
659
+ "title": "CaptureProgress",
660
+ "type": "object",
661
+ "additionalProperties": false,
662
+ "required": ["id", "startedAt"],
663
+ "description": "What the instrumentation has to say about a capture the cloud asked it for. The order travels in the ingest response (ADR 0071) and the answer travels here, on the same cadence and at the same cost: a path of its own would be one more call per capture, and one more thing to authenticate, for a fact that fits in the batch that is already going (gh-378).",
664
+ "properties": {
665
+ "id": {
666
+ "type": "string",
667
+ "minLength": 1,
668
+ "maxLength": 64,
669
+ "description": "The capture's id, as the ingest response gave it. Carries nothing the service wrote."
670
+ },
671
+ "startedAt": {
672
+ "type": "integer",
673
+ "description": "Unix milliseconds when observation **really** started, which CAP-01 keeps apart from when the capture was accepted."
674
+ }
675
+ }
676
+ },
677
+ "ProcessException": {
678
+ "title": "ProcessException",
679
+ "type": "object",
680
+ "additionalProperties": false,
681
+ "required": [
682
+ "kind",
683
+ "hash",
684
+ "count"
685
+ ],
686
+ "description": "Something thrown outside any instrumented operation: an exception nobody caught, or a promise rejected with no `catch`. `product.md:77` asks for «errores **y excepciones**», and these are the two the word «excepciones» names. They live on the batch and not in the profile because they have **no route** — they happen outside a request's life, or after it ended — and filing them under a route that is not theirs would be worse than not having them (gh-341, ADR 0102).",
687
+ "properties": {
688
+ "kind": {
689
+ "enum": ["uncaught", "unhandled-rejection"],
690
+ "description": "Which of the two. Two different failures with two different fixes: counting them together hides which one is happening."
691
+ },
692
+ "hash": {
693
+ "type": "string",
694
+ "minLength": 1,
695
+ "maxLength": 64,
696
+ "description": "Stable identity of the signature, the same shape a query's or an operation error's has (ADR 0017)."
697
+ },
698
+ "text": {
699
+ "type": "string",
700
+ "maxLength": 512,
701
+ "description": "Type, sanitised message and stack signature. Optional and for the same reason as everywhere else: when nothing recognisable survives the sanitising, only the type and the signature travel (ADR 0084). Its absence is not the absence of an exception."
702
+ },
703
+ "count": {
704
+ "type": "integer",
705
+ "minimum": 1,
706
+ "description": "How many times this signature happened. An instant per occurrence would be a row per crash of a process that crashes in a loop; what a reader asks is how many."
707
+ }
708
+ }
709
+ },
710
+ "LocalTrigger": {
711
+ "type": "object",
712
+ "title": "LocalTrigger",
713
+ "additionalProperties": false,
714
+ "required": ["signal", "observedAt"],
715
+ "description": "One local signal, sustained past its threshold. It asks for detail; it does not claim a cause (invariant 7).",
716
+ "properties": {
717
+ "signal": {
718
+ "type": "string",
719
+ "enum": ["event-loop-delay"],
720
+ "description": "Which signal fired. An enum and not free text: the cloud files findings by footprint, and a trigger type nobody can compare is a footprint that never matches. `product.md:114` names the absolute-threshold signals; this is the first of them."
721
+ },
722
+ "observedAt": {
723
+ "type": "integer",
724
+ "minimum": 0,
725
+ "description": "Unix milliseconds when the signal was last seen over its threshold. Milliseconds and not a date string because that is how this contract writes an instant —an interval's `start`, a capture's `startedAt`— and the evidence, which writes dates, is a different payload with different readers."
726
+ },
727
+ "valueMs": {
728
+ "type": "number",
729
+ "minimum": 0,
730
+ "description": "What was measured: the p99 of the event loop delay over the interval that fired."
731
+ },
732
+ "thresholdMs": {
733
+ "type": "number",
734
+ "minimum": 0,
735
+ "description": "The threshold it passed, sent with the value because a number without its threshold cannot be read by anyone who does not have this version of the instrumentation in front of them."
736
+ },
737
+ "intervals": {
738
+ "type": "integer",
739
+ "minimum": 1,
740
+ "description": "How many consecutive intervals it stayed over. More than one is what makes it sustained rather than a spike (`product.md:114`)."
741
+ }
742
+ }
743
+ },
744
+ "AgentResources": {
745
+ "title": "AgentResources",
746
+ "type": "object",
747
+ "additionalProperties": false,
748
+ "description": "The instrumentation's own resources. Every field is optional and **absent is not zero**: an older sender says nothing, and a cloud that read that as «nothing was lost» would be inventing the one answer this exists to stop it inventing (invariant 14). The counters are differences since the previous batch, like everything else here; the two that are instants say so.",
749
+ "properties": {
750
+ "droppedBatches": {
751
+ "type": "integer",
752
+ "minimum": 0,
753
+ "description": "Batches the instrumentation threw away because its queue was full, since the previous batch. This is telemetry that existed and is gone: the number that separates «nothing happened» from «nothing arrived»."
754
+ },
755
+ "rejectedBatches": {
756
+ "type": "integer",
757
+ "minimum": 0,
758
+ "description": "Batches the cloud refused as invalid, since the previous batch. Nothing broke: something was sent wrong."
759
+ },
760
+ "failedBatches": {
761
+ "type": "integer",
762
+ "minimum": 0,
763
+ "description": "Batches that could not be sent —network, timeout, a cloud that was not there— since the previous batch. Not the same as dropped: these are retried, and only become loss if the queue fills."
764
+ },
765
+ "internalErrors": {
766
+ "type": "integer",
767
+ "minimum": 0,
768
+ "description": "Errors inside the instrumentation itself, since the previous batch. It disables itself after enough of them, and a sender that has gone quiet with these climbing is not a quiet service."
769
+ },
770
+ "bufferBytes": {
771
+ "type": "integer",
772
+ "minimum": 0,
773
+ "description": "What the black box's registers have allocated, right now. An instant, and arithmetic rather than a measurement: the rings are preallocated."
774
+ },
775
+ "hookMsPerRequest": {
776
+ "type": "number",
777
+ "minimum": 0,
778
+ "description": "Estimated milliseconds of the instrumentation's own hooks per request. **An estimate**, sampled, and named as one: it is what invariant 3 budgets, and reporting it as an exact measurement would claim a precision the sampling does not have."
779
+ },
780
+ "shed": {
781
+ "type": "string",
782
+ "enum": [
783
+ "nothing",
784
+ "fine",
785
+ "profile"
786
+ ],
787
+ "description": "What the instrumentation has given up because it was costing too much, cheapest loss first. `product.md:241` asks for both halves —«se autolimita» and «lo registra como pérdida de cobertura»— and this is the second. An enum and not free text: it is ours, and it has to be comparable between senders."
788
+ },
789
+ "shedReason": {
790
+ "type": "string",
791
+ "enum": ["latency", "memory"],
792
+ "description": "Why it gave ground. Absent when nothing was given up."
793
+ }
794
+ }
795
+ }
796
+ }
797
+ };
798
+ //#endregion
799
+ //#region schema/v0/capture-evidence.schema.json
800
+ var capture_evidence_schema_default = {
801
+ $schema: "https://json-schema.org/draft/2020-12/schema",
802
+ $id: "https://downtrace.io/schema/v0/capture-evidence.schema.json",
803
+ title: "CaptureEvidence",
804
+ description: "What an instrumentation sends back for a capture the cloud asked for (POST /v0/captures/{id}/evidence). It is the contents of the black box's fine register, frozen: requests with their operations, in order, with starts and ends. Hashes only — the text of a query never travels here (invariant 5). Its own path and not the aggregates batch, because a batch is what goes out every ten seconds and this is a rare event several orders of magnitude larger.",
805
+ "x-evidence-path": "/v0/captures/{id}/evidence",
806
+ type: "object",
807
+ additionalProperties: false,
808
+ required: [
809
+ "protocol",
810
+ "instance",
811
+ "startedAt",
812
+ "endedAt",
813
+ "coverage",
814
+ "requests"
815
+ ],
816
+ properties: {
817
+ "protocol": {
818
+ "type": "string",
819
+ "description": "Protocol version this payload conforms to. Same enum as a batch: every published minor of v0 stays acceptable.",
820
+ "enum": [
821
+ "0.1.0",
822
+ "0.2.0",
823
+ "0.3.0",
824
+ "0.4.0",
825
+ "0.5.0",
826
+ "0.6.0",
827
+ "0.7.0"
828
+ ]
829
+ },
830
+ "instance": {
831
+ "type": "object",
832
+ "additionalProperties": false,
833
+ "required": ["id"],
834
+ "description": "Which process observed this. Several instances of one deployment get the same order on purpose (ADR 0071), so the cloud has to be able to tell two answers apart.",
835
+ "properties": {
836
+ "id": {
837
+ "type": "string",
838
+ "minLength": 1,
839
+ "maxLength": 128
840
+ },
841
+ "hostname": {
842
+ "type": "string",
843
+ "maxLength": 253
844
+ },
845
+ "pid": {
846
+ "type": "integer",
847
+ "minimum": 0
848
+ }
849
+ }
850
+ },
851
+ "startedAt": {
852
+ "type": "string",
853
+ "format": "date-time",
854
+ "description": "The **effective start of observation**, which is the instant CAP-01 insists on keeping apart from the acceptance. It travels with the evidence rather than in a call of its own: a capture that started and never finished should not cost two requests."
855
+ },
856
+ "endedAt": {
857
+ "type": "string",
858
+ "format": "date-time",
859
+ "description": "When the instrumentation stopped watching."
860
+ },
861
+ "coverage": { "$ref": "#/$defs/Coverage" },
862
+ "requests": {
863
+ "type": "array",
864
+ "maxItems": 4096,
865
+ "items": { "$ref": "#/$defs/CapturedRequest" },
866
+ "description": "The requests observed, oldest first. An empty array is a real answer and the commonest one: a route nobody called during the window. It means the capture is `empty`, and `product.md:192` is explicit that this must never read as an invitation to ask again unchanged."
867
+ },
868
+ "reference": { "$ref": "#/$defs/Reference" }
869
+ },
870
+ $defs: {
871
+ "Coverage": {
872
+ "type": "object",
873
+ "title": "CaptureCoverage",
874
+ "additionalProperties": false,
875
+ "required": [
876
+ "observedRequests",
877
+ "attachedRequests",
878
+ "detailLost",
879
+ "truncated"
880
+ ],
881
+ "description": "`product.md:192` asks a capture to declare **both** coverages: what it attached from detail still retained, and what it observed from its effective start. Two numbers, never one — a total would hide that half of it is older than the capture.",
882
+ "properties": {
883
+ "observedRequests": {
884
+ "type": "integer",
885
+ "minimum": 0,
886
+ "description": "Requests seen from the effective start onwards."
887
+ },
888
+ "attachedRequests": {
889
+ "type": "integer",
890
+ "minimum": 0,
891
+ "description": "Requests that were already in the register when the capture started, and are attached. Zero is normal: the register may have wrapped, and nothing brings back what was not kept."
892
+ },
893
+ "detailLost": {
894
+ "type": "integer",
895
+ "minimum": 0,
896
+ "description": "Requests whose operations were overwritten before they could be read. Their timing is still true; what is gone is the detail. Reported rather than dropped, because a request with no operations reads as one that ran nothing (invariant 14)."
897
+ },
898
+ "truncated": {
899
+ "type": "integer",
900
+ "minimum": 0,
901
+ "description": "Requests that ran more operations than the register keeps per request. Their count is real and their list is not complete."
902
+ }
903
+ }
904
+ },
905
+ "CapturedRequest": {
906
+ "type": "object",
907
+ "title": "CapturedRequest",
908
+ "additionalProperties": false,
909
+ "required": [
910
+ "method",
911
+ "route",
912
+ "status",
913
+ "startedAt",
914
+ "durationMs",
915
+ "operations"
916
+ ],
917
+ "properties": {
918
+ "method": {
919
+ "type": "string",
920
+ "maxLength": 16
921
+ },
922
+ "route": {
923
+ "type": "string",
924
+ "maxLength": 512,
925
+ "description": "The route template, never the path with its values in it (invariant 5)."
926
+ },
927
+ "status": {
928
+ "type": "integer",
929
+ "minimum": 100,
930
+ "maximum": 599
931
+ },
932
+ "startedAt": {
933
+ "type": "string",
934
+ "format": "date-time",
935
+ "description": "When this request started. Absolute, so requests from two instances can be read side by side."
936
+ },
937
+ "durationMs": {
938
+ "type": "number",
939
+ "minimum": 0
940
+ },
941
+ "operations": {
942
+ "type": "array",
943
+ "maxItems": 256,
944
+ "items": { "$ref": "#/$defs/CapturedOperation" },
945
+ "description": "What it ran, in the order it started them. Empty means it ran nothing — unless `detailLost` says the list was overwritten, which is why that flag is on the request and not only in the totals."
946
+ },
947
+ "truncated": {
948
+ "type": "boolean",
949
+ "description": "This request ran more operations than the register keeps per request. Absent means false."
950
+ },
951
+ "detailLost": {
952
+ "type": "boolean",
953
+ "description": "This request's operations were overwritten before they were read. Absent means false. Its timing is still true."
954
+ }
955
+ }
956
+ },
957
+ "CapturedOperation": {
958
+ "type": "object",
959
+ "title": "CapturedOperation",
960
+ "additionalProperties": false,
961
+ "required": [
962
+ "hash",
963
+ "startMs",
964
+ "endMs"
965
+ ],
966
+ "description": "One operation inside a request. Starts and ends and not durations, because the whole reason for capturing detail is order and overlap, which a duration cannot express (ADR 0068).",
967
+ "properties": {
968
+ "hash": {
969
+ "type": "string",
970
+ "minLength": 1,
971
+ "maxLength": 64,
972
+ "description": "The fingerprint's hash. Never the text: the profile is where a sender chooses whether to ship the text of its queries, and this path never carries it (invariant 5, ADR 0017)."
973
+ },
974
+ "startMs": {
975
+ "type": "number",
976
+ "minimum": 0,
977
+ "description": "Milliseconds from the start of its own request."
978
+ },
979
+ "endMs": {
980
+ "type": "number",
981
+ "minimum": 0
982
+ }
983
+ }
984
+ },
985
+ "Reference": {
986
+ "type": "object",
987
+ "title": "ReferenceSamples",
988
+ "additionalProperties": false,
989
+ "required": [
990
+ "selection",
991
+ "population",
992
+ "samples"
993
+ ],
994
+ "description": "A few requests of each endpoint kept as something to compare the captured ones against. `product.md:100`: «Comparar requests degradadas con requests de referencia exige conservar ambas; el detalle fino de hace una hora ya no existe». Being earlier does not certify health, which is why every field here is about how they were chosen and none of them says «healthy».",
995
+ "properties": {
996
+ "selection": {
997
+ "type": "string",
998
+ "enum": ["uniform-reservoir"],
999
+ "description": "How they were chosen. Travels with them because a sample whose selection is unknown cannot support an attribution (ATR-01). `uniform-reservoir`: every request observed of that endpoint had the same chance of being kept, whatever it did — which is what «the fastest N» would not be."
1000
+ },
1001
+ "population": {
1002
+ "type": "integer",
1003
+ "minimum": 0,
1004
+ "description": "How many requests they were drawn from, over the life of the sending process."
1005
+ },
1006
+ "routesDropped": {
1007
+ "type": "integer",
1008
+ "minimum": 0,
1009
+ "description": "Endpoints seen that the register had no room for. Counted rather than silently absent: an endpoint with no samples is not an endpoint with no traffic (invariant 14)."
1010
+ },
1011
+ "renewalPaused": {
1012
+ "type": "boolean",
1013
+ "description": "True when requests were observed that the register deliberately did not consider. The instrumentation pauses renewal while it is watching a capture, which is the closest it can get to REF-01 from inside the process: it cannot know whether an incident is open, but it knows detail has been asked of it. Absent means false."
1014
+ },
1015
+ "samples": {
1016
+ "type": "array",
1017
+ "maxItems": 64,
1018
+ "items": { "$ref": "#/$defs/CapturedRequest" },
1019
+ "description": "The kept requests, in the same shape as the captured ones. An empty array is a real answer: a process that has just started has nothing to compare with yet."
568
1020
  }
569
1021
  }
570
1022
  }
571
1023
  }
572
1024
  };
573
1025
  //#endregion
1026
+ //#region schema/v0/ingest-response.schema.json
1027
+ var ingest_response_schema_default = {
1028
+ $schema: "https://json-schema.org/draft/2020-12/schema",
1029
+ $id: "https://downtrace.io/schema/v0/ingest-response.schema.json",
1030
+ title: "IngestResponse",
1031
+ description: "What the cloud answers to POST /v0/aggregates. Described here, and not left as an implementation detail, because since protocol 0.7.0 it carries instructions: the captures the cloud is waiting for. It follows the same rules as the batch — fields are only ever added, each addition bumps the minor, and a published minor is accepted for ever — with one difference in who owes what. An agent that does not read this body must behave exactly as it did before (ADR 0008), so every field here is something an agent may ignore.",
1032
+ type: "object",
1033
+ additionalProperties: false,
1034
+ required: ["accepted", "inserted"],
1035
+ properties: {
1036
+ "accepted": {
1037
+ "type": "integer",
1038
+ "minimum": 0,
1039
+ "description": "How many intervals of the batch the cloud took."
1040
+ },
1041
+ "inserted": {
1042
+ "type": "integer",
1043
+ "minimum": 0,
1044
+ "description": "How many rows were new. Lower than `accepted` when a batch is re-sent: ingest is idempotent."
1045
+ },
1046
+ "captures": {
1047
+ "type": "array",
1048
+ "maxItems": 16,
1049
+ "items": { "$ref": "#/$defs/PendingCapture" },
1050
+ "description": "Captures the cloud is waiting for, in the environment this batch came from. Absent or empty means none. Bounded because this rides on every batch: the cloud never asks for more at once than an instrumentation could reasonably freeze, and the concurrency budget is far below this anyway. Several instances of one deployment receive the same list on purpose — the cloud knows which instance sent recently, not which is alive, so dealing one capture to one instance would lose it silently when that process is gone (invariant 14)."
1051
+ }
1052
+ },
1053
+ $defs: { "PendingCapture": {
1054
+ "type": "object",
1055
+ "title": "PendingCapture",
1056
+ "additionalProperties": false,
1057
+ "required": [
1058
+ "id",
1059
+ "windowSeconds",
1060
+ "expiresAt"
1061
+ ],
1062
+ "properties": {
1063
+ "id": {
1064
+ "type": "string",
1065
+ "minLength": 1,
1066
+ "maxLength": 64,
1067
+ "description": "What the evidence will be sent back under. Carries nothing the service wrote."
1068
+ },
1069
+ "environment": {
1070
+ "type": "string",
1071
+ "maxLength": 128,
1072
+ "description": "The environment this capture is about, which is always the one the batch came from. Sent anyway so the payload is readable on its own."
1073
+ },
1074
+ "method": {
1075
+ "type": "string",
1076
+ "maxLength": 16,
1077
+ "description": "HTTP method of the route to watch."
1078
+ },
1079
+ "route": {
1080
+ "type": "string",
1081
+ "maxLength": 512,
1082
+ "description": "Route template to watch. Empty when the capture is about a dependency rather than a route."
1083
+ },
1084
+ "kind": {
1085
+ "type": "string",
1086
+ "maxLength": 32,
1087
+ "description": "Dependency kind to watch. Empty when the capture is about a route."
1088
+ },
1089
+ "target": {
1090
+ "type": "string",
1091
+ "maxLength": 256,
1092
+ "description": "Dependency target to watch."
1093
+ },
1094
+ "windowSeconds": {
1095
+ "type": "integer",
1096
+ "minimum": 1,
1097
+ "maximum": 600,
1098
+ "description": "How long to watch for, from the effective start of observation."
1099
+ },
1100
+ "expiresAt": {
1101
+ "type": "string",
1102
+ "format": "date-time",
1103
+ "description": "After this instant the cloud stops waiting. An instrumentation that reads a stale response must not start a capture past it: the cloud will refuse the evidence, and a capture nobody is waiting for spends the fine register for nothing."
1104
+ }
1105
+ }
1106
+ } }
1107
+ };
1108
+ //#endregion
574
1109
  //#region src/generated/boundaries.ts
575
1110
  /** Upper bounds (ms) of the fixed latency buckets; the last bucket is open-ended. */
576
1111
  const LATENCY_BOUNDARIES_V0 = [
@@ -627,6 +1162,12 @@ const CALLS_PER_REQUEST_BUCKETS_V0 = 8;
627
1162
  //#region src/generated/paths.ts
628
1163
  /** Path, relative to the ingest URL, that receives AggregatesBatch payloads. */
629
1164
  const AGGREGATES_PATH = "/v0/aggregates";
1165
+ /** Path template that receives a capture's evidence. `{id}` is the capture's identifier. */
1166
+ const CAPTURE_EVIDENCE_PATH = "/v0/captures/{id}/evidence";
1167
+ /** The evidence path for one capture. Here rather than in every caller: one place builds it (gh-322). */
1168
+ function captureEvidencePath(id) {
1169
+ return CAPTURE_EVIDENCE_PATH.replace("{id}", encodeURIComponent(id));
1170
+ }
630
1171
  //#endregion
631
1172
  //#region src/generated/versions.ts
632
1173
  /** Every published minor of v0, oldest first. The cloud never stops accepting one it published (ADR 0008). */
@@ -636,14 +1177,26 @@ const ACCEPTED_PROTOCOL_VERSIONS_V0 = [
636
1177
  "0.3.0",
637
1178
  "0.4.0",
638
1179
  "0.5.0",
639
- "0.6.0"
1180
+ "0.6.0",
1181
+ "0.7.0"
640
1182
  ];
641
1183
  /** The newest published minor: what an up-to-date agent stamps on every batch. */
642
- const PROTOCOL_VERSION = "0.6.0";
1184
+ const PROTOCOL_VERSION = "0.7.0";
643
1185
  //#endregion
644
1186
  //#region src/index.ts
645
1187
  /** The JSON Schema (draft 2020-12) for AggregatesBatch, for validators on either side. */
646
1188
  const AGGREGATES_SCHEMA_V0 = aggregates_schema_default;
1189
+ /**
1190
+ * The JSON Schema for what the cloud answers. A contract since 0.8.0, when the answer started carrying the
1191
+ * captures the cloud is waiting for: an agent that ignores this body behaves exactly as it always did.
1192
+ */
1193
+ const INGEST_RESPONSE_SCHEMA_V0 = ingest_response_schema_default;
1194
+ /**
1195
+ * The JSON Schema for a capture's evidence: the black box's fine detail, frozen and sent back. Its own path
1196
+ * and its own contract, because a batch goes out every ten seconds and this is a rare event several orders of
1197
+ * magnitude larger.
1198
+ */
1199
+ const CAPTURE_EVIDENCE_SCHEMA_V0 = capture_evidence_schema_default;
647
1200
  /** Index of the bucket a latency (ms) falls into: first boundary >= latency, else the open-ended last bucket. */
648
1201
  function latencyBucket(ms) {
649
1202
  const n = LATENCY_BOUNDARIES_V0.length;
@@ -663,4 +1216,4 @@ function callsPerRequestBucket(calls) {
663
1216
  return n;
664
1217
  }
665
1218
  //#endregion
666
- export { ACCEPTED_PROTOCOL_VERSIONS_V0, AGGREGATES_PATH, AGGREGATES_SCHEMA_V0, CALLS_PER_REQUEST_BOUNDARIES_V0, CALLS_PER_REQUEST_BUCKETS_V0, LATENCY_BOUNDARIES_V0, LATENCY_BUCKETS_V0, PROTOCOL_VERSION, callsPerRequestBucket, latencyBucket };
1219
+ export { ACCEPTED_PROTOCOL_VERSIONS_V0, AGGREGATES_PATH, AGGREGATES_SCHEMA_V0, CALLS_PER_REQUEST_BOUNDARIES_V0, CALLS_PER_REQUEST_BUCKETS_V0, CAPTURE_EVIDENCE_PATH, CAPTURE_EVIDENCE_SCHEMA_V0, INGEST_RESPONSE_SCHEMA_V0, LATENCY_BOUNDARIES_V0, LATENCY_BUCKETS_V0, PROTOCOL_VERSION, callsPerRequestBucket, captureEvidencePath, latencyBucket };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@downtrace/protocol",
3
- "version": "0.6.0",
3
+ "version": "0.7.1",
4
4
  "description": "Downtrace ingestion protocol: JSON Schema, fixtures and generated TypeScript types",
5
5
  "type": "module",
6
6
  "exports": {