OpenTelemetry instrumentation for light-my-request, which instruments Fastify's inject() method for testing and internal request handling.
npm install @platformatic/instrumentation-light-my-requestThis instrumentation automatically patches light-my-request to create OpenTelemetry spans for injected requests. This is useful because fastify.inject() bypasses HTTP entirely, so standard HTTP instrumentation doesn't capture these operations.
import { NodeSDK } from '@opentelemetry/sdk-node'
import { LightMyRequestInstrumentation } from '@platformatic/instrumentation-light-my-request'
const sdk = new NodeSDK({
instrumentations: [
new LightMyRequestInstrumentation()
]
})
sdk.start()import { registerInstrumentations } from '@opentelemetry/instrumentation'
import { LightMyRequestInstrumentation } from '@platformatic/instrumentation-light-my-request'
registerInstrumentations({
instrumentations: [
new LightMyRequestInstrumentation()
]
})- Automatic span creation: Creates SERVER spans for each
inject()call - Context propagation: Extracts trace context from injected headers
- Error tracking: Records exceptions and sets appropriate span status
- Promise and callback support: Works with both callback and promise-based inject calls
- Provider-agnostic: Uses
this.tracergetter, works with any TracerProvider
This instrumentation follows OpenTelemetry semantic conventions and sets the following attributes:
http.request.method: HTTP method (GET, POST, etc.)url.path: Path portion of the URL (without query string)url.scheme: URL scheme (defaults to "http")
url.full: Full URL of the requestserver.address: Server hostname (extracted from Host header)server.port: Server port (extracted from Host header)client.address: Client IP address (fromremoteAddressoption)user_agent.original: User-Agent header valuenetwork.protocol.version: HTTP protocol version (if available)
http.response.status_code: HTTP status code (set when response is received)url.query: Query string portion of the URL (set when query parameters are present)error.type: Error type/name for exceptions, or HTTP status code for 4xx/5xx responses
Fastify's inject() method is used for:
- Testing Fastify applications
- Internal request routing (e.g., in Platformatic's thread-interceptor)
- Simulating HTTP requests without network overhead
Since these requests bypass HTTP, standard HTTP instrumentation doesn't see them. This instrumentation fills that gap by patching light-my-request directly.
- light-my-request: >=4.0.0
- Node.js: >=20.0.0
- @opentelemetry/api: ^1.0.0
- Works with any OpenTelemetry-compatible TracerProvider
Apache-2.0