@@ -5,7 +5,6 @@ https://github.com/fastify/otel/releases/tag/v0.8.0
55Tried not to modify the original code too much keeping it as a JavaScript CJS module to make it easier to update when required
66
77Modifications include:
8- - Removed `logger` as it created problems with TypesScript
98- Removed reading of package.json to get the version and package name
109
1110MIT License
@@ -36,7 +35,7 @@ SOFTWARE.
3635/* eslint-disable max-lines */
3736/* eslint-disable no-param-reassign */
3837import dc from 'node:diagnostics_channel' ;
39- import { context , propagation , SpanStatusCode , trace } from '@opentelemetry/api' ;
38+ import { context , diag , propagation , SpanStatusCode , trace } from '@opentelemetry/api' ;
4039import { getRPCMetadata , RPCType } from '@opentelemetry/core' ;
4140import { InstrumentationBase } from '@opentelemetry/instrumentation' ;
4241import {
@@ -89,6 +88,7 @@ export class FastifyOtelInstrumentation extends InstrumentationBase {
8988 super ( PACKAGE_NAME , PACKAGE_VERSION , config ) ;
9089 this . servername = config ?. servername ?? process . env . OTEL_SERVICE_NAME ?? 'fastify' ;
9190 this [ kIgnorePaths ] = null ;
91+ this . _logger = diag . createComponentLogger ( { namespace : PACKAGE_NAME } ) ;
9292
9393 if ( config ?. ignorePaths != null || process . env . OTEL_FASTIFY_IGNORE_PATHS != null ) {
9494 const ignorePaths = config ?. ignorePaths ?? process . env . OTEL_FASTIFY_IGNORE_PATHS ;
@@ -177,9 +177,9 @@ export class FastifyOtelInstrumentation extends InstrumentationBase {
177177
178178 instance . addHook ( 'onRoute' , function ( routeOptions ) {
179179 if ( instrumentation [ kIgnorePaths ] ?. ( routeOptions ) === true ) {
180- // instrumentation.logger .debug(
181- // `Ignoring route instrumentation ${routeOptions.method} ${routeOptions.url} because it matches the ignore path`,
182- // );
180+ instrumentation . _logger . debug (
181+ `Ignoring route instrumentation ${ routeOptions . method } ${ routeOptions . url } because it matches the ignore path` ,
182+ ) ;
183183 return ;
184184 }
185185
@@ -254,9 +254,9 @@ export class FastifyOtelInstrumentation extends InstrumentationBase {
254254 method : request . method ,
255255 } ) === true
256256 ) {
257- // this[kInstrumentation].logger .debug(
258- // `Ignoring request ${request.method} ${request.url} because it matches the ignore path`,
259- // );
257+ this [ kInstrumentation ] . _logger . debug (
258+ `Ignoring request ${ request . method } ${ request . url } because it matches the ignore path` ,
259+ ) ;
260260 return hookDone ( ) ;
261261 }
262262
0 commit comments