@luvio/service-instrumentation
v5.24.1
Published
Luvio Instrumentation Service definition
Downloads
622
Maintainers
Keywords
Readme
This software is provided as-is with no support provided.
Instrumentation Service
We are about standards around here. OpenTelemetry is the standard. We are also about exposing what makes sense from their API for a library. We want to trace and record metrics. We want to log too, but that component is under development (as of March 2024), so for the sake of stability we will hold off on that.
No-Op Implementation
We provide a no-op implementation OOTB, so things run smoothly when an actual implementation is not provided.
Use buildNoopInstrumentationService
when building out your services.
import { buildNoopInstrumentationService } from '@luvio/service-instrumentation/v1';
Aside: We originally tried using the no-op implementations provided by the OTel API, but it came with a cost of 7kb, which was a little rich for our taste, especially when this service exposes a relatively small subset of the API. I'm sure there is a way to scope it down, but for now we make due with our own
Adding to the interface
So you realized we have to have DiagAPI
as part of the API? (We probably should add it at some point)
The process is pretty simple, albeit tedious (with the handrolling of a No-Op implementation and the unit-testing). What's important is that we are only pulling in the portion of the API that makes sense. For example, with the TraceAPI, setGlobalTracerProvider
is the responsibility of the runtime application, and we shouldn't have the power to set it ourselves, so we leave that out. With that in mind, there are only a few steps to take.
- Create a type from the OTel API you'd like to include, use
Pick<>
to select what makes sense - Add it to the service interface
- Create a No-Op implementation, along with unit tests to keep our code coverage happy
- Update the
buildNoopInstrumentationService
function we export with the service
Checkout this PR that adds the MetricsAPI to the service interface for guidance.