refactor(otel): enable isolated declarations (#1203)

* refactor(otel): enable isolated declarations

* refactor: remove extra type arguments
pull/1206/head
Jonathan Haines 2025-06-09 19:58:01 +10:00 committed by GitHub
parent b8802e01b7
commit 3c1ecb0ce9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 11 additions and 7 deletions

View File

@ -0,0 +1,5 @@
---
'@hono/otel': patch
---
Add explicit `MiddlewareHandler` return type

View File

@ -8,7 +8,7 @@ import {
ATTR_URL_FULL,
ATTR_HTTP_ROUTE,
} from '@opentelemetry/semantic-conventions'
import type { Env, Input } from 'hono'
import type { MiddlewareHandler } from 'hono'
import { createMiddleware } from 'hono/factory'
import metadata from '../package.json' with { type: 'json' }
@ -24,11 +24,9 @@ export type OtelOptions =
augmentSpan: true
}
export const otel = <E extends Env = any, P extends string = any, I extends Input = {}>(
options: OtelOptions = {}
) => {
export const otel = (options: OtelOptions = {}): MiddlewareHandler => {
if (options.augmentSpan) {
return createMiddleware<E, P, I>(async (c, next) => {
return createMiddleware(async (c, next) => {
const result = await next()
const span = trace.getActiveSpan()
if (span != null) {
@ -41,7 +39,7 @@ export const otel = <E extends Env = any, P extends string = any, I extends Inpu
}
const tracerProvider = options.tracerProvider ?? trace.getTracerProvider()
const tracer = tracerProvider.getTracer(PACKAGE_NAME, PACKAGE_VERSION)
return createMiddleware<E, P, I>(async (c, next) => {
return createMiddleware(async (c, next) => {
// Handle propagation of trace context from a request using the W3C Trace Context format
let activeContext = context.active()
if (c.req.header('traceparent')) {

View File

@ -4,7 +4,8 @@
"rootDir": "src",
"outDir": "dist",
"tsBuildInfoFile": "dist/tsconfig.build.tsbuildinfo",
"emitDeclarationOnly": false
"emitDeclarationOnly": false,
"isolatedDeclarations": true
},
"include": ["package.json", "src/**/*.ts"],
"exclude": ["**/*.test.ts"],