@adonisjs/otel 1.1.0 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ declare const _default: import("util").DebugLogger;
2
+ export default _default;
@@ -0,0 +1,2 @@
1
+ import { debuglog } from 'node:util';
2
+ export default debuglog('adonisjs:otel');
@@ -8,6 +8,7 @@ export declare class HttpUrlFilter {
8
8
  #private;
9
9
  static readonly DEFAULT_IGNORED_URLS: string[];
10
10
  static readonly STATIC_FILE_EXTENSIONS: Set<string>;
11
+ static readonly DEV_SERVER_PATTERNS: string[];
11
12
  constructor(config?: HttpInstrumentationConfig);
12
13
  /**
13
14
  * Check if a request should be ignored (not traced).
@@ -1,3 +1,4 @@
1
+ import debug from './debug.js';
1
2
  /**
2
3
  * Handles URL filtering for OpenTelemetry HTTP instrumentation.
3
4
  * Determines which requests should be ignored (not traced).
@@ -11,6 +12,13 @@ export class HttpUrlFilter {
11
12
  '/readiness',
12
13
  '/metrics',
13
14
  '/internal/metrics',
15
+ '/favicon.ico',
16
+ '/robots.txt',
17
+ '/sitemap.xml',
18
+ '/manifest.json',
19
+ '/site.webmanifest',
20
+ '/browserconfig.xml',
21
+ '/ads.txt',
14
22
  ];
15
23
  static STATIC_FILE_EXTENSIONS = new Set([
16
24
  'css',
@@ -40,7 +48,13 @@ export class HttpUrlFilter {
40
48
  'ogg',
41
49
  'wav',
42
50
  'pdf',
51
+ 'vue',
52
+ 'svelte',
53
+ 'webmanifest',
54
+ 'txt',
55
+ 'xml',
43
56
  ]);
57
+ static DEV_SERVER_PATTERNS = ['/@vite/', '/@id/', '/@fs/', '/__vite', '/@react-refresh'];
44
58
  #ignoredUrls;
45
59
  #ignoreStaticFiles;
46
60
  #ignoreOptionsRequests;
@@ -66,6 +80,9 @@ export class HttpUrlFilter {
66
80
  const extension = lastSegment.slice(dotIndex + 1).toLowerCase();
67
81
  return HttpUrlFilter.STATIC_FILE_EXTENSIONS.has(extension);
68
82
  }
83
+ #isDevServerRequest(url) {
84
+ return HttpUrlFilter.DEV_SERVER_PATTERNS.some((pattern) => url.startsWith(pattern));
85
+ }
69
86
  #matchesPattern(urlPath, pattern) {
70
87
  if (pattern.endsWith('/*')) {
71
88
  const prefix = pattern.slice(0, -2);
@@ -83,17 +100,29 @@ export class HttpUrlFilter {
83
100
  */
84
101
  shouldIgnore(request) {
85
102
  const { url, method } = request;
86
- if (this.#ignoreOptionsRequests && method === 'OPTIONS')
103
+ if (this.#ignoreOptionsRequests && method === 'OPTIONS') {
104
+ debug('ignoring request "%s %s" (reason: OPTIONS method)', method, url);
87
105
  return true;
106
+ }
88
107
  if (!url)
89
108
  return false;
90
109
  const urlPath = url.split('?')[0];
91
- if (this.#ignoreStaticFiles && this.#isStaticFile(urlPath))
110
+ if (this.#ignoreStaticFiles && this.#isStaticFile(urlPath)) {
111
+ debug('ignoring request "%s %s" (reason: static file)', method, urlPath);
112
+ return true;
113
+ }
114
+ if (this.#ignoreStaticFiles && this.#isDevServerRequest(urlPath)) {
115
+ debug('ignoring request "%s %s" (reason: dev server pattern)', method, urlPath);
92
116
  return true;
93
- if (this.#ignoredUrls.some((pattern) => this.#matchesPattern(urlPath, pattern)))
117
+ }
118
+ if (this.#ignoredUrls.some((pattern) => this.#matchesPattern(urlPath, pattern))) {
119
+ debug('ignoring request "%s %s" (reason: ignored url pattern)', method, urlPath);
120
+ return true;
121
+ }
122
+ if (this.#userIgnoreHook && this.#userIgnoreHook(request)) {
123
+ debug('ignoring request "%s %s" (reason: user hook)', method, urlPath);
94
124
  return true;
95
- if (this.#userIgnoreHook)
96
- return this.#userIgnoreHook(request);
125
+ }
97
126
  return false;
98
127
  }
99
128
  /**
package/build/src/otel.js CHANGED
@@ -6,6 +6,7 @@ import { ATTR_HTTP_ROUTE, ATTR_SERVICE_NAME, ATTR_SERVICE_VERSION, } from '@open
6
6
  import { ATTR_DEPLOYMENT_ENVIRONMENT_NAME, ATTR_SERVICE_INSTANCE_ID, } from '@opentelemetry/semantic-conventions/incubating';
7
7
  import { HttpContext } from '@adonisjs/core/http';
8
8
  import { HttpUrlFilter } from './http_url_filter.js';
9
+ import debug from './debug.js';
9
10
  /**
10
11
  * OpenTelemetry SDK manager for AdonisJS.
11
12
  *
@@ -140,6 +141,10 @@ export class OtelManager {
140
141
  */
141
142
  #buildInstrumentations() {
142
143
  const { customInstances, disabledSet, configOverrides, httpConfig, pinoConfig } = this.#processUserInstrumentations(this.#config.instrumentations);
144
+ if (disabledSet.size > 0)
145
+ debug('disabled instrumentations: %O', [...disabledSet]);
146
+ if (customInstances.length > 0)
147
+ debug('custom instrumentations: %O', customInstances.map((i) => i.instrumentationName));
143
148
  const mergedConfig = this.#buildBaseInstrumentationConfig();
144
149
  for (const [name, config] of Object.entries(configOverrides)) {
145
150
  mergedConfig[name] = {
@@ -221,12 +226,14 @@ export class OtelManager {
221
226
  * Start the OpenTelemetry SDK
222
227
  */
223
228
  start() {
229
+ debug('starting otel sdk for service "%s" v%s (%s)', this.serviceName, this.serviceVersion, this.environment);
224
230
  this.sdk.start();
225
231
  }
226
232
  /**
227
233
  * Gracefully shutdown the OpenTelemetry SDK
228
234
  */
229
235
  async shutdown() {
236
+ debug('shutting down otel sdk');
230
237
  await this.sdk.shutdown();
231
238
  }
232
239
  /**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@adonisjs/otel",
3
3
  "description": "OpenTelemetry integration for AdonisJS with sensible defaults and zero-config setup",
4
- "version": "1.1.0",
4
+ "version": "1.1.2",
5
5
  "engines": {
6
6
  "node": ">=20.6.0"
7
7
  },