diff --git a/.changeset/wise-trams-like.md b/.changeset/wise-trams-like.md new file mode 100644 index 00000000..49eef37d --- /dev/null +++ b/.changeset/wise-trams-like.md @@ -0,0 +1,5 @@ +--- +'@hono/otel': patch +--- + +Add explicit `MiddlewareHandler` return type diff --git a/packages/otel/src/index.ts b/packages/otel/src/index.ts index e359199d..7fa0d67d 100644 --- a/packages/otel/src/index.ts +++ b/packages/otel/src/index.ts @@ -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 = ( - options: OtelOptions = {} -) => { +export const otel = (options: OtelOptions = {}): MiddlewareHandler => { if (options.augmentSpan) { - return createMiddleware(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 = (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')) { diff --git a/packages/otel/tsconfig.build.json b/packages/otel/tsconfig.build.json index 66b0baa9..b8855cf8 100644 --- a/packages/otel/tsconfig.build.json +++ b/packages/otel/tsconfig.build.json @@ -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"],