mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 14:10:49 -05:00
X-Ray is the one AWS service local stacks ask for and Floci does not have: SQS
and SNS already carry AWSTraceHeader, and nothing on the other end accepts the
segments that header points at. This serves the ingest loop, the summaries that
read it back, the service graph a console draws from it, and the sampling the
X-Ray daemon polls on its own timers.
The API is REST JSON on literal paths (/TraceSegments, /Traces, /TraceSummaries,
/ServiceGraph, /TraceGraph, /GetSamplingRules, ...), which S3's path-style routes
would swallow as a bucket name, so a request signed for the xray credential scope
is rewritten onto an internal prefix and every other request keeps its path. Only
the paths Floci serves are claimed.
What Floci stores is the segment document as sent: BatchGetTraces has to answer
exactly what PutTraceSegments accepted, so re-serialising through a model would
change what the caller reads. The summaries and the graph parse those documents
on read, which keeps the stored bytes the caller's and costs nothing while a local
stack is idle.
A filter expression is parsed, not pattern-matched: service("name"), hasError,
hasFault, hasThrottle, duration, responsetime, http.status, annotation.key,
comparisons, AND, OR, NOT and parentheses. Anything outside that set is refused
with InvalidRequestException naming what it could not read, because accepting a
filter and ignoring half of it hands a caller a superset and looks like a pass. A
lone '!' is refused the same way rather than left as a delimiter no branch
consumes, and responsetime is compared in seconds, the unit AWS uses.
The graph collapses segments into services by name, derives edges from parent ids,
and reports AWS's SummaryStatistics and cumulative DurationHistogram per node and
per edge. A node is a service, not a document shape: the same service seen once
with an http block and once without is one node.
Sampling answers the Default rule AWS serves in every Region, so a daemon has
something to sample at before any rule exists, and five rules per Region on top of
it. It is answered, not adapted: the reservoir is reported as the quota and
renewed every 10 seconds rather than decremented per report, and the service page
says so.
A local emulator runs for days, so the store is bounded to 10000 traces per Region
with AWS's 30 day window, oldest evicted first. A bad document is reported under
UnprocessedTraceSegments with its reason instead of failing the whole call, and
100 documents per call is the AWS limit, enforced.
Co-authored-by: David Guardiola <davidguardiola@gmail.com>
98 lines
5.3 KiB
Markdown
98 lines
5.3 KiB
Markdown
# AWS X-Ray
|
|
|
|
**Protocol:** REST JSON
|
|
**Endpoint:** `http://localhost:4566/TraceSegments` (SigV4 service `xray`)
|
|
|
|
Floci emulates the X-Ray tracing API. A client, the X-Ray SDK or the X-Ray daemon sends
|
|
segment documents and Floci stores them by trace, returning them exactly as they were
|
|
sent. Traces are isolated by account and Region, and kept for the same 30 day window AWS
|
|
uses.
|
|
|
|
Point any client at the emulator and the existing configuration works unchanged:
|
|
|
|
```bash
|
|
export AWS_ENDPOINT_URL=http://localhost:4566
|
|
aws xray put-trace-segments --trace-segment-documents file://segment.json
|
|
aws xray batch-get-traces --trace-ids 1-5f3b8a0e-3c9d4d8e9b7a2c1d4e5f6a7b
|
|
```
|
|
|
|
The X-Ray daemon reads the endpoint from the standard AWS environment, so the same
|
|
variable points it at Floci. It is the real gate for this service: it fetches sampling
|
|
rules, samples, sends segments and reports telemetry on its own timers.
|
|
|
|
```bash
|
|
docker run -d --name xray-daemon -p 2000:2000/tcp -p 2000:2000/udp \
|
|
-e AWS_ENDPOINT_URL=http://host.docker.internal:4566 \
|
|
-e AWS_REGION=us-east-1 \
|
|
-e AWS_ACCESS_KEY_ID=test -e AWS_SECRET_ACCESS_KEY=test \
|
|
amazon/aws-xray-daemon -o -n us-east-1
|
|
```
|
|
|
|
Send a segment to the daemon over UDP, the way an instrumented app does:
|
|
|
|
```bash
|
|
printf '{"format": "json", "version": 1}\n%s\n' \
|
|
'{"trace_id":"1-abcdef01-23456789abcdef0123456789","id":"0f1e2d3c4b5a6979",
|
|
"name":"orders-api","start_time":1794038810.0,"end_time":1794038811.0}' \
|
|
| nc -u -w1 127.0.0.1 2000
|
|
```
|
|
|
|
## Supported Actions
|
|
|
|
<!-- floci:actions:start -->
|
|
| Action | Description |
|
|
| --- | --- |
|
|
| `PutTraceSegments` | Stores segment documents grouped by trace and reports the ones it cannot index. |
|
|
| `BatchGetTraces` | Returns the stored segments of up to five traces, exactly as they were sent. |
|
|
| `GetTraceSummaries` | Lists the traces in a time window, filtered by the supported expression subset. |
|
|
| `GetServiceGraph` | Aggregates every trace in a window into services, calls between them and their counts. |
|
|
| `GetTraceGraph` | Answers the same graph for named traces, without a window. |
|
|
| `GetSamplingRules` | Lists the sampling rules of a Region, always including the `Default` rule AWS serves. |
|
|
| `CreateSamplingRule` | Creates a sampling rule, minting its ARN, up to five per Region. |
|
|
| `UpdateSamplingRule` | Changes the members supplied for a rule and keeps the rest, as AWS does. |
|
|
| `DeleteSamplingRule` | Deletes a rule by name or ARN; the `Default` rule cannot be deleted. |
|
|
| `GetSamplingTargets` | Answers the fixed rate and reservoir quota the daemon should sample at. |
|
|
| `PutTelemetryRecords` | Accepts the segment and connection counters the daemon reports. |
|
|
<!-- floci:actions:end -->
|
|
|
|
`PutTraceSegments` accepts up to 100 documents per call and reports the ones it refuses
|
|
under `UnprocessedTraceSegments`, per document, instead of failing the whole request.
|
|
`BatchGetTraces` takes up to 5 trace ids and answers the stored documents verbatim.
|
|
|
|
`GetTraceSummaries` takes a `StartTime`/`EndTime` window and answers one summary per trace,
|
|
with the duration, the outcome flags, the HTTP call, the services the trace touched and the
|
|
root segment's annotations. `FilterExpression` supports `service("name")`, the `ok`, `error`,
|
|
`fault` and `throttle` keywords, `duration`, `responsetime`, `http.status`, `annotation.key`,
|
|
comparisons, `AND`, `OR`, `NOT`, `!` and parentheses; anything outside that set is refused with
|
|
`InvalidRequestException` rather than ignored, so a filter never quietly returns a superset.
|
|
|
|
`GetServiceGraph` and `GetTraceGraph` answer the same shape: one node per service, one edge per
|
|
call a segment made into another, `SummaryStatistics` with ok/error/fault/throttle counts and
|
|
`DurationHistogram` in cumulative buckets. A node's `Type` is `client` when the segment has an
|
|
`http` block and no `aws` block, and is omitted otherwise.
|
|
|
|
`GetSamplingRules` always answers the `Default` rule AWS serves in every Region (priority 10000,
|
|
fixed rate 0.05, reservoir 1), so a daemon has something to sample at before any rule exists. A
|
|
Region takes five rules, the `Default` one excluded and not editable, and `GetSamplingTargets`
|
|
answers each rule's fixed rate with its reservoir size as the quota, renewed every 10 seconds.
|
|
`LastRuleModification` moves when any rule of the Region changes, so a daemon that did not name the
|
|
changed rule still refetches the set.
|
|
|
|
## Not emulated
|
|
|
|
Floci stores, serves and aggregates traces; it does not analyse them. Insights, trace retrieval
|
|
jobs, indexing rules, groups and tags are not served: their paths are not claimed by this service, so
|
|
a call to them reaches whatever else claims the path (S3's `/{bucket}` routes) rather than answering
|
|
an AWS-shaped error.
|
|
|
|
The rest of Floci is not instrumented either: the segments are those a client, an SDK or the daemon
|
|
sends. Lambda and API Gateway do not emit segments of their own, so a trace that crosses them shows
|
|
only what the caller recorded.
|
|
|
|
Sampling is answered, not enforced: the daemon is given a fixed rate and a reservoir quota, but the
|
|
quota is not decremented per report, so a client keeps sampling at the rule's rate for as long as it
|
|
runs. That is enough to exercise a trace pipeline locally and is not AWS's adaptive sampling.
|
|
|
|
The store is bounded: at most 10 000 traces per Region, oldest evicted first, so a long
|
|
running emulator does not grow without bound.
|