Regarding the Tyk error message

I am using the go plugin with the Tyk gateway.
When i am sending the error response from go plugin, Tyk is also sending the error plugin message.

Sample code:

func writeError(rw http.ResponseWriter, statusCode int, message string) {
    rw.Header().Set("Content-Type", "application/json")
    rw.WriteHeader(statusCode)
    errorObject := map[string]string{"error": message}
    json.NewEncoder(rw).Encode(errorObject)
}

func OAuth2Introspect(rw http.ResponseWriter, r *http.Request) {
    // ... your code

    if err != nil {
        log.Printf("Error: %+v", err)
        writeError(rw, http.StatusInternalServerError, "Internal Server Error")
        return
    }

    // ... your code
}

Hello @AJAY_K_R and welcome to the community :partying_face:

Could you be referring to [TT-9231] Prevent double error in GoPlugin calls by furkansenharputlu · Pull Request #5562 · TykTechnologies/tyk · GitHub

If yes, then this was fixed in v5.0.7 and v5.2.2. If not then could you explain further?

Thanks @Olu , I upgraded & tried its working. But how can we customise the Tyk error message using Go plugin before sending it to client?
Any idea on the response middleware using Go plugin?

Glad to hear that it’s working as expected

You can use the ResponseWriter as shown here custom-plugin-examples/plugins/go-postauth-opa_integration/authorize_opa.go at master · TykTechnologies/custom-plugin-examples · GitHub

Have you had a look at our documentation on the topic

Yeah this looks great → Golang plugins, Will try to implement this. I don’t see any tyk tracing objects such as tyk request processing time and all in it. Can you help me with this.

I am looking for the processing time of a request when tyk api is called.

I cracked it by adding the startTime as headers in the request middleware & used in response middleware, If you have any other suggestions please let me know.

I can’t recall, but maybe timers.<prefix>.SystemAPICall.success from the gateway instrumentation is what you are looking for.

If not, then we encourage you to try Otel. You can also check out Otel with plugins