@adonisjs/otel 1.1.0 → 1.1.1

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 VITE_DEV_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).
@@ -40,7 +41,10 @@ export class HttpUrlFilter {
40
41
  'ogg',
41
42
  'wav',
42
43
  'pdf',
44
+ 'vue',
45
+ 'svelte',
43
46
  ]);
47
+ static VITE_DEV_PATTERNS = ['/@vite/', '/@id/', '/@fs/', '/__vite'];
44
48
  #ignoredUrls;
45
49
  #ignoreStaticFiles;
46
50
  #ignoreOptionsRequests;
@@ -66,6 +70,9 @@ export class HttpUrlFilter {
66
70
  const extension = lastSegment.slice(dotIndex + 1).toLowerCase();
67
71
  return HttpUrlFilter.STATIC_FILE_EXTENSIONS.has(extension);
68
72
  }
73
+ #isViteDevRequest(url) {
74
+ return HttpUrlFilter.VITE_DEV_PATTERNS.some((pattern) => url.startsWith(pattern));
75
+ }
69
76
  #matchesPattern(urlPath, pattern) {
70
77
  if (pattern.endsWith('/*')) {
71
78
  const prefix = pattern.slice(0, -2);
@@ -83,17 +90,29 @@ export class HttpUrlFilter {
83
90
  */
84
91
  shouldIgnore(request) {
85
92
  const { url, method } = request;
86
- if (this.#ignoreOptionsRequests && method === 'OPTIONS')
93
+ if (this.#ignoreOptionsRequests && method === 'OPTIONS') {
94
+ debug('ignoring request "%s %s" (reason: OPTIONS method)', method, url);
87
95
  return true;
96
+ }
88
97
  if (!url)
89
98
  return false;
90
99
  const urlPath = url.split('?')[0];
91
- if (this.#ignoreStaticFiles && this.#isStaticFile(urlPath))
100
+ if (this.#ignoreStaticFiles && this.#isStaticFile(urlPath)) {
101
+ debug('ignoring request "%s %s" (reason: static file)', method, urlPath);
102
+ return true;
103
+ }
104
+ if (this.#ignoreStaticFiles && this.#isViteDevRequest(urlPath)) {
105
+ debug('ignoring request "%s %s" (reason: vite dev pattern)', method, urlPath);
92
106
  return true;
93
- if (this.#ignoredUrls.some((pattern) => this.#matchesPattern(urlPath, pattern)))
107
+ }
108
+ if (this.#ignoredUrls.some((pattern) => this.#matchesPattern(urlPath, pattern))) {
109
+ debug('ignoring request "%s %s" (reason: ignored url pattern)', method, urlPath);
110
+ return true;
111
+ }
112
+ if (this.#userIgnoreHook && this.#userIgnoreHook(request)) {
113
+ debug('ignoring request "%s %s" (reason: user hook)', method, urlPath);
94
114
  return true;
95
- if (this.#userIgnoreHook)
96
- return this.#userIgnoreHook(request);
115
+ }
97
116
  return false;
98
117
  }
99
118
  /**
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.1",
5
5
  "engines": {
6
6
  "node": ">=20.6.0"
7
7
  },