@luvio/service-instrumentation
v5.66.0
Published
Luvio Instrumentation Service definition
Maintainers
Keywords
Readme
This software is provided as-is with no support provided.
Luvio Instrumentation Service
This package re-exports the instrumentation service interface types and implementations.
Package Structure
The instrumentation service is divided into the following packages:
@luvio/service-instrumentation-types: Type definitions@luvio/service-instrumentation-noop: A no-op implementation@luvio/service-instrumentation-o11y: An implementation using the O11y library
This main package (@luvio/service-instrumentation) re-exports all the types and implementations to maintain backward compatibility.
Installation
npm install @luvio/service-instrumentationUsage
// Using the noop implementation
import { buildNoopInstrumentationServiceDescriptor } from '@luvio/service-instrumentation/v1';
const noopService = buildNoopInstrumentationServiceDescriptor();
// Using the o11y implementation
import { buildO11yInstrumentationServiceDescriptor } from '@luvio/service-instrumentation/v1';
import { logger } from '@luvio/logger';
const o11yService = buildO11yInstrumentationServiceDescriptor(logger);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
buildNoopInstrumentationServicefunction we export with the service
Checkout this PR that adds the MetricsAPI to the service interface for guidance.
