NOTE: Since this is a GitHub gist, subdirectories are not allowed, but that will mean we have two
package main
scripts in the same directory, which is problematic.
First, create symlinks to our scripts in separate directories
mkdir client/
ln -s ../client.go client/main.go
mkdir server/
ln -s ../server.go server/main.go
Then run two servers (a primary and downstream) and (after they are running) the client in three different shells. For example, the client output may resemble:
$ go run client/main.go
{"_timestamp":"2020-01-14T00:09:07.877225Z","flag":"info","text":"status: 200, body: \"ok!\""}
{"_timestamp":"2020-01-14T00:09:07.881183Z","flag":"info","text":"status: 200, body: \"outbound\""}
The main server:
$ go run server/main.go
{"_timestamp":"2020-01-14T00:08:54.076604Z","flag":"info","text":"http server started, listening on :8080"}
{"_timestamp":"2020-01-14T00:09:07.876169Z","flag":"http.request","host":"localhost:8080","ip":"::1","labels":{"web.route":"/"},"path":"/","query":"","route":"/","userAgent":"Go-http-client/1.1","verb":"GET"}
{"_timestamp":"2020-01-14T00:09:07.876286Z","annotations":{"dd":{"trace_id":1234567890,"span_id":5494006354809255998}},"flag":"info","labels":{"web.route":"/"},"text":"CLIENT: dd.trace_id: 1234567890 dd.span_id=9876543210"}
{"_timestamp":"2020-01-14T00:09:07.876403Z","annotations":{"dd":{"trace_id":1234567890,"span_id":5494006354809255998}},"flag":"info","labels":{"web.route":"/"},"text":"CURRENT: dd.trace_id: 1234567890 dd.span_id=5494006354809255998"}
{"_timestamp":"2020-01-14T00:09:07.876439Z","annotations":{"dd":{"trace_id":1234567890,"span_id":5494006354809255998}},"contentEncoding":"","contentLength":3,"contentType":"text/plain; charset=utf-8","elapsed":0.275,"flag":"http.response","host":"localhost:8080","ip":"::1","labels":{"web.route":"/"},"path":"/","query":"","route":"/","statusCode":200,"userAgent":"Go-http-client/1.1","verb":"GET"}
{"_timestamp":"2020-01-14T00:09:07.877457Z","flag":"http.request","host":"localhost:8080","ip":"::1","labels":{"web.route":"/outbound"},"path":"/outbound","query":"","route":"/outbound","userAgent":"Go-http-client/1.1","verb":"GET"}
{"_timestamp":"2020-01-14T00:09:07.880938Z","annotations":{"body":"ok!","dd":{"trace_id":1234567890,"span_id":4619113203306507260},"status":200},"flag":"info","labels":{"web.route":"/outbound"},"text":"HTTP response"}
{"_timestamp":"2020-01-14T00:09:07.88098Z","annotations":{"dd":{"trace_id":1234567890,"span_id":4619113203306507260}},"contentEncoding":"","contentLength":8,"contentType":"text/plain; charset=utf-8","elapsed":3.523,"flag":"http.response","host":"localhost:8080","ip":"::1","labels":{"web.route":"/outbound"},"path":"/outbound","query":"","route":"/outbound","statusCode":200,"userAgent":"Go-http-client/1.1","verb":"GET"}
{"_timestamp":"2020-01-14T00:09:27.522474Z","flag":"info","text":"server shutting down"}
{"_timestamp":"2020-01-14T00:09:27.522611Z","flag":"info","text":"server shutdown complete"}
{"_timestamp":"2020-01-14T00:09:27.522648Z","flag":"info","text":"server exited"}
and the second server (downstream of the main server, must be running on
port 9090
):
$ PORT=9090 go run server/main.go
{"_timestamp":"2020-01-14T00:09:06.17761Z","flag":"info","text":"http server started, listening on :9090"}
{"_timestamp":"2020-01-14T00:09:07.879909Z","flag":"http.request","host":"localhost:9090","ip":"::1","labels":{"web.route":"/"},"path":"/","query":"","route":"/","userAgent":"Go-http-client/1.1","verb":"GET"}
{"_timestamp":"2020-01-14T00:09:07.88004Z","annotations":{"dd":{"trace_id":1234567890,"span_id":8185291757207509523}},"flag":"info","labels":{"web.route":"/"},"text":"CLIENT: dd.trace_id: 1234567890 dd.span_id=5033722923861251624"}
{"_timestamp":"2020-01-14T00:09:07.880177Z","annotations":{"dd":{"trace_id":1234567890,"span_id":8185291757207509523}},"flag":"info","labels":{"web.route":"/"},"text":"CURRENT: dd.trace_id: 1234567890 dd.span_id=8185291757207509523"}
{"_timestamp":"2020-01-14T00:09:07.880212Z","annotations":{"dd":{"trace_id":1234567890,"span_id":8185291757207509523}},"contentEncoding":"","contentLength":3,"contentType":"text/plain; charset=utf-8","elapsed":0.315,"flag":"http.response","host":"localhost:9090","ip":"::1","labels":{"web.route":"/"},"path":"/","query":"","route":"/","statusCode":200,"userAgent":"Go-http-client/1.1","verb":"GET"}
{"_timestamp":"2020-01-14T00:09:26.395019Z","flag":"info","text":"server shutting down"}
{"_timestamp":"2020-01-14T00:09:26.395189Z","flag":"info","text":"server exited"}
{"_timestamp":"2020-01-14T00:09:26.395185Z","flag":"info","text":"server shutdown complete"}
-
There is no way to "merge" into context labels or annotations
-
The incoming
http.request
log does not get thedd
annotation, but to be useful (e.g. in Splunk), it should -
While doing this I stumbled upon the fact that the JSON logger drops this text log from the client on the floor
2020-01-10T22:54:55.119712Z [http.client.response]