|
1 | 1 | import fs from "node:fs"; |
2 | 2 | import type { Server as HTTPServer } from "node:http"; |
3 | 3 | import path from "node:path"; |
4 | | -import { ExpressInstrumentation } from "@opentelemetry/instrumentation-express"; |
5 | | -import { HttpInstrumentation } from "@opentelemetry/instrumentation-http"; |
6 | 4 | import { Plugin, toPlugin } from "../plugin"; |
7 | 5 | import type { BasePluginConfig, PluginPhase } from "shared"; |
8 | 6 | import { databricksClientMiddleware, isRemoteServerEnabled } from "../utils"; |
9 | 7 | import dotenv from "dotenv"; |
10 | 8 | import express from "express"; |
11 | 9 | import { DevModeManager } from "./dev-mode"; |
12 | 10 | import { getQueries, getRoutes } from "./utils"; |
| 11 | +import { instrumentations } from "../telemetry"; |
13 | 12 |
|
14 | 13 | dotenv.config({ path: path.resolve(process.cwd(), "./server/.env") }); |
15 | 14 |
|
@@ -44,7 +43,10 @@ export class ServerPlugin extends Plugin { |
44 | 43 | this.serverApplication = express(); |
45 | 44 | this.server = null; |
46 | 45 | this.serverExtensions = []; |
47 | | - this.telemetry.registerInstrumentations(this.createInstrumentations()); |
| 46 | + this.telemetry.registerInstrumentations([ |
| 47 | + instrumentations.http, |
| 48 | + instrumentations.express, |
| 49 | + ]); |
48 | 50 | } |
49 | 51 |
|
50 | 52 | async setup() { |
@@ -268,53 +270,6 @@ export class ServerPlugin extends Plugin { |
268 | 270 | process.exit(0); |
269 | 271 | } |
270 | 272 | } |
271 | | - |
272 | | - private createInstrumentations() { |
273 | | - return [ |
274 | | - new HttpInstrumentation({ |
275 | | - applyCustomAttributesOnSpan(span: any, request: any) { |
276 | | - let spanName: string | null = null; |
277 | | - |
278 | | - if (request.route) { |
279 | | - const baseUrl = request.baseUrl || ""; |
280 | | - const url = request.url?.split("?")[0] || ""; |
281 | | - const fullPath = baseUrl + url; |
282 | | - if (fullPath) { |
283 | | - spanName = `${request.method} ${fullPath}`; |
284 | | - } |
285 | | - } else if (request.url) { |
286 | | - // No Express route (e.g., static assets) - use the raw URL path |
287 | | - // Remove query string for cleaner trace names |
288 | | - const path = request.url.split("?")[0]; |
289 | | - spanName = `${request.method} ${path}`; |
290 | | - } |
291 | | - |
292 | | - if (spanName) { |
293 | | - span.updateName(spanName); |
294 | | - } |
295 | | - }, |
296 | | - }), |
297 | | - new ExpressInstrumentation({ |
298 | | - requestHook: (span: any, info: any) => { |
299 | | - const req = info.request; |
300 | | - |
301 | | - // Only update span name for route handlers (layerType: request_handler) |
302 | | - // This ensures we're not renaming middleware spans |
303 | | - if (info.layerType === "request_handler" && req.route) { |
304 | | - // Combine baseUrl with url to get full path with actual parameter values |
305 | | - // e.g., baseUrl="/api/analytics" + url="/query/spend_data" = "/api/analytics/query/spend_data" |
306 | | - const baseUrl = req.baseUrl || ""; |
307 | | - const url = req.url?.split("?")[0] || ""; |
308 | | - const fullPath = baseUrl + url; |
309 | | - if (fullPath) { |
310 | | - const spanName = `${req.method} ${fullPath}`; |
311 | | - span.updateName(spanName); |
312 | | - } |
313 | | - } |
314 | | - }, |
315 | | - }), |
316 | | - ]; |
317 | | - } |
318 | 273 | } |
319 | 274 |
|
320 | 275 | const EXCLUDED_PLUGINS = [ServerPlugin.name]; |
|
0 commit comments