trc
The trc package supports distributed tracing with OpenTelemetry. It defines various Options that can be applied to the tracing span using the options pattern. This pattern is used in Go for expressing optional arguments.
For example:
con.StartSpan(ctx, "Job", trc.String("name", "my job"))The options fall into three groups:
- Span kind —
Server,Client,Producer,Consumer,Internal. - Attributes —
String,Strings,Bool,Int,Float, plusRequestfor a request’s structural attributes andClientIPfor the caller’s address. - Timing —
Timestampsets the span’s event time explicitly rather than taking it from the clock at the call.
On a live span, SetAttributes adds attributes, SetError / SetOK record the outcome, the Log* methods attach events, and SetClientIP records the caller’s address.
Requests Contribute Structure, Never Credentials
A request’s structural attributes — method, scheme, host, port, path and body size — are attached to a server span when it is created, in every deployment.
Request headers and the query string are never recorded. Both routinely carry credentials, and dropping them wholesale is deliberate rather than filtering by well-known name, since a name list can only cover the framework’s own secrets and never an application’s. Because the structural attributes go on unconditionally, a PROD trace forced by an error still carries useful request context without ever having carried a secret. Distributed Tracing covers what this means when troubleshooting.