Lesson 1 · Unit 04
Instrumenting
Where a span or a metric earns its place, naming, vendor-neutral instrumentation in outline, and sampling.
What you practise
- Where a span or a metric earns its place, naming, vendor-neutral instrumentation (OpenTelemetry) in outline, sampling
Try a question from this lesson
Pick one
A date helper runs 40 times per request and takes 2 microseconds. A call to the payment provider runs once and takes 80 to 2,000 ms. You may wrap one in a span. Which?
Hint
Which one could be the answer to "why was this request slow"?
Correct answer
The provider call: slow, variable, and it can fail
Why
A span is worth its cost where time and failure hide: a call that leaves the process. Wrapping the helper would add 40 spans per request, each costing more than the work it measures, and tell you nothing you will ever need.
The ideas
Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.
Concept
Instrument the boundaries
Put a span where work crosses a boundary: a request arriving, a call going out to a service, a database or a queue. Those are the places that are slow, that fail, and that you do not control.
Metrics: the golden signals for each service, plus a counter for each event the business counts. Code in between rarely needs either.
request in span + rate, errors,
duration
call out (http) span
database query span
order placed counter
a loop, a helper nothingConcept
Vendor-neutral instrumentation
If your code calls one company's tracing library, changing company means touching every call. OpenTelemetry is the open standard that prevents this, in three parts.
The API is what your code calls to start a span or record a metric. The SDK batches and samples. An exporter sends the data on, and is picked in configuration.
Libraries for common frameworks can add the boundary spans for you.
your code -> API -> SDK -> exporter
|
any backend you chooseConcept
Sampling
Keeping every trace of a busy service costs more than it teaches. Sampling keeps a share.
Head sampling decides when the request starts, usually from the trace id, and passes the verdict along with the context. Whole traces are kept or dropped. It is cheap, and blind: it cannot know the request will fail.
Tail sampling decides after the trace is complete, so it can keep every error. It must hold all spans until then.
head decide at the start, by trace id
cheap; errors kept only by luck
tail decide at the end, by content
keeps errors; must buffer spans9 more exercises in the app
- 4× multiple choice
- 1× fill the blanks
- 1× order the lines
- 2× type the answer
- 1× true or false
Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.