Skip to content

m.ginMetricHandle is not exectued if ctx.Next() panics #26

Open
@jerome-laforge

Description

@jerome-laforge

If next middle ware panics then m.ginMetricHandle is not executed.
I known in this case response can not be correctly set, but at least can we count it and all correct metrics (client IP, lantency ...)

This can fix this case:

// monitorInterceptor as gin monitor middleware.
func (m *Monitor) monitorInterceptor(ctx *gin.Context) {
	if ctx.Request.URL.Path != m.metricPath {
		startTime := time.Now()

		defer func() {
			// after request
			m.ginMetricHandle(ctx, startTime)
		}()
	}

	// execute normal process.
	ctx.Next()
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions