Skip to content

Commit

Permalink
fix(otel): fix src/configuration.ts using middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
waitingsong committed Oct 29, 2024
1 parent 3e56a14 commit e965166
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions packages/otel/src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,33 +87,23 @@ export class AutoConfiguration implements ILifeCycle {
this.app,
'this.app undefined. If start for development, please set env first like `export MIDWAY_SERVER_ENV=local`',
)

// const otel = await this.app.getApplicationContext().getAsync(OtelComponent, [ { name, version } ])
// assert(otel, 'otel must be set')

if (this.config.enable) {
registerMiddleware(this.app, TraceMiddlewareInner, 'last')

const grpcFramework = this.frameworkService.getFramework('gRPC')
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (grpcFramework) {
const rpcApp = grpcFramework.getApplication() as unknown as Application
registerMiddleware(rpcApp, TraceMiddlewareInnerGRpc, 'last')
}
}
}

@TraceInit({ namespace: ConfigKey.componentName })
async onServerReady(container: IMidwayContainer): Promise<void> {
void container
if (this.config.enable) {
registerMiddleware(this.app, TraceMiddleware, 'first')
registerMiddleware(this.app, TraceMiddlewareInner, 'last')

const grpcFramework = this.frameworkService.getFramework('gRPC')
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (grpcFramework) {
const rpcApp = grpcFramework.getApplication() as unknown as Application
registerMiddleware(rpcApp, TraceMiddlewareGRpc, 'first')
const rpcApp = grpcFramework.getApplication() as unknown as Application | undefined
if (rpcApp) {
registerMiddleware(rpcApp, TraceMiddlewareGRpc, 'first')
registerMiddleware(rpcApp, TraceMiddlewareInnerGRpc, 'last')
}
}

void setTimeout(async () => {
Expand Down

0 comments on commit e965166

Please sign in to comment.